build.js 1.1 KB

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