Skip to content
Provide an alias for modules in Rollup
JavaScript
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Prepare for 1.0 (#48) Dec 11, 2018
test chore: npm audit fix, update dependencies May 31, 2019
.editorconfig Add editorconfig Feb 29, 2016
.eslintignore Prepare for 1.0 (#48) Dec 11, 2018
.eslintrc.yml Prepare for 1.0 (#48) Dec 11, 2018
.gitignore Add gitignore Feb 29, 2016
.travis.yml simplify build Oct 19, 2017
CHANGELOG.md Update changelog Jun 1, 2019
LICENSE Add license Feb 29, 2016
README.md Update travis link (#43) May 2, 2018
appveyor.yml simplify build Oct 19, 2017
package-lock.json 1.5.2 Jun 1, 2019
package.json
rollup.config.js simplify build Oct 19, 2017
yarn.lock chore: update yarn.lock to match package.json updates, kill vulnerabi… Jun 12, 2019

README.md

rollup-plugin-alias

Define aliases when bundling packages with Rollup.

Build Status Dependency Status devDependency Status Coverage Status

Let's take a simple import as an example:

import something from '../../../something';

something();

This probably doesn't look too bad on its own. But imagine this is not the only instance in your code base and after a refactor/restructuring this might fall over. With this plugin in place, you can alias ../../../something with something for readability. In case of a refactor only the alias would need to be changed instead of navigating through the code base and changing all imports.

import something from 'something';

something();

When we write tests, we may want an easier way to access the local library we are testing or mocking libraries. We may also define aliases to counteract "require hell" and get rid of all those ../../../ imports we may have in the process.

For Webpack users: This is a plugin to mimic the resolve.alias functionality in Rollup.

Installation

$ npm install rollup-plugin-alias

Usage

// rollup.config.js
import alias from 'rollup-plugin-alias';

export default {
  input: './src/index.js',
  plugins: [alias({
    somelibrary: './mylocallibrary'
  })],
};

An optional resolve array with file extensions can be provided. If present local aliases beginning with ./ will be resolved to existing files:

// rollup.config.js
import alias from 'rollup-plugin-alias';

export default {
  input: './src/index.js',
  plugins: [alias({
    resolve: ['.jsx', '.js'],
    foo: './bar'  // Will check for ./bar.jsx and ./bar.js
  })],
};

If not given local aliases will be resolved with a .js extension.

License

MIT, see LICENSE for more information

You can’t perform that action at this time.