build.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. const spinner = ora('building for' + process.env.NODE_ENV + 'of' + process.env.env_config + 'mode...')
  13. spinner.start()
  14. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  15. if (err) throw err
  16. webpack(webpackConfig, (err, stats) => {
  17. spinner.stop()
  18. if (err) throw err
  19. process.stdout.write(stats.toString({
  20. colors: true,
  21. modules: false,
  22. children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
  23. chunks: false,
  24. chunkModules: false
  25. }) + '\n\n')
  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. })