Giter Site home page Giter Site logo

babel-plugin-transform-uiw-import's Introduction

babel-plugin-transform-uiw-import

NPM version Build Status Coverage Status

Modular import uiw plugin for babel. compatible with uiw, antd, lodash, material-ui, and so on.

Usage

npm install babel-plugin-transform-uiw-import --save-dev

Via .babelrc or babel-loader.

{
  "plugins": [
    ["babel-plugin-transform-uiw-import"]
  ]
}
// Input Code
import { Alert } from 'uiw';
import { CopyToClipboard } from 'uiw';
import { DateInput, DatePicker } from 'uiw';

// Output   ↓ ↓ ↓ ↓ ↓ ↓
import Alert from "uiw/lib/cjs/alert";
import CopyToClipboard from "uiw/lib/cjs/copy-to-clipboard";
import DateInput from "uiw/lib/cjs/date-input";
import DatePicker from "uiw/lib/cjs/date-picker";

Output Result

- import { Alert } from 'uiw';
+ import Alert from "uiw/lib/cjs/alert";
- import { CopyToClipboard } from 'uiw';
+ import CopyToClipboard from "uiw/lib/cjs/copy-to-clipboard";
- import { DateInput, DatePicker } from 'uiw';
+ import DateInput from "uiw/lib/cjs/date-input";
+ import DatePicker from "uiw/lib/cjs/date-picker";

Options

export interface Options {
  [key: string]: {
    transform: (importName: string) => void | string;
    preventFullImport?: boolean;
    skipDefaultConversion?: boolean;
  }
}

Default Options

/**
 * Camel conversion horizontal line interval
 * @param {String} name 
 * `CopyToClipboard` => `copy-to-clipboard`
 */
function toLine(name) {
  return name.replace(/\B([A-Z])/g, '-$1').toLowerCase()
}

// The default Options
{
  uiw: {
    transform: importName => `uiw/lib/cjs/${toLine(importName)}`,
  }
}

transform: string | function(importName: string): string

The library name to use instead of the one specified in the import statement. ${member} will be replaced with the import name, aka Grid/Row/Col/etc., and ${1-n} will be replaced by any matched regular expression groups. If using a JS Babel config file, a function may be passed directly. (see Programmatic Usage)

preventFullImport: boolean

default false

Whether or not to throw when an import is encountered which would cause the entire module to be imported.

skipDefaultConversion: boolean

default false

When set to true, will preserve import { X } syntax instead of converting to import X.

// Input Code
import { Grid as gird } from 'uiw';
// Output   ↓ ↓ ↓ ↓ ↓ ↓  ====> skipDefaultConversion: true
import { Grid as gird } from 'uiw/lib/Grid';
- import { Grid as gird } from 'uiw';
+ import { Grid as gird } from 'uiw/lib/Grid';

Programmatic Usage

import plugin from 'babel-plugin-transform-uiw-import'
import { transform } from 'babel-core'

// `CopyToClipboard` => `copy-to-clipboard`
function toLine(name) {
  return name.replace(/\B([A-Z])/g, '-$1').toLowerCase();
}
 
function replace (code) {
  return transform(code, {
    babelrc: false,
    plugins: [
      [plugin, {
        'date-fns': {
          transform: importName => `date-fns/${toLine(importName)}`,
          preventFullImport: true,
        },
      }]
    ],
  }).code;
}
 
replace("import { CopyToClipboard } from 'date-fns';")
//=> "import CopyToClipboard from "date-fns/copy-to-clipboard";"

License

MIT © Kenny Wong

babel-plugin-transform-uiw-import's People

Contributors

jaywcjlove avatar renovate-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

babel-plugin-transform-uiw-import's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update jaywcjlove/changelog-generator action to v1.9.6
  • chore(deps): update jaywcjlove/create-tag-action action to v1.3.20
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency ubuntu to v22
  • chore(deps): update jaywcjlove/changelog-generator action to v2
  • chore(deps): update jaywcjlove/create-tag-action action to v2

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v2
  • actions/setup-node v1
  • jaywcjlove/create-tag-action v1.1.7
  • jaywcjlove/changelog-generator v1.3.9
  • ubuntu 20.04
npm
package.json
  • @babel/types ^7.7.4
  • is-valid-path ^0.1.1
  • @babel/cli 7.13.16
  • @babel/core 7.14.2
  • @babel/plugin-proposal-class-properties 7.13.0
  • @babel/plugin-proposal-do-expressions 7.14.0
  • @babel/plugin-proposal-export-default-from 7.12.13
  • @babel/preset-env 7.14.2
  • babel-core 7.0.0-bridge.0
  • jest 26.6.3
  • @babel/core ^7.0.0-0

  • Check this box to trigger a request for Renovate to run again on this repository

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.