How to build minified and uncompressed bundle with webpack?

前端 未结 14 1128
囚心锁ツ
囚心锁ツ 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: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!^^

提交回复
热议问题