A Babel macro that provides compile-time access to file path information like __dirname and __filename, returning static values rather than runtime variables. Current version 3.0.1. It uses babel-plugin-macros for integration. Key differentiators: no need for __filename polyfills in Node ESM, works with bundlers that support macros, and supports multiple path forms (base, file, extension, filename, npmRoot, gitRoot). Commonly used in tooling and build-time code generation.
npm install paths.macroVerified import paths — ran on the pinned version, not inferred.
Shows how to import and log multiple path macros from a source file. The values are computed at build time.
Install and configure babel-plugin-macros according to the README.
Understand that these values cannot be changed programmatically. Use environment variables or dynamic resolution if runtime flexibility is needed.
Update imports to use 'base' for the directory path, or import 'fileAbsolute' explicitly if needed.
Replace 'wd' with the appropriate path export.
Install paths.macro, babel-plugin-macros, and add 'macros' to babel plugins array.
Ensure your project uses Babel with babel-plugin-macros configured to transform the macro imports.
Change const base = require('paths.macro') to import base from 'paths.macro'.