How to build minified and uncompressed bundle with webpack?

前端 未结 14 1160
囚心锁ツ
囚心锁ツ 2020-11-29 14:52

Here\'s my webpack.config.js

var webpack = require(\"webpack\");

module.exports = {

  entry: \"./entry.js\",
  devtool: \"source-map\",
  outp         


        
14条回答
  •  长情又很酷
    2020-11-29 15:27

    You can define two entry points in your webpack configuration, one for your normal js and the other one for minified js. Then you should output your bundle with its name, and configure UglifyJS plugin to include min.js files. See the example webpack configuration for more details:

    module.exports = {
     entry: {
       'bundle': './src/index.js',
       'bundle.min': './src/index.js',
     },
    
     output: {
       path: path.resolve(__dirname, 'dist'),
       filename: "[name].js"
     },
    
     plugins: [
       new webpack.optimize.UglifyJsPlugin({
          include: /\.min\.js$/,
          minimize: true
       })
     ]
    };
    

    After running webpack, you will get bundle.js and bundle.min.js in your dist folder, no need for extra plugin.

提交回复
热议问题