Package Exports
- rollup-plugin-node-externals
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-node-externals) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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' /* and many more */
]in my rollup.config.js file each time I begin working on an Electron app. :)
Install
npm install --save-dev rollup-plugin-node-externalsUsage
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, // include pkg.dependencies (default: true)
devDeps: true, // include pkg.devDependencies (default: true)
peerDeps: true, // include pkg.peerDependencies (default: true)
optDeps: true, // include pkg.optionalDependencies (default: true)
except: [] // exceptions (default: []) -- see below
})
],
external: [ // Rollup's `external` option has precedence -- see below
'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 thebuiltin-modulespackage, by Sindre Sorhus. - Set the
deps,devDeps,peerDepsand/oroptDepsoptions tofalseto prevent the corresponding dependencies in yourpackage.jsonfile from being marked as external, therefore letting Rollup bundle them with your code, or... - Use the
exceptoption to remove certain dependencies from the list of externals.exceptcan be a string, a regex, or an array of those, for example:
externals({
deps: true, // Mark all dependencies as external...
except: [
'electron-reload', // ... except `electron-reload`
/^vuex?/ // and the VueJS family
]
})- Rollup's
externaloption is always honored, no matter what:
plugins: [
externals({
deps: false // Keep all dependencies in the bundle
})
],
external: [
'electron' // But `electron` stays external
]Licence
MIT