# babel-plugin-transform-dirname-filename **Repository Path**: mirrors_wuchangming/babel-plugin-transform-dirname-filename ## Basic Information - **Project Name**: babel-plugin-transform-dirname-filename - **Description**: Babel plugin that rewrites `__dirname` and `__filename` to static values - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-26 - **Last Updated**: 2025-10-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # babel-plugin-transform-dirname-filename Babel plugin that rewrites `__dirname` and `__filename` to static values. ## Example Source file `t.js`: ```javascript console.log(__dirname); console.log(__filename); ``` ### Execute normally ```sh $ node t.js /path/to /path/to/t.js ``` ### Before ```sh $ 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 ```sh $ 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 ```sh $ npm install babel-plugin-transform-dirname-filename --save-dev ``` ## Usage ### Via `.babelrc` (Recommended) **.babelrc** ```json { "plugins": ["transform-dirname-filename"] } ``` ### Via CLI ```sh $ babel --plugins transform-dirname-filename script.js ``` ### Via Node API ```javascript require("babel-core").transform("code", { plugins: ["transform-dirname-filename"] }); ```