0.1.2 • Published 5 years ago

ts-dynamic-plugin v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

ts-dynamic-plugin

module dynamic import plugin for TypeScript

Table of Contents

Installation

For use with node and npm:

npm install --save-dev ts-dynamic-plugin

Usage

With ts-loader

// webpack.config.js
const tsDynamicPluginFactory = require('ts-dynamic-plugin')

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

Examples

tsDynamicPluginFactory({
  funcName:'formatLocale',
  importDecla:`import { formatLocale } from './utils/locale'` 
})
const word = formatLocale('test')
/** will auto add import **/
import { formatLocale } from './utils/locale'
const word = formatLocale('test')

License

MIT License