Easily exclude node_modules in Rollup bundle, forked from webpack-node-externals
Last updated 3 years ago by yelo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @yelo/rollup-node-external 
SYNC missed versions from official npm registry.

rollup node modules external

Easily exclude node modules in rollup, forked from webpack-node-externals

Version Downloads

rollup allows you to define external - modules that should not be bundled.

When bundling with rollup for the backend - you usually don't want to bundle its node_modules dependencies. This library creates an external function that ignores node_modules when bundling in rollup.

Forked from liady/webpack-node-externals

Quick usage

npm install @yelo/rollup-node-external --save-dev

In your rollup.config.js:

var external = require('@yelo/rollup-node-external');
module.exports = {
    external: external(), // in order to ignore all modules in node_modules folder
    plugins: [
        // import node-resolve plugin

And that's it. All node modules will no longer be bundled but will be left as require('module').

Detailed overview


This library scans the node_modules folder for all node_modules names, and builds an external function that tells rollup not to bundle those modules, or any sub-modules of theirs.


This library accepts an options object.

options.whitelist (=[])

An array for the external 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 module name and returns whether it should be included.
Important - if you have set aliases in your rollup config with the exact same names as modules in node_modules, you need to whitelist them so rollup will know they should be bundled.

options.importType (='commonjs')

The method in which unbundled modules will be required in the code. Best to leave as commonjs for node modules.

options.modulesDir (='node_modules')

The folder in which to search for the node modules.

options.modulesFromFile (=false)

Read the modules from the package.json file instead of the node_modules folder.


var external = require('@yelo/rollup-node-external');
module.exports = {
    external: external({
        // this WILL include `jquery` and `rollup/hot/dev-server` in the bundle, as well as `lodash/*`
        whitelist: ['jquery', 'rollup/hot/dev-server', /^lodash/]
    plugins: [

For most use cases, the defaults of importType and modulesDir should be used.


npm run test



Current Tags

  • 1.0.1                                ...           latest (3 years ago)

2 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 3
Last Month 5
Dependencies (0)
Dev Dependencies (7)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |