babel-plugin-path-variable
v1.0.0
Published
babel plugin
Downloads
386
Readme
babel-plugin-path-variable
This plugin allows Babel to compile __dirname
and __filename
with string literals.
Installation
npm install --save-dev babel-plugin-path-variable
Example
__dirname
In
file path: /Users/wuchangming/github/babel-plugin-path-variable/test_folder/dirname.js
var dir = __dirname;
Out
var dir = "/Users/wuchangming/github/babel-plugin-path-variable/test_folder";
__filename
In
file path: /Users/wuchangming/github/babel-plugin-path-variable/test_folder/filename.js
var dir = __filename;
Out
var dir = "/Users/wuchangming/github/babel-plugin-path-variable/test_folder/filename.js";
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["path-variable"]
}
Via CLI
babel --plugins path-variable script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["path-variable"]
});