Skip to content

Commit

Permalink
Show how to skip imports for optional plugins (#2627)
Browse files Browse the repository at this point in the history
The most common Rollup plugins are pretty fast to import (by Node
standards), but even those will commonly add on a handful of
milliseconds, and it’s not unheard of to have imports literally take
seconds. If you don’t need it, why load it? I think that this is a good
pattern to recommend.

eslint and stylelint are two good examples of unreasonably slow modules
that will commonly be optional. stylelint can take a second or two, and
eslint a few hundred milliseconds, because neither of them care enough
about startup time. stylelint/stylelint#2454
was me reporting it for stylelint. I wish more people used Rollup on
their packages before submitting them to npm.
  • Loading branch information
chris-morgan authored and lukastaegert committed Jan 3, 2019
1 parent 6d32530 commit 5ff6352
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/999-big-list-of-options.md
Expand Up @@ -210,20 +210,21 @@ See [Using plugins](guide/en#using-plugins) for more information on how to use p
// rollup.config.js
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import {terser} from 'rollup-plugin-terser';

const isProduction = process.env.NODE_ENV === 'production';

export default {
export default (async () => ({
entry: 'main.js',
plugins: [
resolve(),
commonjs(),
isProduction && terser()
isProduction && (await import('rollup-plugin-terser')).terser()
]
};
})();
```
(This example also demonstrates how to use an async IIFE and dynamic imports to avoid unnecessary module loading, which can be surprisingly slow.)
### Advanced functionality
#### cache
Expand Down

0 comments on commit 5ff6352

Please sign in to comment.