如何将标题注释添加到webpack uglified JavaScript?

Mau*_*olf 6 javascript minify uglifyjs webpack babeljs

我目前正在使用以下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}) ]
}
Run Code Online (Sandbox Code Playgroud)

这完全符合我的要求.但是现在我想在输出文件中添加一些带有项目信息的注释,并在一行中添加了uglified代码.我该怎么做呢?

Ori*_*ori 7

使用Webpack后,在缩小后将注释添加到代码中BannerlPlugin():

Webpack 1 - BannerPlugin():

plugins: [
    new webpack.BannerPlugin("The head comment", { entryOnly: true })
]
Run Code Online (Sandbox Code Playgroud)

Webpack 2 - BannerPlugin():

plugins: [
    new webpack.BannerPlugin({ 
        banner: "The head comment", 
        entryOnly: true 
    })
]
Run Code Online (Sandbox Code Playgroud)