Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 485
Mauro Bringolf Avatar asked Nov 19 '16 09:11

Mauro Bringolf


1 Answers

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

const webpack = require('webpack');
new webpack.BannerPlugin(banner);
// or
new webpack.BannerPlugin(options);
like image 83
Ori Drori Avatar answered Oct 21 '22 23:10

Ori Drori