build.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. require('./check-versions')()
  2. var server = require('pushstate-server')
  3. var ora = require('ora')
  4. var rm = require('rimraf')
  5. var path = require('path')
  6. var chalk = require('chalk')
  7. var webpack = require('webpack')
  8. var config = require('../config')
  9. var webpackConfig = require('./webpack.prod.conf')
  10. console.log(process.env.NODE_ENV)
  11. var spinner = ora('building for ' + process.env.NODE_ENV + '...')
  12. spinner.start()
  13. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  14. if (err) throw err
  15. webpack(webpackConfig, function(err, stats) {
  16. spinner.stop()
  17. if (err) throw err
  18. process.stdout.write(stats.toString({
  19. colors: true,
  20. modules: false,
  21. children: false,
  22. chunks: false,
  23. chunkModules: false
  24. }) + '\n\n')
  25. console.log(chalk.cyan(' Build complete.\n'))
  26. if (process.env.npm_config_preview) {
  27. const port = process.env.PORT
  28. server.start({
  29. port: port,
  30. directory: './dist',
  31. file: '/index.html'
  32. });
  33. console.log(`> Listening at ${process.env.BASE_URL}:${port}\
  34. n`)
  35. }
  36. })
  37. })