webpackangular-cliwebpack-plugin

Run webpack plugin through angular CLI


how to run webpack plugin via CLI? I found something like that, but this is not what I need. npx webpack plugin


Solution

  • If you use custom-webpack builder

    Configure your custom webpack as a function, the parameter that will be injected at build time is the existing webpack configuration - which is the one angular define.

    Like so:

    webpack.config.js - (which is defined in angular.json architect.buid.options.customWebpackConfig.path)

    const merge = require('webpack-merge');
    const YourCustomPlugin = require('./YourCustomPlugin');
    
    // Config parameter is Angular default configurations.
    module.exports = function(angularConfig) {
        return merge(angularConfig, {
            plugins: [new YourCustomPlugin()],
            ... // other custom webpack configuration
        });
    };
    

    Worth mentioning there's another solution with ngx-build-plus