Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Lazily require() webpack plugins to improve performance #1101

Merged
merged 1 commit into from
Sep 14, 2018
Merged

Lazily require() webpack plugins to improve performance #1101

merged 1 commit into from
Sep 14, 2018

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Sep 14, 2018

webpack-chain 4.11.0's config.plugin('abc').use(...) now also supports being passed the path to a plugin, rather than just the already-require()ed plugin itself. See:
neutrinojs/webpack-chain#102

This means we can avoid the expensive require() of plugins in cases where the plugin isn't used - such as when:

  • running ESLint's CLI with a Neutrino-generated .eslintrc.js
  • running tests with Jest/Mocha (which don't perform a webpack build)
  • the plugin isn't needed for that NODE_ENV (eg clean-webpack-plugin isn't used in development).

For example, this reduces time node .eslintrc.js for a React+AirBnb project from 1700ms to 370ms - and for projects that use more of the non-default core Neutrino presets, the improvement will be even more noticeable.

As an added bonus, plugins specified by path also have their require() statement generated automatically when using toString(), meaning that the configuration output by --inspect no longer needs any adjustments before it can be run.

ie this "just works" with the core presets:

$ echo "module.exports = $(yarn neutrino --inspect --mode production);" > exported-config.js
$ yarn webpack --config exported-config.js

The webpack-chain docs have also been synced with those from upstream.

Refs #239.

webpack-chain 4.11.0's `.plugin('abc').use(...)` now supports being
passed the path to a plugin, instead of the plugin itself. See:
neutrinojs/webpack-chain#102

This means we can avoid the expensive `require()` of plugins in cases
where the plugin isn't used - such as when:
* running ESLint's CLI with a Neutrino-generated `.eslintrc.js`
* running tests with Jest/Mocha (which don't perform a webpack build)
* the plugin isn't needed for that `NODE_ENV` (eg `clean-webpack-plugin`
  isn't used in development).

For example, this reduces `time node .eslintrc.js` for a React+AirBnb
project from 1700ms to 370ms - and for projects that use more of the
non-default core Neutrino presets, the improvement will be even more
noticeable.

As an added bonus, plugins specified by path also have their `require()`
statement generated automatically when using `toString()`, meaning
that the configuration output by `--inspect` no longer needs any
adjustments before it can be run.

ie this "just works" with the core presets:

```
$ echo "module.exports = $(yarn neutrino --inspect --mode production);" > exported-config.js
$ yarn webpack --config exported-config.js
```

The webpack-chain docs have also been synced with those from upstream.

Refs #239.
@edmorley edmorley added this to the v9 milestone Sep 14, 2018
@edmorley edmorley self-assigned this Sep 14, 2018
Copy link
Member

@eliperelman eliperelman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely amazing! I can't believe that this ejection works either; incredible.

@edmorley edmorley merged commit a0cb90a into neutrinojs:master Sep 14, 2018
@edmorley edmorley deleted the lazy-plugin-require branch September 14, 2018 18:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

2 participants