rollup-plugin-alias
    Overview
    Documentation
    Tutorials
    Insights
    Code
    Dependencies
    Contributors
    Jobs

rollup-plugin-alias

Resolves aliases with Rollup

2.0.0  •  Updated 7 months ago  •  by rollup  •  MIT License

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({
      resolve: ['.jsx', '.js'], //optional, by default this will just look for .js files or folders
      entries:[
        {find:'something', replacement: '../../../something'}, //the initial example
        {find:'somelibrary-1.0.0', replacement: './mylocallibrary-1.5.0'}, //remap a library with a specific version
        {find:/^i18n\!(.*)/, replacement: '$1.js'}, //remove something in front of the import and append an extension (e.g. loaders, for files that were previously transpiled via the AMD module, to properly handle them in rollup as internals now)
        //for whatever reason, replace all .js extensions with .wasm
        {find:/^(.*)\.js$/, replacement: '$1.wasm'} 
      ]
    })
  ],
};

The order of the entries is important, in that the first rules are applied first.

You can use either simple Strings or Regular Expressions to search in a more distinct and complex manner (e.g. to do partial replacements via subpattern-matching, see aboves example).

License

MIT, see LICENSE for more information

Popularity

Weekly Downloads
39.1K
Stars
169

Maintenance

Development

Last ver 7 months ago
Created 4 years ago
Last commit 5 months ago
18 days between commits

Technology

Node version: 12.6.0
14.4K unpacked

Compliance

MIT License
OSI Approved
0 vulnerabilities

Contributors

21 contributors
Johannes Stein
Maintainer, 24 commits, 8 merges, 1 PRs
Lukas Taegert-Atkinson
Maintainer, 15 commits, 6 merges, 2 PRs
Works at TNG Technology Consulting GmbH
Rich-Harris
Maintainer, 13 commits, 5 merges, 1 PRs
Mohamed H. Hegazy
5 commits, 1 PRs
Works at wuilt
shellscape
Maintainer, 4 commits
Zachary Golba
4 commits, 2 PRs
Works at postlight

Tags

rollup
rollup-plugin
resolve
alias
Openbase helps developers choose among and use millions of open-source packages, so they can build amazing products faster.
FacebookTwitterLinkedIn
© 2020 Devstore, Inc.