GithubHelp home page GithubHelp logo

storybookjs / paths.macro Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 7.0 98 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
extension .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 '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

barclayd avatar dzienisz avatar igor-dv avatar ndelangen avatar tyankatsu0105 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

paths.macro's Issues

Install failed

I run 'yarn add babel-plugin-module-paths' command, and then I got this feedback below:

PS C:> yarn add babel-plugin-module-paths
yarn add v1.5.1
[1/5] Validating package.json...
[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.npmjs.org/babel-plugin-module-paths: Not found".
info If you think this is a bug, please open a bug report with the information provided in "C:\GoBear\GoBear_DesignPantry\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Has this module been removed from npm?

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.