⚠️ WARNING ⚠️
This is an unstable release
Rollup node externals
Automatically list package.json dependencies as external
Quick usage
npm i -D rollup-node-externals
In rollup.config.js
:
var rollupNodeExternals = ;...moduleexports = // ... external: // ...;
Now all dependencies
, peerDependencies
, and optionalDependencies
will be listed as external.
Detailed overview
Description
Rollup only will include relative imports by default, but almost always you want your package.json
’s dependencies to be configured as external in your rollup config. Without this configuration, rollup will give you a warning that you’re referencing an undeclared dependency.
Configuration
This library accepts an options
object.
options.whitelist (=[])
An array for the externals
to whitelist, so they will be included in the bundle. Can accept exact strings ('module_name'
), regex patterns (/^module_name/
), or a function that accepts the id and returns whether it should be included (id => id.startsWith('foo')
).
Example
const rollupNodeExternals = ;const rollupPluginCommonjs = ; moduleexports = // ... external: plugins: { // if there is an unresolved import, you forgot to list it in your package.json if warningcode === 'UNRESOLVED_IMPORT' throw warningmessage; console; } // ...;
Q&A
How can I bundle required assets (i.e css files) from node_modules?
Using the whitelist
option, this is possible. You may bundle all files with extensions that are not js/jsx/json, using this regex:
Contributing
Contributions and pull requests welcome. Please make sure your code is covered and passes tests.
License
MIT