Giter Club home page Giter Club logo

rollup-plugin-alias's Introduction

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

import { rollup } from 'rollup';
import alias from 'rollup-plugin-alias';

rollup({
  entry: './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:

import { rollup } from 'rollup';
import alias from 'rollup-plugin-alias';

rollup({
  entry: './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

rollup-plugin-alias's People

Contributors

frostney avatar zacharygolba avatar rich-harris avatar chiefcll avatar dak0rn avatar yyx990803 avatar szwacz avatar lukeed avatar

Watchers

Mohamed H. Hegazy avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.