An open API service indexing awesome lists of open source software.

https://github.com/jetsly/ts-dynamic-plugin

Modular dynamic plugin for TypeScript
https://github.com/jetsly/ts-dynamic-plugin

dynamic ts-dynamic-plugin ts-loader typescript

Last synced: 11 months ago
JSON representation

Modular dynamic plugin for TypeScript

Awesome Lists containing this project

README

          


npm
downloads
travis

# ts-dynamic-plugin

> module dynamic import plugin for TypeScript

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [License](#license)

## Installation

For use with [node](http://nodejs.org) and [npm](https://npmjs.com):

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

## Usage
### With ts-loader

```js
// 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

```js
tsDynamicPluginFactory({
funcName:'formatLocale',
importDecla:`import { formatLocale } from './utils/locale'`
})
```

```js
const word = formatLocale('test')
/** will auto add import **/
import { formatLocale } from './utils/locale'
const word = formatLocale('test')
```

## License

[MIT License](LICENSE.md)