storybooks/paths.macro

Name: paths.macro

Owner: Storybook

Description: Babel plugin that returns an object containing paths like __dirname and __filename as static values

Created: 2018-01-23 13:25:01.0

Updated: 2018-02-19 14:03:26.0

Pushed: 2018-01-28 08:48:37.0

Homepage: null

Size: 66

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Babel paths.macro

A babel macro that allows you to “import” the location of the source-file.

The supported paths you can import:

name | example ———— | — npmRoot | /Users/you/project gitRoot | /Users/you/project wd | /Users/you/project fileAbsolute | /Users/you/project/src/input.js file | input.js extention | .js filename | input baseAbsolute | /Users/you/project/src/ base | /src/

The default import is equal to base.

Example

Source file input.js:

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

ole.log(base, filename);

t(filename, base);

tion usePathsForSomething() {
turn [filename, base];

Output:

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

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

tion usePathsForSomething() {
turn ["input", "/src/"];

Config

Install:

 add babel-plugin-module-paths

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

 add babel-plugin-macros

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


lugins": ["macros"]


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.