build.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. require('./check-versions')()
  2. process.env.NODE_ENV = 'production'
  3. process.env.PLATFORM = process.argv[process.argv.length - 1] || 'wx'
  4. var ora = require('ora')
  5. var rm = require('rimraf')
  6. var path = require('path')
  7. var chalk = require('chalk')
  8. var webpack = require('webpack')
  9. var config = require('../config')
  10. var webpackConfig = require('./webpack.prod.conf')
  11. var utils = require('./utils')
  12. var spinner = ora('building for production...')
  13. spinner.start()
  14. rm(path.join(config.build.assetsRoot, '*'), err => {
  15. if (err) throw err
  16. webpack(webpackConfig, function (err, stats) {
  17. spinner.stop()
  18. if (err) throw err
  19. if (process.env.PLATFORM === 'swan') {
  20. utils.writeFrameworkinfo()
  21. }
  22. process.stdout.write(stats.toString({
  23. colors: true,
  24. modules: false,
  25. children: false,
  26. chunks: false,
  27. chunkModules: false
  28. }) + '\n\n')
  29. if (stats.hasErrors()) {
  30. console.log(chalk.red(' Build failed with errors.\n'))
  31. process.exit(1)
  32. }
  33. console.log(chalk.cyan(' Build complete.\n'))
  34. console.log(chalk.yellow(
  35. ' Tip: built files are meant to be served over an HTTP server.\n' +
  36. ' Opening index.html over file:// won\'t work.\n'
  37. ))
  38. })
  39. })