rollup-plugin-resolve2

1.0.0 • Public • Published

rollup-plugin-resolve2

Resolves import statements by using aliases and file extensions when bundling with rollup. Also resolves the file when importing a directory. Based on rollup-plugin-import-resolver (sync with webpack resolve specs)

Install

yarn add --dev rollup-plugin-resolve2

# OR

npm install --save-dev rollup-plugin-resolve2

Options

import importResolver from "rollup-plugin-resolve2";

importResolver({
  // a list of file extensions to check, default = ['.js']
  extensions: ['.js', '.vue'],
  // a list of aliases, default = {}
  alias: {
      'lib': './node_modules/otherlib/src'
  },
  // index file name without extension, default = 'index'
  indexFile: 'index'
});

// if called without options, the defaults are
defaultOptions = {
  extensions: ['js'],
  alias: {},
  indexFile: 'index'
};

Usage scenarios

Consider the following project structure

|-- .. 
'-- src
   |-- ..
   |-- index.js
   '-- utils
       |-- ..
       |-- util1.js
       |-- util2.jsm
       '-- index.js

and plugin options

{
    "extensions": [".js", ".jsm"],
    "alias": {
        "somelib": "./node_modules/other_lib/src/"
    }
}

Resolve "index" file if import points to a directory

// src/index.js

import * as utils from "./utils"; 
// resolved to ./utils/index.js

Resolve extensions

// src/utils/index.js

import util1 from "./util1"; 
// resolved to ./util1.js
import util2 from "./util2"; 
// resolved to ./util2.jsm

export {util1 as u1, util2 as u2};

Resolve aliases

// src/utils/util1.js

import somelib from "somelib";
// resolved to ./node_modules/other_lib/src/index.js

import component1 from "somelib/component1";
// resolved to ./node_modules/other_lib/src/component1.js
// OR if component1 is a folder ./node_modules/other_lib/src/component1/index.js

Package Sidebar

Install

npm i rollup-plugin-resolve2

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.46 kB

Total Files

4

Last publish

Collaborators

  • allex