主要变更包括: 1. 更新Babel配置,使用@babel/preset-env和@babel/plugin-transform-object-rest-spread。 2. 升级Webpack及相关插件,使用MiniCssExtractPlugin替代ExtractTextPlugin。 3. 更新package-lock.json和package.json,调整依赖版本。 4. 修改README.md,更新项目简介和环境要求。 5. 代码格式优化和错误处理增强,提升构建和开发体验。
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
'use strict'
|
|
require('./check-versions')()
|
|
|
|
process.env.NODE_ENV = 'production'
|
|
|
|
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')
|
|
|
|
const spinner = ora('building for production...')
|
|
spinner.start()
|
|
|
|
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
|
|
if (err) throw err
|
|
webpack(webpackConfig, (err, stats) => {
|
|
spinner.stop()
|
|
if (err) {
|
|
console.log(chalk.red(' Webpack configuration error:'))
|
|
console.error(err)
|
|
process.exit(1)
|
|
}
|
|
process.stdout.write(stats.toString({ colors: true,
|
|
modules: true,
|
|
children: true,
|
|
chunks: false,
|
|
chunkModules: false
|
|
}) + '\n\n')
|
|
|
|
if (stats.hasErrors()) {
|
|
console.log(chalk.red(' Build failed with errors.\n'))
|
|
console.log(chalk.red(' Error details:'))
|
|
stats.toJson().errors.forEach(error => {
|
|
console.error(error)
|
|
})
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log(chalk.cyan(' Build complete.\n'))
|
|
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'
|
|
))
|
|
})
|
|
})
|