-1

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

R. Richards
  • 24,603
  • 10
  • 64
  • 64
whiteboss
  • 1
  • 1

2 Answers2

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
  • if this answered work for you, can you please accept it? Thanks :) – Raz Ronen Jan 28 '21 at 09:25
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