build.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict'
  2. require('./check-versions')()
  3. console.log(process.env.NODE_ENV);
  4. // process.env.NODE_ENV = 'production'
  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 = process.env.NODE_ENV === 'private' ? require('./webpack.private.prod.conf') : require('./webpack.prod.conf')
  12. // console.log(webpackConfig);
  13. // const spinner = ora('building for production...')
  14. const spinner = ora('building for' + process.env.NODE_ENV + 'of' + process.env.env_config + 'mode...')
  15. spinner.start()
  16. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  17. if (err) throw err
  18. webpack(webpackConfig, (err, stats) => {
  19. spinner.stop()
  20. if (err) throw err
  21. process.stdout.write(stats.toString({
  22. colors: true,
  23. modules: false,
  24. children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.
  25. chunks: false,
  26. chunkModules: false
  27. }) + '\n\n')
  28. if (stats.hasErrors()) {
  29. console.log(chalk.red(' Build failed with errors.\n'))
  30. process.exit(1)
  31. }
  32. console.log(chalk.cyan(' Build complete.\n'))
  33. console.log(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. })