build.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 spinner = ora('building for production...')
  12. spinner.start()
  13. rm(path.join(config.build.assetsRoot, '*'), err => {
  14. if (err) throw err
  15. webpack(webpackConfig, function (err, stats) {
  16. spinner.stop()
  17. if (err) throw err
  18. process.stdout.write(stats.toString({
  19. colors: true,
  20. modules: false,
  21. children: false,
  22. chunks: false,
  23. chunkModules: false
  24. }) + '\n\n')
  25. if (stats.hasErrors()) {
  26. console.log(chalk.red(' Build failed with errors.\n'))
  27. process.exit(1)
  28. }
  29. console.log(chalk.cyan(' Build complete.\n'))
  30. console.log(chalk.yellow(
  31. ' Tip: built files are meant to be served over an HTTP server.\n' +
  32. ' Opening index.html over file:// won\'t work.\n'
  33. ))
  34. })
  35. })