GithubHelp home page GithubHelp logo

babel-plugin-import-glob-meta's Introduction

Babel Plugin Import Glob Meta

A babel plugin that converts imports with glob patterns to multiple imports of the matches found and adds metadata about those matches, including fetching a package.json name property.

Based on the ideas from:

Getting Started

Install with npm:

npm install babel-plugin-import-glob-meta --save-dev

And add it to the babel config as a plugin:

plugins: ["import-glob-meta"];

Usage

This plugin uses is-glob and glob to determine if an import pattern is a glob pattern and to find matching files, respectively.

It only supports default imports with a single specifier:

import modules from "./*/index.js";

This import will then be converted into this:

import _ig from "./moduleA/index.js";
import _ig2 from "./module-B/index.js";

let modules = [
  {
    name: "moduleA",
    value: _ig,
    path: "./moduleA/index.js",
    package: "@modules/moduleA",
  },
  {
    name: "moduleB",
    value: _ig2,
    path: "./module-B/index.js",
    package: "@modules/module-B",
  },
];

Each object in modules is made of the following object properties:

  • name - identifierfy'd name of the parent directory of the file.
  • value - Reference of the placeholder specifier used in the import.
  • path - Relative - to the file where the import is made - path of the matched file.
  • package - Sibling - relative to the glob pattern - package.json name property.

Errors

Whenever a named import or multiple imports are found the following code frame error is thrown:

'Can only import the default export from a glob pattern'

If there's no pattern matches the import is replaced by:

let modules = [];

babel-plugin-import-glob-meta's People

Contributors

danielsousaio 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.