JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16906
  • Score
    100M100P100Q126198F
  • License MIT

babel-plugin-import TypeScript version

Package Exports

  • ts-import-plugin

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-import-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version CircleCI Coverage Status

ts-import-plugin

Greenkeeper badge

Modular import plugin for TypeScript, compatible with antd, antd-mobile and so on.

webpack template ./webpack.config.js, run: npm start to see the bundle analyzer.

bundle-analyzer

Why use this

transform such code:

import { Alert, Card as C } from 'antd'

into:

import Alert from 'antd/lib/alert'
import 'antd/lib/alert/style/index.less'
import { default as C } from 'antd/lib/card'
import 'antd/lib/card/style/index.less'

Usage

With ts-loader

// webpack.config.js
const tsImportPluginFactory = require('ts-import-plugin')

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.(jsx|tsx|js|ts)$/,
        loader: 'ts-loader',
        options: {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [ tsImportPluginFactory( /** options */) ]
          }),
          compilerOptions: {
            module: 'es2015'
          }
        },
        exclude: /node_modules/
      }
    ]
  },
  // ...
}

With awesome-typescript-loader

Due to https://github.com/s-panferov/awesome-typescript-loader/issues/447, awesome-typescript-loader is not working with any TypeScript plugin, include this one.

Options

options can be an object:

  • libraryName string

    default 'antd'

  • style boolean | 'css'

    default false

  • libraryDirectory string

    default 'lib'

  • camel2DashComponentName boolean

    default true

  • camel2UnderlineComponentName boolean

    default false

example:

tsImportPluginFactory({
  libraryName: 'antd',
  libraryDirectory: 'lib',
  style: true
})
{
  libraryName: 'material-ui',
  libraryDirectory: 'components',
  camel2DashComponentName: false
}

options can be an array:

example:

[
  {
    libraryName: 'antd',
    libraryDirectory: 'lib',
    style: true
  }, {
    libraryName: 'material-ui',
    libraryDirectory: 'components',
    camel2DashComponentName: false
  }
]