rollup-plugin-resolve-index

0.0.5 • Public • Published

rollup-plugin-resolve-index

Resolves Node-style directories with index.js files in Rollup

Rollup by default doesn't handle resolving ./folder to ./folder/index.js/jsx internally. While there is the rollup-plugin-node-resolve plugin which also resolves directories as well as all dependencies from the node_modules directory, these may sometimes be too much for the use case at hand.

Installation

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

Usage

import { rollup } from 'rollup';
import localResolve from 'rollup-plugin-resolve-index';

// This will resolve `./files` to `./files/index.js` if the file exists
rollup({
  entry: './files',
  plugins: [localResolve()],
});

if you want to resolve a different file than index.js you can pass a extensions option to the plugin:

// This will resolve `./files` to `./files/index.js` or `./files/index.jsx` if the file exists
rollup({
  entry: './files',
  plugins: [localResolve({
    extensions: ['.js', '.jsx'],
  })],
});

Things to improve on

  • Check for index.js file asynchronously
  • Use absolute paths instead of relative ones to be consistent with how Rollup handles modules

License

MIT, see LICENSE for more information

Package Sidebar

Install

npm i rollup-plugin-resolve-index

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

10 kB

Total Files

9

Last publish

Collaborators

  • pengzai-dev