Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ module.exports = {
return this;
},

/**
* Add a plugin to the sets of plugins already registered by Encore
*
* For example, if you want to add the "webpack.IgnorePlugin()", then:
* .addPlugin(new webpack.IgnorePlugin(requestRegExp, contextRegExp))
*
* @param {string} plugin
* @return {exports}
*/
addPlugin(plugin) {
webpackConfig.addPlugin(plugin);

return this;
},

/**
* Adds a custom loader config
*
Expand Down
5 changes: 5 additions & 0 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WebpackConfig {
this.manifestKeyPrefix = null;
this.entries = new Map();
this.styleEntries = new Map();
this.plugins = [];
this.useVersioning = false;
this.useSourceMaps = false;
this.usePostCssLoader = false;
Expand Down Expand Up @@ -158,6 +159,10 @@ class WebpackConfig {
this.styleEntries.set(name, src);
}

addPlugin(plugin) {
this.plugins.push(plugin);
}

addLoader(loader) {
this.loaders.push(loader);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ class ConfigGenerator {
plugins.push(new AssetOutputDisplayPlugin(outputPath, friendlyErrorsPlugin));
}

this.webpackConfig.plugins.forEach(function(plugin) {
plugins.push(plugin);
});

return plugins;
}

Expand Down
14 changes: 14 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const WebpackConfig = require('../lib/WebpackConfig');
const RuntimeConfig = require('../lib/config/RuntimeConfig');
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');

function createConfig() {
const runtimeConfig = new RuntimeConfig();
Expand Down Expand Up @@ -277,6 +278,19 @@ describe('WebpackConfig object', () => {
});
});

describe('addPlugin', () => {
it('extends the current registered plugins', () => {
const config = createConfig();
const nbOfPlugins = config.plugins.length;

expect(nbOfPlugins).to.equal(0);

config.addPlugin(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));

expect(config.plugins.length).to.equal(1);
});
});

describe('addLoader', () => {
it('Adds a new loader', () => {
const config = createConfig();
Expand Down
14 changes: 14 additions & 0 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,18 @@ describe('The config-generator function', () => {
expect(actualConfig.devServer.publicPath).to.equal('/subdirectory/build/');
});
});

describe('test for addPlugin config', () => {
it('extra plugin is set correctly', () => {
const config = createConfig();
config.outputPath = '/tmp/public/build';
config.setPublicPath('/build/');
config.addPlugin(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/));

const actualConfig = configGenerator(config);

const ignorePlugin = findPlugin(webpack.IgnorePlugin, actualConfig.plugins);
expect(ignorePlugin).to.not.be.undefined;
});
});
});