GithubHelp home page GithubHelp logo

efidiles / paths.macro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from storybookjs/paths.macro

1.0 1.0 0.0 35 KB

Babel plugin that returns an object containing paths like __dirname and __filename as static values

JavaScript 100.00%

paths.macro's Introduction

Babel paths.macro

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.

Example

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/"];
};

Config

Install:

yarn add paths.macro

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"]
}

paths.macro's People

Contributors

dzienisz avatar igor-dv avatar ndelangen avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.