Skip to content

Commit ac4a69e

Browse files
committed
Allow to add extra plugin
1 parent 8fb9b4b commit ac4a69e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ module.exports = {
176176
return this;
177177
},
178178

179+
/**
180+
* Add a plugin to the sets of plugins already registered by Encore
181+
*
182+
* For example, if you want to add the "webpack.IgnorePlugin()", then:
183+
* .addPlugin(new webpack.IgnorePlugin(requestRegExp, contextRegExp))
184+
*
185+
* @param {string} plugin
186+
* @return {exports}
187+
*/
188+
addPlugin(plugin) {
189+
webpackConfig.addPlugin(plugin);
190+
191+
return this;
192+
},
193+
179194
/**
180195
* When enabled, files are rendered with a hash based
181196
* on their contents (e.g. main.a2b61cc.js)

lib/WebpackConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ class WebpackConfig {
167167
this.loaders.push(loader);
168168
}
169169

170+
addPlugin(plugin) {
171+
this.plugins.push(plugin);
172+
}
173+
170174
enableVersioning(enabled = true) {
171175
this.useVersioning = enabled;
172176
}

test/WebpackConfig.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,17 @@ describe('WebpackConfig object', () => {
300300
expect(config.loaders).to.deep.equals([{ 'test': /\.custom$/, 'loader': 'custom-loader' }]);
301301
});
302302
});
303+
304+
describe('addPlugin', () => {
305+
it('extends the current registered plugins', () => {
306+
const config = createConfig();
307+
const nbOfPlugins = config.plugins.length;
308+
309+
expect(nbOfPlugins).to.equal(0);
310+
311+
config.addPlugin(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));
312+
313+
expect(config.plugins.length).to.equal(1);
314+
});
315+
});
303316
});

0 commit comments

Comments
 (0)