How to build minified and uncompressed bundle with webpack?

前端 未结 14 1054
囚心锁ツ
囚心锁ツ 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:35

    According with this line: https://github.com/pingyuanChen/webpack-uglify-js-plugin/blob/master/index.js#L117

    should be something like:

    var webpack = require("webpack");
    
    module.exports = {
    
      entry: "./entry.js",
      devtool: "source-map",
      output: {
        path: "./dist",
        filename: "bundle.js"
      },
      plugins: [
        new webpack.optimize.UglifyJsPlugin({
         minimize: true,
         compress: false
        })
      ]
    };
    

    Indeed you can have multiple builds by exporting different configs according your env / argv strategies.

    0 讨论(0)
  • 2020-11-29 15:36

    Maybe i am late here, but i have the same issue, so i wrote a unminified-webpack-plugin for this purpose.

    Installation

    npm install --save-dev unminified-webpack-plugin
    

    Usage

    var path = require('path');
    var webpack = require('webpack');
    var UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
    
    module.exports = {
        entry: {
            index: './src/index.js'
        },
        output: {
            path: path.resolve(__dirname, 'dist'),
            filename: 'library.min.js'
        },
        plugins: [
            new webpack.optimize.UglifyJsPlugin({
                compress: {
                    warnings: false
                }
            }),
            new UnminifiedWebpackPlugin()
        ]
    };
    

    By doing as above, you will get two files library.min.js and library.js. No need execute webpack twice, it just works!^^

    0 讨论(0)
提交回复
热议问题