Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: customizer to remove plugin #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/customizers/__snapshots__/webpack.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ Object {
}
`;

exports[`removeWebpackPlugin removes plugin with provided name from plugins list 1`] = `
Object {
"plugins": Array [
PluginToStay {},
],
}
`;

exports[`setWebpackOptimizationSplitChunks sets the customized optimization.splitChunks for webpack 1`] = `
Object {
"optimization": Object {
Expand Down
7 changes: 7 additions & 0 deletions src/customizers/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ export const addWebpackPlugin = plugin => config => {
return config;
};

export const removeWebpackPlugin = pluginName => config => {
config.plugins = config.plugins.filter(
p => p.constructor.name !== pluginName
);
return config;
};

export const adjustWorkbox = adjust => config => {
config.plugins.forEach(p => {
if (p.constructor.name === "GenerateSW") {
Expand Down
16 changes: 16 additions & 0 deletions src/customizers/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
addWebpackAlias,
addWebpackResolve,
addWebpackPlugin,
removeWebpackPlugin,
disableEsLint,
useEslintRc,
enableEslintTypescript,
Expand Down Expand Up @@ -81,6 +82,21 @@ test("addWebpackPlugin adds the provided plugin to the config plugins list", ()
expect(actual).toMatchSnapshot();
});

test("removeWebpackPlugin removes plugin with provided name from plugins list", () => {
class TestPlugin {
constructor(){}
}
class PluginToStay {
constructor(){}
}
const pluginToRemove = new TestPlugin();
const pluginToStay = new PluginToStay();
const config = { plugins: [pluginToStay, pluginToRemove] };
const actual = removeWebpackPlugin("TestPlugin")(config);

expect(actual).toMatchSnapshot();
});

describe("eslint", () => {
test("disableEsLint filters out the eslint rules from the config rules list", () => {
const inputConfig = {
Expand Down