🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More →
Socket
Book a DemoSign in
Socket

rollup-node-externals

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-node-externals

module to automatically mark node_modules as externals for rollup

latest
Source
npmnpm
Version
0.0.1-2
Version published
Maintainers
1
Created
Source

⚠️ WARNING ⚠️

This is an unstable release

Rollup node externals

Automatically list package.json dependencies as external

Version Downloads Build Status

Quick usage

npm i -D rollup-node-externals

In rollup.config.js:

var rollupNodeExternals = require('rollup-node-externals');
...
module.exports = {
  // ...
  external: rollupNodeExternals(),
  // ...
};

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 = require('rollup-node-externals');
const rollupPluginCommonjs = require('rollup-plugin-commonjs');

module.exports = {
    // ...
    external: rollupNodeExternals({
        // this will not mark  `jquery` and `lodash/*` as external
        whitelist: ['jquery', /^lodash\//],
    }),
    plugins: [
      rollupPluginCommonjs(),
    ],
    onwarn(warning) {
      // if there is an unresolved import, you forgot to list it in your package.json
      if (warning.code === 'UNRESOLVED_IMPORT') throw new Error(warning.message);
      console.warn(warning.message);
    },
    // ...
};

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:

rollupNodeExternals({
  // load non-javascript files with extensions, presumably via loaders
  whitelist: [/\.(?!js(x?|on))[^.]*$/i],
})

Contributing

Contributions and pull requests welcome. Please make sure your code is covered and passes tests.

License

MIT

Keywords

rollup

FAQs

Package last updated on 07 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts