Skip to content

Commit da632bf

Browse files
authored
refactor(types): bundle client types (#9966)
1 parent bafccf5 commit da632bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2216
-2032
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dist
22
playground-temp
33
temp
4-
4+
packages/vite/client/types.d.ts

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ module.exports = defineConfig({
131131
}
132132
},
133133
{
134-
files: ['packages/vite/types/**', '*.spec.ts'],
134+
files: ['packages/vite/src/dep-types/**', '*.spec.ts'],
135135
rules: {
136136
'node/no-extraneous-import': 'off'
137137
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.local
66
*.log
77
/.vscode/
8+
/packages/vite/client/types.d.ts
89
/packages/vite/LICENSE
910
dist
1011
dist-ssr

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ playground/tsconfig-json-load-error/has-error/tsconfig.json
99
playground/html/invalid.html
1010
playground/html/valid.html
1111
playground/worker/classic-worker.js
12+
packages/vite/client/types.d.ts

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ Avoid deps with large transitive dependencies that result in bloated size compar
218218

219219
Vite aims to be fully usable as a dependency in a TypeScript project (e.g. it should provide proper typings for VitePress), and also in `vite.config.ts`. This means technically a dependency whose types are exposed needs to be part of `dependencies` instead of `devDependencies`. However, this also means we won't be able to bundle it.
220220

221-
To get around this, we inline some of these dependencies' types in `packages/vite/types`. This way, we can still expose the typing but bundle the dependency's source code.
221+
To get around this, we inline some of these dependencies' types in `packages/vite/src/dep-types`. This way, we can still expose the typing but bundle the dependency's source code.
222222

223223
Use `pnpm run check-dist-types` to check that the bundled types do not rely on types in `devDependencies`. If you are adding `dependencies`, make sure to configure `tsconfig.check.json`.
224224

docs/guide/api-plugin.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,21 @@ It is possible to type custom events by extending the `CustomEventMap` interface
595595

596596
```ts
597597
// events.d.ts
598-
import 'vite/types/customEvent'
598+
import 'vite'
599+
import 'vite/client/types'
599600
600-
declare module 'vite/types/customEvent' {
601-
interface CustomEventMap {
602-
'custom:foo': { msg: string }
603-
// 'event-key': payload
604-
}
601+
interface MyCustomEventMap {
602+
'custom:foo': { msg: string }
603+
// 'event-key': payload
604+
}
605+
606+
// extend interface for server-side
607+
declare module 'vite' {
608+
interface CustomEventMap extends MyCustomEventMap {}
609+
}
610+
611+
// extend interface for client-side
612+
declare module 'vite/client/types' {
613+
interface CustomEventMap extends MyCustomEventMap {}
605614
}
606615
```

packages/plugin-legacy/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"noUnusedLocals": true,
1313
"esModuleInterop": true,
1414
"paths": {
15-
"types/*": ["../vite/types/*"],
1615
"vite": ["../vite/src/node/index.js"]
1716
}
1817
}

packages/plugin-react/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"noUnusedLocals": true,
1313
"esModuleInterop": true,
1414
"paths": {
15-
"types/*": ["../vite/types/*"],
1615
"vite": ["../vite/src/node/index.js"]
1716
}
1817
}

packages/plugin-vue-jsx/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"noUnusedLocals": true,
1313
"esModuleInterop": true,
1414
"paths": {
15-
"types/*": ["../vite/types/*"],
1615
"vite": ["../vite/src/node/index.js"]
1716
}
1817
}

packages/plugin-vue/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"esModuleInterop": true,
1515
"baseUrl": ".",
1616
"paths": {
17-
"types/*": ["../vite/types/*"],
1817
"vite": ["../vite/src/node/index.js"]
1918
}
2019
}

0 commit comments

Comments
 (0)