最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add header comments to webpack uglified JavaScript? - Stack Overflow

programmeradmin7浏览0评论

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 ments with project info to the output file, on top of the one line with uglified code. How do I do this?

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 ments with project info to the output file, on top of the one line with uglified code. How do I do this?

Share Improve this question edited Jan 22, 2017 at 11:47 d4nyll 12.7k6 gold badges57 silver badges70 bronze badges asked Nov 19, 2016 at 9:58 Mauro BringolfMauro Bringolf 5385 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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

const webpack = require('webpack');
new webpack.BannerPlugin(banner);
// or
new webpack.BannerPlugin(options);
发布评论

评论列表(0)

  1. 暂无评论