@nice-labs/ts-import-plugin

2.1.1 • Public • Published

npm version

@nice-labs/ts-import-plugin

Modular import plugin for TypeScript.

The library predefined supports:

  • Functional library
    • lodash
    • ramda
    • async
    • date-fns
    • rxjs@5
    • rxjs@6
  • UI framework
    • react-bootstrap
    • material-ui

Why use this

transform such code:

import _, { add } from "lodash";
import { getTime } from "date-fns";
_.chunk;

into:

import add from "lodash/add";
import _$chunk from "lodash/chunk";
import getTime from "date-fns/get_time";
_$chunk;

Usage with ts-loader (webpack)

import webpack from "webpack";
import tsImportPluginFactory from "@nice-labs/ts-import-plugin";

const configure: webpack.Configuration = {
  // ...
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: require.resolve("ts-loader"),
        options: {
          compilerOptions: {
            module: "esnext"
          },
          getCustomTransformers: () => ({
            before: [
              tsImportPluginFactory(
                // predefined-names or ILibrary objects
                "lodash",
                "date-fns",
                {
                  // ILibrary object
                  libraryName: "antd",
                  libraryPath: "lib",
                  moduleName: "kebabCase",
                  appendPaths: path => `${path}/style/index.less`
                }
              )
            ]
          })
        }
      }
    ]
  }
  // ...
};

export default configure;

ILibrary definition

Reference: src/types.ts

Compatible libraries

Reference: src/libraries.ts

About antd & antd-mobile supports

Reference: test/test/antd.test.ts

License

see LICENSE

Readme

Keywords

none

Package Sidebar

Install

npm i @nice-labs/ts-import-plugin

Weekly Downloads

0

Version

2.1.1

License

MIT

Unpacked Size

50.9 kB

Total Files

36

Last publish

Collaborators

  • jackworks
  • septs