Mauro Bringolf Mauro Bringolf - 1 year ago 64
Javascript Question

How to add header comments to webpack uglified JavaScript?

I am currently using the following 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}) ]

This works exactly how I want it to. But now I want to add some comments with project info to the output file, on top of the one line with uglified code. How do I do this?

Answer Source

Add the comments to the code after magnification using Webpack's BannerPlugin():

plugins: [
    new webpack.BannerPlugin("The head comment", { entryOnly: true })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download