Webpack: How can we *conditionally* use a plugin?

后端 未结 7 2191
死守一世寂寞
死守一世寂寞 2021-02-07 00:31

In Webpack, I have the following plugins:

plugins: [
        new ExtractTextPlugin(\'styles.css\'),
        new webpack.optimize.UglifyJsPlugin({
            com         


        
7条回答
  •  灰色年华
    2021-02-07 01:28

    I push onto the plugins array given a condition in my webpack.config.js

    var webpack = require('webpack');
    const ExtractTextPlugin = require("extract-text-webpack-plugin");
    
    module.exports = {
        entry: {
            ...
        },
        output: {
            ...
        },
        module: {
            rules: [
                ...
            ]
        },
        plugins: [
            new ExtractTextPlugin('styles.css'),
        ]
    };
    
    
    if (TARGET === 'build') {
        module.exports.plugins.push(
            new webpack.optimize.UglifyJsPlugin({
                compress: {
                    warnings: false
                },
                drop_console: true,
            }),
        );
    }
    

提交回复
热议问题