Git Product home page Git Product logo

babel-plugin-import-resolve-alias's Introduction

babel-plugin-import-resolve-alias

Use aliases to resolve imports. Similar to webpack's resolve-alias.

Inspired by babel-plugin-module-resolver

!important! Affects only import statements, not require calls.

Why does this matter?

Webpack has convenient feature resolve-alias. You can avoid the double dots in your import declarations animals/Cat instead of ../../../animals/Cat.

Using webpack for building packages is ok, but when it comes to running tests, you need some untrivial hacks to make this aliasing feature work. Why don't we just delegate it to Babel? So do we with this plugin.

You can just set up the aliases in the plugin setting in .babelrc and they'll be used by all the Babel invokers, let's say the builder and the test runner.

Differences with webpack and babel-plugin-module-resolver

  1. There is no root option, hence no multiple roots too. The root is always only one and it's the root of the project
  2. Only import statements are handled. require calls remain unchanged.

Usage

Install

Configure

{
  plugins: [
    ['import-resolve-alias', {
      alias: {
        'brilliant-lib': './app/lib', // the dot means path is relative to the project root
        'brilliant': './app/src',
        'one': 'another'
      }
    }]
  ]
}

What to expect

Let us having the config from the previous section and project root is /home/fred/proj/.

  • import brilliant-lib/xyz becomes import /home/fred/proj/app/lib/xyz
  • import brilliant-lib/xyz becomes import /home/fred/proj/app/lib/xyz
  • import one becomes import another

Generally the table from webpack documentation is the reference.

babel-plugin-import-resolve-alias's People

Contributors

shofel avatar

Stargazers

 avatar

Watchers

 avatar  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.