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
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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
.
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/"];
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"]