2016-11-19 61 views
3

我目前使用以下webpack.config.js:如何添加標題註釋到webpack uglified JavaScript?

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}) ] 
} 

這工作正是我想要它。但是現在我想在輸出文件中添加一些帶有項目信息的註釋,並在一行代碼中使用簡化代碼。我該怎麼做呢?

回答

3

使用添加註釋代碼後,微小的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 
    }) 
]