1.0.0 • Published 6 years ago

babel-plugin-paths v1.0.0

Weekly downloads
19
License
MIT
Repository
-
Last release
6 years ago

babel-plugin-transform-dirname-filename

Babel macro that allows you to "import" the location of the source-file.

The supported paths you can import:

nameexample
npmRoot/Users/you/project
gitRoot/Users/you/project
wd/Users/you/project
fileAbsolute/Users/you/project/src/input.js
fileinput.js
extention.js
filenameinput
baseAbsolute/Users/you/project/src/
base/src/

The default import is equal to base.

Example

Source file input.js:

import base, { filename } from 'babel-plugin-module-paths/paths.macro';

console.log(base, filename);

alert(filename, base);

function usePathsForSomething() {
  return [filename, base];
};

Output:

console.log("/src/", "input");

alert("input", "/src/");

function usePathsForSomething() {
  return ["input", "/src/"];
};

Config

Install:

yarn add babel-plugin-module-paths

If you don't have babel-macros already you must also install that:

yarn add babel-plugin-macros

Ensure you have babel-plugin-macros in your babel config (.babelrc).

{
  "plugins": ["macros"]
}