运行 webpack 插件通过 angular CLI

Run webpack plugin through angular CLI

如何通过 CLI 运行 webpack 插件? 我找到了类似的东西,但这不是我需要的。 npx webpack plugin

如果你使用custom-webpack builder

将您的自定义 webpack 配置为一个函数,将在构建时注入的参数是现有的 webpack 配置 - 这是 angular 定义的。

像这样:

webpack.config.js -(在 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
    });
};

值得一提的是 ngx-build-plus

的另一个解决方案

以下是对我有用的方法。我创建了另一个不以任何方式依赖 webpack 的文件,并通过节点 cli 运行 它作为常规 js 文件