rollup-node-externals

0.0.1-2 • Public • Published

⚠️ 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

Package Sidebar

Install

npm i rollup-node-externals

Weekly Downloads

0

Version

0.0.1-2

License

MIT

Unpacked Size

5.63 kB

Total Files

4

Last publish

Collaborators

  • jnields