通过 angular CLI 运行 webpack 插件

问题描述

如何通过 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 的文件,并通过 node cli 作为常规 js 文件运行它

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...