build.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict"
  2. require("./check-versions")()
  3. process.env.NODE_ENV = "production"
  4. const path = require("path")
  5. try {
  6. var dist = path.resolve(process.argv.splice(2)[0])
  7. process.env.dist = dist
  8. } catch (e) {
  9. }
  10. const ora = require("ora")
  11. const rm = require("rimraf")
  12. const chalk = require("chalk")
  13. const webpack = require("webpack")
  14. const config = require("../config")
  15. const webpackConfig = require("./webpack.prod.conf")
  16. const spinner = ora("building for production...")
  17. spinner.start()
  18. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  19. if (err) throw err
  20. webpack(webpackConfig, function (err, stats) {
  21. spinner.stop()
  22. if (err) throw err
  23. process.stdout.write(
  24. stats.toString({
  25. colors: true,
  26. modules: false,
  27. children: false,
  28. chunks: false,
  29. chunkModules: false
  30. }) + "\n\n"
  31. )
  32. if (stats.hasErrors()) {
  33. console.log(chalk.red(" Build failed with errors.\n"))
  34. process.exit(1)
  35. }
  36. console.log(chalk.cyan(" Build complete.\n"))
  37. console.log(
  38. chalk.yellow(
  39. " Tip: built files are meant to be served over an HTTP server.\n" +
  40. " Opening index.html over file:// won't work.\n"
  41. )
  42. )
  43. })
  44. })