rollup-plugin-node-externals
A Rollup plugin that automatically declares NodeJS built-in modules
and npm dependencies as 'external'.
Useful when building a NodeJS or an Electron app and you don't want to bundle
npm modules with your own code but rather require()
them at runtime.
Why?
Because I was getting tired of writing:
external: [
'path', 'fs', 'fs-jetpack', 'electron-settings'
]
in my rollup.config.js
file each time I begin working on an Electron app. :)
Install
npm install --save-dev rollup-plugin-node-externals
Usage
import externals from 'rollup-plugin-node-externals'
export default {
input: 'src/renderer/index.ts',
output: {
file: 'dist/renderer/bundle.js',
format: 'cjs'
},
plugins: [
externals({
deps: true,
devDeps: true,
peerDeps: true,
optDeps: true,
except: []
})
],
external: [
'electron'
]
}
Options
By default, the plugin will mark Node built-in modules and all your dependencies as external.
- Node built-in modules (eg,
path
, fs
, etc.) are always external. The list of built-ins is obtained via the builtin-modules
package, by Sindre Sorhus. - Set the
deps
, devDeps
, peerDeps
and/or optDeps
options to false
to prevent the corresponding dependencies in your package.json
file from being marked as external, therefore letting Rollup bundle them with your code, or... - Use the
except
option to remove certain dependencies from the list of externals. except
can be a string, a regex, or an array of those, for example:
externals({
deps: true,
except: [
'electron-reload',
/^vuex?/
]
})
- Rollup's
external
option is always honored, no matter what:
plugins: [
externals({
deps: false
})
],
external: [
'electron'
]
Licence
MIT