build.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict'
  2. require('./check-versions')()
  3. const ora = require('ora')
  4. const rm = require('rimraf')
  5. const path = require('path')
  6. const chalk = require('chalk')
  7. const webpack = require('webpack')
  8. const config = require('../config')
  9. const webpackConfig = require('./webpack.prod.conf')
  10. const server = require('pushstate-server')
  11. var spinner = ora('building for '+ process.env.env_config+ ' environment...' )
  12. spinner.start()
  13. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  14. if (err) throw err
  15. webpack(webpackConfig, (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. if (stats.hasErrors()) {
  26. console.log(chalk.red(' Build failed with errors.\n'))
  27. process.exit(1)
  28. }
  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. if(process.env.npm_config_preview){
  35. server.start({
  36. port: 9526,
  37. directory: './dist',
  38. file: '/index.html'
  39. });
  40. console.log('> Listening at ' + 'http://localhost:9526' + '\n')
  41. }
  42. })
  43. })