build.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict'
  2. require('./check-versions')()
  3. process.env.NODE_ENV = 'production'
  4. process.env.env_config = 'test'
  5. const ora = require('ora')
  6. const rm = require('rimraf')
  7. const path = require('path')
  8. const chalk = require('chalk')
  9. const webpack = require('webpack')
  10. const config = require('../config')
  11. const webpackConfig = require('./webpack.prod.conf')
  12. // const spinner = ora('building for production...')
  13. const spinner = ora('building for' + process.env.NODE_ENV + 'of' + process.env.env_config + 'mode...')
  14. spinner.start()
  15. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  16. if (err) throw err
  17. webpack(webpackConfig, (err, stats) => {
  18. spinner.stop()
  19. if (err) throw err
  20. process.stdout.write(stats.toString({
  21. colors: true,
  22. modules: false,
  23. children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
  24. chunks: false,
  25. chunkModules: false
  26. }) + '\n\n')
  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(chalk.yellow(
  33. ' Tip: built files are meant to be served over an HTTP server.\n' +
  34. ' Opening index.html over file:// won\'t work.\n'
  35. ))
  36. })
  37. })