我目前正在使用以下webpack.config.js:
var webpack = require('webpack');
module.exports = {
entry: __dirname + "/src/index.js",
output: {
path: __dirname,
filename: "index.js"
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: '/node_modules/',
query: {
presets: ['latest']
}
}
]
},
plugins: [ new webpack.optimize.UglifyJsPlugin({minimize: true}) ]
}
这正是我想要的方式。但是现在我想在输出文件中添加一些带有项目信息的注释,并在一行中添加了uglified代码。我该怎么做?
答案 0 :(得分:7)
使用Webpack BannerlPlugin()
缩小后将注释添加到代码中:
Webpack 1 - BannerPlugin()
:
plugins: [
new webpack.BannerPlugin("The head comment", { entryOnly: true })
]
Webpack 2 - BannerPlugin()
:
plugins: [
new webpack.BannerPlugin({
banner: "The head comment",
entryOnly: true
})
]