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

add adjustWebpackPlugin #301

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This file documents the functions exported by `customize-cra`.
- [removeModuleScopePlugin](#removemodulescopeplugin)
- [watchAll](#watchall)
- [adjustStyleLoaders](#adjustStyleLoaders)
- [adjustWebpackPlugin](#adjustWebpackPlugin)
- [`utilities`](#utilities)
- [getBabelLoader](#getbabelloaderconfig-isoutsideofapp)
- [tap](#tapoptions)
Expand Down Expand Up @@ -476,6 +477,16 @@ adjustStyleLoaders(({ use: [ , css, postcss, resolve, processor ] }) => {
})
```

### adjustWebpackPlugin(name, callback)

Find plugin and callback.

```js
adjustWebpackPlugin('HtmlWebpackPlugin', (plugin) => {});
```

You can find plugin and change options or anything else.

## `utilities`

`utilities` are functions consumed by `customizers` in order to navigate their config.
Expand Down
2 changes: 2 additions & 0 deletions src/customizers/__snapshots__/webpack.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Object {
}
`;

exports[`adjustWebpackPlugin find plugin and callback 1`] = `FooPlugin {}`;

exports[`adjustWorkbox calls the provided adjustment using the workbox plugin config 1`] = `
Object {
"plugins": Array [
Expand Down
10 changes: 10 additions & 0 deletions src/customizers/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const adjustStyleLoaders = callback => config => {
return config;
};

export const adjustWebpackPlugin = (name, callback) => config => {
for (let plugin of config.plugins) {
if (plugin.constructor.name === name) {
callback(plugin);
break;
}
}
return config;
};

export const useEslintRc = configFile => config => {
const eslintRule = config.module.rules.filter(
r => r.use && r.use.some(u => u.options && u.options.useEslintrc !== void 0)
Expand Down
8 changes: 8 additions & 0 deletions src/customizers/webpack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
addWebpackModuleRule,
adjustWorkbox,
adjustStyleLoaders,
adjustWebpackPlugin,
watchAll,
disableChunk,
removeModuleScopePlugin,
Expand Down Expand Up @@ -175,6 +176,13 @@ test("adjustStyleLoaders find all style loaders and callback one by one", () =>
adjustStyleLoaders(actual => expect(actual).toMatchSnapshot())(inputConfig);
});

test("adjustWebpackPlugin find plugin and callback", () => {
const FooPlugin = function () { };
const BarPlugin = function () { };
const inputConfig = { plugins: [ new FooPlugin(), new BarPlugin() ] };
adjustWebpackPlugin('FooPlugin', actual => expect(actual).toMatchSnapshot())(inputConfig);
});

test("addLessLoader", () => {});

test("watchAll removes the watchOptions from config if --watch-all passed", () => {
Expand Down