build.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // https://github.com/shelljs/shelljs
  2. require('./check-versions')()
  3. process.env.NODE_ENV = 'production'
  4. var ora = require('ora')
  5. var path = require('path')
  6. var chalk = require('chalk')
  7. var shell = require('shelljs')
  8. var webpack = require('webpack')
  9. var config = require('../config')
  10. var webpackConfig = require('./webpack.prod.conf')
  11. var spinner = ora('building for production...')
  12. spinner.start()
  13. var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory)
  14. shell.rm('-rf', assetsPath)
  15. shell.mkdir('-p', assetsPath)
  16. shell.config.silent = true
  17. shell.cp('-R', 'static/*', assetsPath)
  18. shell.config.silent = false
  19. webpack(webpackConfig, function (err, stats) {
  20. spinner.stop()
  21. if (err) throw err
  22. process.stdout.write(stats.toString({
  23. colors: true,
  24. modules: false,
  25. children: false,
  26. chunks: false,
  27. chunkModules: false
  28. }) + '\n\n')
  29. console.log(chalk.cyan(' Build complete.\n'))
  30. console.log(chalk.yellow(
  31. ' Tip: built files are meant to be served over an HTTP server.\n' +
  32. ' Opening index.html over file:// won\'t work.\n'
  33. ))
  34. })