问题描述
如何通过 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 文件运行它