Giter VIP home page Giter VIP logo

import.macro's Introduction

English | 简体中文

import.macro

auto import importDeclaration

NPM version Build Status codecov

install

npm i -D import.macro
// or
yarn add -D import.macro

ensure you have installed babel-plugin-macros

.babelrc

{
  plugins: ['babel-plugin-macros']
}

usage

import i from 'import.macro';
i('./a/b');
i('./a/b');

output:

import _aB from './a/b';
_aB;
_aB;

custom import

add a config file:

  • .babel-plugin-macrosrc
  • .babel-plugin-macrosrc.json
  • .babel-plugin-macrosrc.yaml
  • .babel-plugin-macrosrc.yml
  • .babel-plugin-macrosrc.js
  • babel-plugin-macros.config.js
  • babelMacros in package.json

Configuration is as follows:

// .babel-plugin-macrosrc.js
module.exports = {
  importHelper: {
    // import i from 'import.macro'
    defaultImport: {
      transformSource: a => a
    },
    imports: [
      [
        'customImport',
        {
          prefix: '/path/to', // prefix source path
          isDefaultExport: true, // default is true
          transformSource: a => a // before add importDeclaration,transform sourcePath
        }
      ]
    ]
  }
};

then, you can import customImport from import.macro

import { customImport } from 'import.macro';
customImport('filename');

output:

import filename from '../a/b/filename';
filename;

there is also a default import,you can configure it by importHelper.defaultImport.

when start with @, it will be compiled to React component. For example,

import { customImport } from 'import.macro';
customImport('@SomeComponent');

will be compiled to,

<SomeComponent />

import.macro's People

Contributors

dependabot[bot] avatar hhelibeb avatar yoyooyooo avatar

Forkers

hhelibeb

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.