how to run webpack plugin via CLI?
I found something like that, but this is not what I need.
npx webpack plugin
Asked
Active
Viewed 589 times
-1

R. Richards
- 24,603
- 10
- 64
- 64

whiteboss
- 1
- 1
-
in you angular.json, do you use `@angular-builders/custom-webpack:browser` in the `architect.build.builder` property? – Raz Ronen Jan 27 '21 at 15:56
-
Yes, I do...... – whiteboss Jan 27 '21 at 18:48
-
great, the answer will be simplier – Raz Ronen Jan 27 '21 at 19:00
2 Answers
0
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

Raz Ronen
- 2,418
- 2
- 14
- 26
-
At first, if i already have some config in this file I have to add this one level with "plugins"? Secondly, which command can I use to launch one specific plugin? – whiteboss Jan 28 '21 at 07:13
-
yes, I'll update my answer. Webpack will launch it for you in the hook that you defined inside your plugin – Raz Ronen Jan 28 '21 at 07:19
-
yes, I know that and it works like that now. I'm wondering if I can somehow run 1 specific plugin without starting the webpack build. For example, something like `webpack plugin my-wp-plugin.js` – whiteboss Jan 28 '21 at 08:32
-
what does your plugin do? If it doesn't need a webpack build then you can run it in node: `node my-wp-plugin` – Raz Ronen Jan 28 '21 at 09:21
-
0
Here's what worked for me. I created another file that does not depend on webpack in any way and ran it through node cli as a regular js file

whiteboss
- 1
- 1