Skip to content

Commit

Permalink
feat: add buildMode flag to ts checker configruration. resolve #65 (#66)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Oct 7, 2021
1 parent df4917e commit 96fc4b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ export default {

### config.typescript

| field | Type | Default value | Description |
| :----------- | -------- | ----------------------------------------------------- | -------------------------------- |
| root | `string` | [Vite config](https://vitejs.dev/config/#root) `root` | Root path to find tsconfig file |
| tsconfigPath | `string` | `"tsconfig.json"` | Relative tsconfig path to `root` |
| field | Type | Default value | Description |
| :----------- | --------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| root | `string` | [Vite config](https://vitejs.dev/config/#root) `root` | Root path to find tsconfig file |
| tsconfigPath | `string` | `"tsconfig.json"` | Relative tsconfig path to `root` |
| 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)) |

### config.vls

Expand Down
19 changes: 14 additions & 5 deletions packages/vite-plugin-checker/src/checkers/typescript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,21 @@ export class TscChecker extends Checker<'typescript'> {
absFilePath: __filename,
build: {
buildBin: (config) => {
if (typeof config.typescript === 'object' && config.typescript.tsconfigPath) {
const tsconfig = config.typescript.root
? path.join(config.typescript.root, config.typescript.tsconfigPath)
: config.typescript.tsconfigPath
return ['tsc', ['--noEmit', '-p', tsconfig]]
if (typeof config.typescript === 'object') {
const { root, tsconfigPath, buildMode } = config.typescript

// Compiler option '--noEmit' may not be used with '--build'
let args = [buildMode ? '-b' : '--noEmit']

// Custom config path
if (tsconfigPath) {
const fullConfigPath = root ? path.join(root, tsconfigPath) : tsconfigPath
args = args.concat(['-p', fullConfigPath])
}

return ['tsc', args]
}

return ['tsc', ['--noEmit']]
},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/vite-plugin-checker/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type TscConfig =
tsconfigPath: string
/** root path of cwd */
root: string
/** root path of cwd */
buildMode: boolean
}>

/** vue-tsc checker configuration */
Expand Down

1 comment on commit 96fc4b4

@tryforceful
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same change needs to be made for vue-tsc, to allow Vue projects with Vue SFC files (.vue) to support the --build flag and Typescript references as well in tsconfig files.

Please sign in to comment.