1 | const ora = require('ora')
|
2 | const rm = require('rimraf')
|
3 | const path = require('path')
|
4 | const chalk = require('chalk')
|
5 | const webpack = require('webpack')
|
6 | const merge = require('webpack-merge')
|
7 |
|
8 | const { log } = require('../lib/log')
|
9 | const config = require('./config').build
|
10 |
|
11 | require('./lib/check-versions')()
|
12 |
|
13 | process.env.NODE_ENV = 'production'
|
14 |
|
15 | const { resolveCwd } = require('./lib/utils')
|
16 | const { isPlainObject } = require('./lib/utils')
|
17 |
|
18 | const tofurc = require('../lib/get-config')()
|
19 | let webpackConfig = require('./webpack.prod')
|
20 | if (tofurc && tofurc.webpack && isPlainObject(tofurc.webpack)) {
|
21 | webpackConfig = merge(webpackConfig, tofurc.webpack)
|
22 | }
|
23 |
|
24 | module.exports = (compress, deleteDist) => {
|
25 | const spinner = ora('构建打包中...')
|
26 | spinner.start()
|
27 |
|
28 | rm(path.join(config.assetsRoot), err => {
|
29 | if (err) throw err
|
30 |
|
31 | webpack(webpackConfig, function (err, stats) {
|
32 | spinner.stop()
|
33 | if (err) throw err
|
34 |
|
35 | process.stdout.write(stats.toString({
|
36 | colors: true,
|
37 | modules: false,
|
38 | children: false,
|
39 | chunks: false,
|
40 | chunkModules: false
|
41 | }) + '\n\n')
|
42 |
|
43 | log('打包成功。', 'cyan')
|
44 |
|
45 |
|
46 | if (compress) {
|
47 | require('./lib/compress.js')(deleteDist)
|
48 | }
|
49 | })
|
50 | })
|
51 | } |
\ | No newline at end of file |