Socket
Socket
Sign inDemoInstall

rollup-plugin-node-resolve

Package Overview
Dependencies
3
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-plugin-node-resolve


Version published
Maintainers
1
Created

Package description

What is rollup-plugin-node-resolve?

The rollup-plugin-node-resolve package is a Rollup plugin that allows you to use the Node.js resolution algorithm to locate modules using the Node.js module resolution algorithm, which includes resolving modules from node_modules. This is particularly useful for bundling dependencies from npm.

What are rollup-plugin-node-resolve's main functionalities?

Basic Usage

This basic setup demonstrates how to use the rollup-plugin-node-resolve to resolve modules from node_modules in a Rollup configuration.

const resolve = require('@rollup/plugin-node-resolve');

module.exports = {
  input: 'src/index.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [resolve()]
};

Custom Extensions

This example shows how to configure the plugin to resolve additional file extensions such as .mjs, .json, and .node.

const resolve = require('@rollup/plugin-node-resolve');

module.exports = {
  input: 'src/index.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [
    resolve({
      extensions: ['.mjs', '.js', '.json', '.node']
    })
  ]
};

Using with CommonJS

This example demonstrates how to use rollup-plugin-node-resolve in conjunction with rollup-plugin-commonjs to bundle CommonJS modules.

const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');

module.exports = {
  input: 'src/index.js',
  output: {
    file: 'bundle.js',
    format: 'cjs'
  },
  plugins: [
    resolve(),
    commonjs()
  ]
};

Other packages similar to rollup-plugin-node-resolve

Changelog

Source

1.4.0

  • Pass options.extensions through to node-resolve

Readme

Source

rollup-plugin-node-resolve

Locate modules using the Node resolution algorithm, for using third party modules in node_modules

Installation

npm install --save-dev rollup-plugin-node-resolve

Usage

import { rollup } from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve';

rollup({
  entry: 'main.js',
  plugins: [
    nodeResolve({
      // use "jsnext:main" if possible
      // – see https://github.com/rollup/rollup/wiki/jsnext:main
      jsnext: true,

      // use "main" field or index.js, even if it's not an ES6 module
      // (needs to be converted from CommonJS to ES6
      // – see https://github.com/rollup/rollup-plugin-commonjs
      main: true,

      // if there's something your bundle requires that you DON'T
      // want to include, add it to 'skip'
      skip: [ 'some-big-dependency' ],

      // by default, built-in modules such as `fs` and `path` are
      // treated as external if a local module with the same name
      // can't be found. If you really want to turn off this
      // behaviour for some reason, use `builtins: false`
      builtins: false,

      // some package.json files have a `browser` field which
      // specifies alternative files to load for people bundling
      // for the browser. If that's you, use this option, otherwise
      // pkg.browser will be ignored
      browser: true,

      // not all files you want to resolve are .js files
      extensions: [ '.js', '.json' ]
    })
  ]
}).then( bundle => bundle.write({ dest: 'bundle.js', format: 'iife' }) );

// alongside rollup-plugin-commonjs, for using non-ES6 third party modules
import commonjs from 'rollup-plugin-commonjs';

rollup({
  entry: 'main.js',
  plugins: [
    nodeResolve({ jsnext: true, main: true }),
    commonjs()
  ]
}).then( bundle => bundle.write({ dest: 'bundle.js', format: 'iife' }) );

License

MIT

Keywords

FAQs

Last updated on 07 Feb 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc