-
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.
- Loading branch information
Showing
3 changed files
with
144 additions
and
19 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,19 +0,0 @@ | ||
### Step to reproduce: | ||
|
||
1. Install dependencies | ||
```bash | ||
yarn | ||
``` | ||
2. Build plugin | ||
```bash | ||
yarn build:plugin | ||
``` | ||
3. Run build and type check | ||
```bash | ||
yarn build:tspc # ✅ working | ||
yarn build:ts-loader # ✅ working | ||
yarn build:fork-ts # ✅ working | ||
yarn watch:tspc # ⛔️ not working | ||
yarn watch:ts-loader # ✅ working | ||
yarn watch:fork-ts # ⛔️ not working | ||
``` | ||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# ts-overrides-plugin example | ||
|
||
Commands: | ||
|
||
```bash | ||
yarn build:tspc | ||
yarn build:ts-loader | ||
yarn build:fork-ts | ||
yarn watch:tspc | ||
yarn watch:ts-loader | ||
yarn watch:fork-ts | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# ts-overrides-plugin | ||
|
||
Плагин для `TypeScript`, который позволяет переопределять `tsconfig` для определенных файлов и папок | ||
|
||
[![typedoc-theme-hierarchy (latest)](https://img.shields.io/npm/v/ts-overrides-plugin)](https://www.npmjs.com/package/ts-overrides-plugin) | ||
[![typedoc-theme-hierarchy (downloads)](https://img.shields.io/npm/dw/ts-overrides-plugin)](https://www.npmjs.com/package/ts-overrides-plugin) | ||
[![typedoc-theme-hierarchy (stars)](https://img.shields.io/github/stars/difuks/ts-overrides-plugin?style=social)](https://github.com/DiFuks/ts-overrides-plugin) | ||
|
||
## Зачем нужен? | ||
|
||
Самый популярный вариант использования – перевод проекта с `strict: false` на `strict: true`, но также подходит для | ||
любых других случаев, когда нужно переопределить настройки tsconfig для определенных файлов или папок. | ||
|
||
## Установка и настройка | ||
|
||
Примеры можно увидеть в папке [`example`](https://github.com/DiFuks/ts-overrides-plugin/tree/main/packages/example). | ||
|
||
### Для использования плагина только в IDE | ||
|
||
Выполнить в терминале: | ||
```bash | ||
yarn add -D ts-overrides-plugin | ||
``` | ||
|
||
В файле `tsconfig.json` добавить: | ||
```json5 | ||
{ | ||
"compilerOptions": { | ||
"plugins": [ | ||
{ | ||
"name": "ts-overrides-plugin", | ||
"config": { | ||
"overrides": [ | ||
{ | ||
"files": ["src/modern/**/*.{ts,tsx}"], // Путь к файлам (glob), для которых нужно переопределить настройки. Не должен начинаться с './' | ||
"compilerOptions": { // Настройки для этих файлов | ||
"strict": true | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
### Для использования в `webpack`, `tsc` | ||
|
||
Для корректной работы плагина в `webpack`, `tsc` необходимо использовать библиотеку [`ts-patch`](https://github.com/nonara/ts-patch). | ||
|
||
Выполнить в терминале: | ||
|
||
```bash | ||
yarn add -D ts-overrides-plugin ts-patch | ||
``` | ||
|
||
В файле `tsconfig.json` добавить: | ||
|
||
```json5 | ||
{ | ||
"compilerOptions": { | ||
"plugins": [ | ||
{ | ||
"name": "ts-overrides-plugin", | ||
"transform": "ts-overrides-plugin/cli", | ||
"transformProgram": true, | ||
"overrides": [ | ||
{ | ||
"files": ["src/modern/**/*.{ts,tsx}"], // Путь к файлам (glob), для которых нужно переопределить настройки. Не должен начинаться с './' | ||
"compilerOptions": { // Настройки для этих файлов | ||
"strict": true, | ||
}, | ||
}, | ||
] | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
Для команды `tsc` – заменить на `tspc` в `package.json`: | ||
|
||
```json5 | ||
{ | ||
"scripts": { | ||
"build": "tspc" | ||
} | ||
} | ||
``` | ||
|
||
Для `ForkTsCheckerWebpackPlugin` в файле `webpack.config.js` добавить: | ||
|
||
```js | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
plugins: [ | ||
new ForkTsCheckerWebpackPlugin({ | ||
typescript: { | ||
typescriptPath: require.resolve('ts-patch/compiler'), | ||
} | ||
}), | ||
], | ||
}; | ||
``` | ||
|
||
Для `ts-loader` в файле `webpack.config.js` добавить: | ||
|
||
```js | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
loader: 'ts-loader', | ||
options: { | ||
compiler: require.resolve('ts-patch/compiler'), | ||
} | ||
}, | ||
], | ||
}, | ||
}; | ||
``` | ||
|
||
## Известные проблемы | ||
|
||
- Пути в `tsconfig` не должны начинаться с `./` | ||
- Плагин не работает в `WebStorm` при использовании `yarn pnp` |