build.js 1.0 KB

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