// 引入版权插入必要
const webpack = require('webpack');
const { name, version, author, homepage, description } = require('./package');
const nunjucks = require('nunjucks');
const moment = require('moment');
// 使用模板渲染
const LICENSE = nunjucks.render('LICENSE', {
name: name,
version: version,
description: description,
author: author,
homepage: homepage,
date: moment().format('YYYY-MM-DD HH:mm:ss'),
});
module.exports = {
...
optimization: {
minimizer: [
//压缩CSS代码
new CssMinimizerPlugin(),
//压缩js代码
new TerserPlugin({
extractComments: false, // 不将注释提取到单独的文件中
}),
// 添加版权信息
new webpack.BannerPlugin({
entryOnly: true,
banner: LICENSE,
raw: true,
}),
],
},
}