-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from 2fd/fix/preserve-ts-packages
fix: preserve extension if the import is a package
- Loading branch information
Showing
2 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,59 @@ | ||
# swc-plugin-allow-importing-ts-extensions | ||
|
||
SWC Plugin for allowImportingTsExtensions | ||
|
||
## When and Why | ||
|
||
If you are using SWC to transpile your TypeScript code, and your target is `es2016` or higher, you can use this plugin to import `.ts` files extensions (instead of `.js`), and it will be transpiled to `.js` files. | ||
|
||
## Usage | ||
|
||
First, setup your `tsconfig.json` to allow importing `.ts` files extensions. | ||
|
||
```json | ||
{ | ||
"$schema": "http://json.schemastore.org/swcrc", | ||
"jsc": { | ||
"experimental": { | ||
"plugins": [ | ||
["swc-plugin-allow-importing-ts-extensions", {}] | ||
] | ||
} | ||
```json5 | ||
// tsconfig.json | ||
{ | ||
compilerOptions: { | ||
// ... | ||
noEmit: true, | ||
allowImportingTsExtensions: true, | ||
}, | ||
// ... | ||
} | ||
``` | ||
|
||
Then, add the plugin to your `.swcrc` file. | ||
|
||
```json5 | ||
// .swcrc | ||
{ | ||
$schema: "http://json.schemastore.org/swcrc", | ||
jsc: { | ||
experimental: { | ||
plugins: [["swc-plugin-allow-importing-ts-extensions", {}]], | ||
}, | ||
}, | ||
} | ||
``` | ||
|
||
## Options | ||
|
||
```json5 | ||
// .swcrc | ||
{ | ||
// ... | ||
plugins: [ | ||
[ | ||
"swc-plugin-allow-importing-ts-extensions", | ||
{ | ||
preserveImportExtension: true, // default: false | ||
}, | ||
], | ||
], | ||
// ... | ||
} | ||
``` | ||
|
||
| option | type | default | description | | ||
| ------------------------- | --------- | ------- | -------------------------------------------------------- | | ||
| `preserveImportExtension` | `boolean` | `false` | If `true` all imports with extension `.mts` and `.cts` with be map to `.mjs` and `.cjs` respectively, otherwise it will map to `.js` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters