You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

babel-plugin-webpack-aliases

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-webpack-aliases

Babel plugin which allows to use webpack aliases


Version published
Weekly downloads
4.6K
increased by26.56%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Build Status Stable version

babel-plugin-webpack-aliases

This is a fork of babel-plugin-webpack-alias

This Babel 6 plugin allows you to use webpack aliases in Babel.

This plugin is simply going to take the aliases defined in your webpack config and replace require paths. It is especially useful when you rely on webpack aliases to keep require paths nicer (and sometimes more consistent depending on your project configuration) but you can't use webpack in a context, for example for unit testing.

Example

With the following webpack.config.js:

module.exports = {
    ...
    resolve: {
        alias: {
            'my-alias': path.join(__dirname, '/alias-folder/js/'),
            'library-name': './library-folder/folder'
        }
    }
    ...
};

A javascript file before compilation:

var MyModule = require('my-alias/src/lib/MyModule');
import MyImport from 'library-name/lib/import/MyImport';

will become:

var MyModule = require('../../alias-folder/js/lib/MyModule');
import MyImport from '../../library-folder/folder/lib/import/MyImport';

This is an example but the plugin will output the relative path depending on the position of the file and the alias folder.

Install

npm install --save-dev babel-plugin-webpack-aliases

Add it as a plugin to your .babelrc file. You can optionally add a path to a config file, for example:

{
   "presets":[ "react", "es2015", "stage-0" ],
   "env": {
    "test": {
      "plugins": [
        [ "babel-plugin-webpack-aliases", { "config": "./webpack.config.test.js" } ]
      ]
    }
  }
}

In this case, the plugin will only be run when NODE_ENV is set to test.

It is also possible to pass a findConfig option, and the plugin will attempt to find the nearest configuration file within the project using find-up. For example:

{
   "presets":[ "react", "es2015", "stage-0" ],
   "env": {
    "test": {
      "plugins": [
        [ "babel-plugin-webpack-aliases", {
            "config": "webpack.config.test.js",
            "findConfig": true
          } ]
      ]
    }
  }
}

Keywords

FAQs

Package last updated on 13 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc