我目前正在使用以下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代码.我该怎么做呢?
解决方法
使用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 }) ]