
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
paths.macro
Advanced tools
Babel plugin that returns an object containing paths like __dirname and __filename as static values
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
:
import base, { filename } from 'babel-plugin-module-paths/paths.macro';
console.log(base, filename);
alert(filename, base);
function usePathsForSomething() {
return [filename, base];
};
Output:
console.log("/src/", "input");
alert("input", "/src/");
function usePathsForSomething() {
return ["input", "/src/"];
};
Install:
yarn add babel-plugin-module-paths
If you don't have babel-macros already you must also install that:
yarn add babel-plugin-macros
Ensure you have babel-plugin-macros
in your babel config (.babelrc
).
{
"plugins": ["macros"]
}
FAQs
Babel plugin that returns an object containing paths like __dirname and __filename as static values
The npm package paths.macro receives a total of 6,389 weekly downloads. As such, paths.macro popularity was classified as popular.
We found that paths.macro demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.