build.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict'
  2. require('./check-versions')()
  3. const ora = require('ora')
  4. const rm = require('rimraf')
  5. const path = require('path')
  6. const chalk = require('chalk')
  7. const webpack = require('webpack')
  8. const config = require('../config')
  9. const webpackConfig = require('./webpack.prod.conf')
  10. const spinner = ora('building for '+ process.env.NODE_ENV+ ' environment...' )
  11. spinner.start()
  12. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  13. if (err) throw err
  14. webpack(webpackConfig, (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. })