build.js 1.11 KB
Newer Older
Pan's avatar
Pan committed
1
'use strict'
Pan's avatar
Pan committed
2 3 4 5
require('./check-versions')()

process.env.NODE_ENV = 'production'

Pan's avatar
Pan committed
6 7 8 9 10 11 12
const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.prod.conf')
Pan's avatar
Pan committed
13

Pan's avatar
Pan committed
14
const spinner = ora('building for production...')
Pan's avatar
Pan committed
15 16 17 18
spinner.start()

rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
  if (err) throw err
Pan's avatar
Pan committed
19
  webpack(webpackConfig, (err, stats) => {
Pan's avatar
Pan committed
20 21
    spinner.stop()
    if (err) throw err
22 23 24 25 26 27 28 29 30
    process.stdout.write(
      stats.toString({
        colors: true,
        modules: false,
        children: false,
        chunks: false,
        chunkModules: false
      }) + '\n\n'
    )
Pan's avatar
Pan committed
31

Pan's avatar
Pan committed
32 33 34 35 36
    if (stats.hasErrors()) {
      console.log(chalk.red('  Build failed with errors.\n'))
      process.exit(1)
    }

Pan's avatar
Pan committed
37
    console.log(chalk.cyan('  Build complete.\n'))
38 39 40 41 42 43
    console.log(
      chalk.yellow(
        '  Tip: built files are meant to be served over an HTTP server.\n' +
          "  Opening index.html over file:// won't work.\n"
      )
    )
Pan's avatar
Pan committed
44 45
  })
})