UNPKG

1.41 kBJavaScriptView Raw
1const ora = require('ora')
2const rm = require('rimraf')
3const path = require('path')
4const chalk = require('chalk')
5const webpack = require('webpack')
6const merge = require('webpack-merge')
7
8const { log } = require('../lib/log')
9const config = require('./config').build
10
11require('./lib/check-versions')()
12
13process.env.NODE_ENV = 'production'
14
15const { resolveCwd } = require('./lib/utils')
16const { isPlainObject } = require('./lib/utils')
17
18const tofurc = require('../lib/get-config')()
19let webpackConfig = require('./webpack.prod')
20if (tofurc && tofurc.webpack && isPlainObject(tofurc.webpack)) {
21 webpackConfig = merge(webpackConfig, tofurc.webpack)
22}
23
24module.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 // 压缩 dist 文件夹,并移动到桌面
46 if (compress) {
47 require('./lib/compress.js')(deleteDist)
48 }
49 })
50 })
51}
\No newline at end of file