# ts-rename-import-plugin

> Rename import source

Latest version **1.1.6** (published 2022-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-rename-import-plugin
pnpm add ts-rename-import-plugin
yarn add ts-rename-import-plugin
bun add ts-rename-import-plugin
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2022-03-15 |
| First published | 2020-03-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yudu Ban |
| Maintainers | banyudu |

## Links

- npm: https://www.npmjs.com/package/ts-rename-import-plugin
- Repository: https://github.com/banyudu/ts-rename-import-plugin
- Homepage: https://github.com/banyudu/ts-rename-import-plugin#readme
- Issues: https://github.com/banyudu/ts-rename-import-plugin/issues
- npm.io page: https://npm.io/package/ts-rename-import-plugin

## Recent versions

- 1.1.6 (latest) — 2022-03-15
- 1.1.5 — 2022-03-15
- 1.1.4 — 2020-12-15
- 1.1.3 — 2020-12-15
- 1.1.2 — 2020-03-13
- 1.1.1 — 2020-03-13
- 1.0.3 — 2020-03-13

## README

# ts-rename-import-plugin

Transform import paths in typescript compile result.

## UseCases

For example, transform `less` import sentences to `css`:

From

```typescript
import './index.less'
export default () => <div className='hello' />
```

to

```typescript
import './index.css'
export default () => <div className='hello' />
```

## Usage

This plugin can be used programmatically, or by using as a tsconfig.json plugin (*requires [ttypescript](https://github.com/cevek/ttypescript)*).

### In tsconfig.json

To use this plugin in tsconfig.json, add the following config:

```json
{
  "compilerOptions": {
    "plugins": [
      {
        "transform": "ts-rename-import-plugin",
        "type": "config",
        "from": "\\.less$",
        "to": ".css"
      },
    ]
  }
}
```

Then use [ttypescript](https://github.com/cevek/ttypescript) instead of typescript:

```bash
npm i -D ttypescript ts-rename-import-plugin

ttsc # instead of tsc
```

Check out [ttypescript](https://github.com/cevek/ttypescript) for more info.

### Programmatically

```typescript
import tsImportRenamePlugin from "./";
import * as ts from "typescript";

const transform = (source: string) => {
  return ts.transpileModule(source, {
    compilerOptions: {
      module: ts.ModuleKind.CommonJS,
      target: ts.ScriptTarget.ESNext,
      jsx: ts.JsxEmit.React
      // ... other options
    },
    transformers: {
      before: [
        tsImportRenamePlugin({
          transformer: name => name.replace(/\.less$/, '.css')
        })
        /** or
          tsImportRenamePlugin({
            from: '\\.less$',
            to: '.css'
          })
        */
      ]
    }
  }).outputText;
}
});
```

---
_Source: https://npm.io/package/ts-rename-import-plugin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
