build.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. process.env.NODE_ENV = 'production';
  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 spinner = ora('building for production...');
  11. spinner.start();
  12. rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  13. if (err) throw err;
  14. webpack(webpackConfig, function (err, stats) {
  15. spinner.stop();
  16. if (err) throw err;
  17. process.stdout.write(stats.toString({
  18. colors: true,
  19. modules: false,
  20. children: false,
  21. chunks: false,
  22. chunkModules: false
  23. }) + '\n\n');
  24. if (stats.hasErrors()) {
  25. console.log(chalk.red(' Build failed with errors.\n'));
  26. process.exit(1)
  27. }
  28. console.log(chalk.cyan(' Build complete.\n'));
  29. console.log(chalk.yellow(
  30. ' Tip: built files are meant to be served over an HTTP server.\n' +
  31. ' Opening index.less.html over file:// won\'t work.\n'
  32. ));
  33. });
  34. });