blob: 955e9defcaf95e03cc28be768a080e2863ff4a47 [file] [log] [blame]
huibing.xie1f1606f2018-08-20 15:46:55 +08001'use strict'
2require('./check-versions')()
3
4process.env.NODE_ENV = 'production'
5
6const ora = require('ora')
7const rm = require('rimraf')
8const path = require('path')
9const chalk = require('chalk')
10const webpack = require('webpack')
11const config = require('../config')
12const webpackConfig = require('./webpack.prod.conf')
13
14const spinner = ora('building for production...')
15spinner.start()
16
17rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
18 if (err) throw err
19 webpack(webpackConfig, (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
30 if (stats.hasErrors()) {
31 console.log(chalk.red(' Build failed with errors.\n'))
32 process.exit(1)
33 }
34
35 console.log(chalk.cyan(' Build complete.\n'))
36 console.log(chalk.yellow(
37 ' Tip: built files are meant to be served over an HTTP server.\n' +
38 ' Opening index.html over file:// won\'t work.\n'
39 ))
40 })
41})