build.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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(
  18. stats.toString({
  19. colors: true,
  20. modules: false,
  21. children: false,
  22. chunks: false,
  23. chunkModules: false
  24. }) + '\n\n'
  25. )
  26. if (stats.hasErrors()) {
  27. console.log(chalk.red(' Build failed with errors.\n'))
  28. process.exit(1)
  29. }
  30. console.log(chalk.cyan(' Build complete.\n'))
  31. console.log(chalk.yellow(
  32. ' Tip: built files are meant to be served over an HTTP server.\n' +
  33. ' Opening index.html over file:// won\'t work.\n'
  34. ))
  35. })
  36. })