JSPM

babel-plugin-transform-dirname-filename

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1368
  • Score
    100M100P100Q112191F
  • License MIT

Babel plugin that rewrites __dirname and __filename to static values

Package Exports

  • babel-plugin-transform-dirname-filename

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-dirname-filename) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

babel-plugin-transform-dirname-filename

Babel plugin that rewrites __dirname and __filename to static values.

Example

Source file t.js:

console.log(__dirname);
console.log(__filename);

Execute normally

$ node t.js
/path/to
/path/to/t.js

Before

$ babel --out-file build/t.js t.js

$ node build/t.js
/path/to/build
/path/to/build/t.js

Notice how the build directory is part of the paths, which is not what we want.

After

$ babel --out-file build/t.js --plugins transform-dirname-filename t.js

$ node build/t.js
/path/to
/path/to/t.js

So even though the generated file is a build/t.js, the __dirname and __filename values will still reference the source file!

Installation

$ npm install babel-plugin-transform-dirname-filename

Usage

.babelrc

{
  "plugins": ["transform-dirname-filename"]
}

Via CLI

$ babel --plugins transform-dirname-filename script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-dirname-filename"]
});