Skip to content

Commit 96fc4b4

Browse files
Akiyamkafi3ework
andauthored
feat: add buildMode flag to ts checker configruration. resolve #65 (#66)
* feat: Add support for buld mode fix #65 * fix: forget to return final args * doc: update docs and types * fix: fix type errors * style: code style issues * docs: refine README Co-authored-by: Alexandr Dubinin <[email protected]> Co-authored-by: fi3ework <[email protected]>
1 parent df4917e commit 96fc4b4

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ export default {
141141

142142
### config.typescript
143143

144-
| field | Type | Default value | Description |
145-
| :----------- | -------- | ----------------------------------------------------- | -------------------------------- |
146-
| root | `string` | [Vite config](https://vitejs.dev/config/#root) `root` | Root path to find tsconfig file |
147-
| tsconfigPath | `string` | `"tsconfig.json"` | Relative tsconfig path to `root` |
144+
| field | Type | Default value | Description |
145+
| :----------- | --------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
146+
| root | `string` | [Vite config](https://vitejs.dev/config/#root) `root` | Root path to find tsconfig file |
147+
| tsconfigPath | `string` | `"tsconfig.json"` | Relative tsconfig path to `root` |
148+
| buildMode | `boolean` | `false` | Add [`--build`](https://www.typescriptlang.org/docs/handbook/project-references.html) to `tsc` flag, note that `noEmit` does NOT work if `buildMode` is `true` ([#36917](https://github.com/microsoft/TypeScript/issues/36917)) |
148149

149150
### config.vls
150151

packages/vite-plugin-checker/src/checkers/typescript/main.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,21 @@ export class TscChecker extends Checker<'typescript'> {
123123
absFilePath: __filename,
124124
build: {
125125
buildBin: (config) => {
126-
if (typeof config.typescript === 'object' && config.typescript.tsconfigPath) {
127-
const tsconfig = config.typescript.root
128-
? path.join(config.typescript.root, config.typescript.tsconfigPath)
129-
: config.typescript.tsconfigPath
130-
return ['tsc', ['--noEmit', '-p', tsconfig]]
126+
if (typeof config.typescript === 'object') {
127+
const { root, tsconfigPath, buildMode } = config.typescript
128+
129+
// Compiler option '--noEmit' may not be used with '--build'
130+
let args = [buildMode ? '-b' : '--noEmit']
131+
132+
// Custom config path
133+
if (tsconfigPath) {
134+
const fullConfigPath = root ? path.join(root, tsconfigPath) : tsconfigPath
135+
args = args.concat(['-p', fullConfigPath])
136+
}
137+
138+
return ['tsc', args]
131139
}
140+
132141
return ['tsc', ['--noEmit']]
133142
},
134143
},

packages/vite-plugin-checker/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export type TscConfig =
1111
tsconfigPath: string
1212
/** root path of cwd */
1313
root: string
14+
/** root path of cwd */
15+
buildMode: boolean
1416
}>
1517

1618
/** vue-tsc checker configuration */

0 commit comments

Comments
 (0)