You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+63-63Lines changed: 63 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -18,10 +18,12 @@ To develop and test the core `vite` package:
18
18
19
19
3. If you are developing Vite itself, you can go to `packages/vite` and run `pnpm run dev` to automatically rebuild Vite whenever you change its code.
20
20
21
-
You can alternatively use [Vite.js Docker Dev](https://github.com/nystudio107/vitejs-docker-dev) for a containerized Docker setup for Vite.js development.
22
-
23
21
> If you are working on multiple projects with different versions of pnpm, it's recommended to enable [Corepack](https://github.com/nodejs/corepack) by running `corepack enable`.
24
22
23
+
### Cloning the repo on Windows
24
+
25
+
On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to resolve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also, you may want to [set git `core.symlinks` to `true` to resolve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).
26
+
25
27
### Ignoring commits when running `git blame`
26
28
27
29
We have a `.git-blame-ignore-revs` file to ignore formatting changes.
@@ -39,6 +41,51 @@ To develop the `docs/` site:
39
41
40
42
2. Run `pnpm run docs` in Vite's root folder.
41
43
44
+
### Docs Translation Contribution
45
+
46
+
To add a new language to the Vite docs, see [`vite-docs-template`](https://github.com/tony19/vite-docs-template/blob/main/.github/CONTRIBUTING.md).
47
+
48
+
## Notes on Dependencies
49
+
50
+
Vite aims to be lightweight, and this includes being aware of the number of npm dependencies and their size.
51
+
52
+
We use Rollup to pre-bundle most dependencies before publishing! Therefore, most dependencies, even those used in runtime source code, should be added under `devDependencies` by default. This also creates the following constraints that we need to be aware of in the codebase.
53
+
54
+
### Usage of `require()`
55
+
56
+
In some cases, we intentionally lazy-require some dependencies to improve start-up performance. However, note that we cannot use simple `require('somedep')` calls since these are ignored in ESM files, so the dependency won't be included in the bundle, and the actual dependency won't even be there when published since they are in `devDependencies`.
57
+
58
+
Instead, use `(await import('somedep')).default`.
59
+
60
+
### Think Before Adding a Dependency
61
+
62
+
Most deps should be added to `devDependencies` even if they are needed at runtime. Some exceptions are:
63
+
64
+
- Type packages. Example: `@types/*`.
65
+
- Deps that cannot be properly bundled due to binary files. Example: `esbuild`.
66
+
- Deps that ship their own types that are used in Vite's own public types. Example: `rollup`.
67
+
68
+
Avoid deps with large transitive dependencies that result in bloated size compared to the functionality it provides. For example, `http-proxy` itself is around 380kB in size, but `http-proxy-middleware` pulls in a ton of dependencies that make it 3MB(!) when a minimal custom middleware on top of `http-proxy` only requires a couple of lines of code.
69
+
70
+
### Ensure Type Support
71
+
72
+
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.
73
+
74
+
To get around this, we inline some of these dependencies' types in `packages/vite/src/types`. This way, we can still expose the typing but bundle the dependency's source code.
75
+
76
+
Use `pnpm run build-types-check` to check that the bundled types do not rely on types in `devDependencies`.
77
+
78
+
For types shared between client and node, they should be added into `packages/vite/types`. These types are not bundled and are published as is (though they are still considered internal).
79
+
80
+
## Think Before Adding Yet Another Option
81
+
82
+
We already have many config options, and we should avoid fixing an issue by adding yet another one. Before adding an option, consider whether the problem:
83
+
84
+
- is really worth addressing
85
+
- can be fixed with a smarter default
86
+
- has workaround using existing options
87
+
- can be addressed with a plugin instead
88
+
42
89
## Debugging
43
90
44
91
To use breakpoints and explore code execution, you can use the ["Run and Debug"](https://code.visualstudio.com/docs/editor/debugging) feature from VS Code.
@@ -69,6 +116,10 @@ Some errors are masked and hidden away because of the layers of abstraction and
69
116
70
117
6. To close everything, just stop the test process back in your terminal.
71
118
119
+
### Debug Logging
120
+
121
+
You can set the `--debug` option to turn on debugging logs (e.g. `vite --debug resolve`). To see all debug logs, you can set `vite --debug *`, but be warned that it will be quite noisy. You can run `grep -r "createDebugger('vite:" packages/vite/src/` to see a list of available debug scopes.
122
+
72
123
## Testing Vite against external packages
73
124
74
125
You may wish to test your locally modified copy of Vite against another package that is built with Vite. For pnpm, after building Vite, you can use [`pnpm.overrides`](https://pnpm.io/package_json#pnpmoverrides) to do this. Note that `pnpm.overrides` must be specified in the root `package.json`, and you must list the package as a dependency in the root `package.json`:
@@ -92,11 +143,11 @@ And re-run `pnpm install` to link the package.
92
143
93
144
### Integration Tests
94
145
95
-
Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `playground/vitest*` files.
146
+
Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.ts` and `playground/vitest*.ts` files.
96
147
97
148
Some playgrounds define variants to run the same app using different config setups. By convention, when running a test spec file in a nested folder in `__tests__`, the setup will try to use a config file named `vite.config-{folderName}.js` at the playground's root. You can see an example of variants in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets).
98
149
99
-
Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to resolve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also, you may want to [set git `core.symlinks` to `true` to resolve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).
150
+
Before running the tests, make sure that [Vite has been built](#repo-setup).
100
151
101
152
Each integration test can be run under either dev server mode or build mode.
102
153
@@ -106,17 +157,15 @@ Each integration test can be run under either dev server mode or build mode.
106
157
107
158
-`pnpm run test-build` runs tests only under build mode.
108
159
109
-
-`pnpm run test-serve [match]` or `pnpm run test-build [match]` runs tests in specific packages that match the given filter. e.g. `pnpm run test-serve asset` runs tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode.
110
-
111
-
Note package matching is not available for the `pnpm test` script, which always runs all tests.
160
+
`pnpm run test-serve [match]` or `pnpm run test-build [match]` runs tests in specific packages that match the given filter. e.g. `pnpm run test-serve assets` runs tests for both `playground/assets` and `playground/assets-sanitize` under serve mode. Note package matching is not available for the `pnpm test` script, which always runs all tests.
112
161
113
162
### Unit Tests
114
163
115
164
Other than tests under `playground/` for integration tests, packages might contain unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files.
116
165
117
166
-`pnpm run test-unit` runs unit tests under each package.
118
167
119
-
-`pnpm run test-unit [match]` runs tests in specific packages that match the given filter.
168
+
`pnpm run test-unit [match]` runs tests in specific packages that match the given filter.
Some common test helpers (e.g. `testDir`, `isBuild`, or `editFile`) are also available in the utils. Source code is located at `playground/test-utils.ts`.
134
183
135
-
Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/main/playground/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
184
+
Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/main/playground/vitestSetup.ts#L207-L227) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
136
185
137
186
### Extending the Test Suite
138
187
139
-
To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading is tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite app, there is a test for `?raw` imports with [a section defined in the `index.html` for it](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L121):
188
+
To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading is tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite app, there is a test for `?raw` imports with [a section defined in the `index.html` for it](https://github.com/vitejs/vite/blob/v6.3.1/playground/assets/index.html#L266-L267):
140
189
141
190
```html
142
191
<h2>?raw import</h2>
143
192
<codeclass="raw"></code>
144
193
```
145
194
146
-
This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L151):
195
+
This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/v6.3.1/playground/assets/index.html#L543-L544):
147
196
148
197
```js
149
198
importrawSvgfrom'./nested/fragment.svg?raw'
@@ -158,24 +207,20 @@ function text(el, text) {
158
207
}
159
208
```
160
209
161
-
In the [spec tests](https://github.com/vitejs/vite/blob/main/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
210
+
In the [spec tests](https://github.com/vitejs/vite/blob/v6.3.1/playground/assets/__tests__/assets.spec.ts#L469-L471), the modifications to the DOM listed above are used to test this feature:
In many test cases, we need to mock dependencies using `link:` and `file:` protocols. `pnpm` treats `link:` as symlinks and `file:` as hardlinks. To test dependencies as if they were copied into `node_modules`, use the `file:` protocol. Otherwise, use the `link:` protocol.
172
221
173
222
For a mock dependency, make sure you add a `@vitejs/test-` prefix to the package name. This will avoid possible issues like false-positive alerts.
174
223
175
-
## Debug Logging
176
-
177
-
You can set the `--debug` option to turn on debugging logs (e.g. `vite --debug resolve`). To see all debug logs, you can set `vite --debug *`, but be warned that it will be quite noisy. You can run `grep -r "createDebugger('vite:" packages/vite/src/` to see a list of available debug scopes.
178
-
179
224
## Pull Request Guidelines
180
225
181
226
- Checkout a topic branch from a base branch (e.g. `main`), and merge back against that branch.
@@ -283,48 +328,7 @@ flowchart TD
283
328
• In commit message body, list relevant issues being fixed e.g. 'fix #1234, fix #1235'"]
284
329
```
285
330
286
-
## Notes on Dependencies
287
-
288
-
Vite aims to be lightweight, and this includes being aware of the number of npm dependencies and their size.
289
-
290
-
We use Rollup to pre-bundle most dependencies before publishing! Therefore, most dependencies, even those used in runtime source code, should be added under `devDependencies` by default. This also creates the following constraints that we need to be aware of in the codebase.
291
-
292
-
### Usage of `require()`
293
-
294
-
In some cases, we intentionally lazy-require some dependencies to improve start-up performance. However, note that we cannot use simple `require('somedep')` calls since these are ignored in ESM files, so the dependency won't be included in the bundle, and the actual dependency won't even be there when published since they are in `devDependencies`.
295
-
296
-
Instead, use `(await import('somedep')).default`.
297
-
298
-
### Think Before Adding a Dependency
299
-
300
-
Most deps should be added to `devDependencies` even if they are needed at runtime. Some exceptions are:
301
-
302
-
- Type packages. Example: `@types/*`.
303
-
- Deps that cannot be properly bundled due to binary files. Example: `esbuild`.
304
-
- Deps that ship their own types that are used in Vite's own public types. Example: `rollup`.
305
-
306
-
Avoid deps with large transitive dependencies that result in bloated size compared to the functionality it provides. For example, `http-proxy` itself plus `@types/http-proxy` is a little over 1MB in size, but `http-proxy-middleware` pulls in a ton of dependencies that make it 7MB(!) when a minimal custom middleware on top of `http-proxy` only requires a couple of lines of code.
307
-
308
-
### Ensure Type Support
309
-
310
-
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.
311
-
312
-
To get around this, we inline some of these dependencies' types in `packages/vite/src/types`. This way, we can still expose the typing but bundle the dependency's source code.
313
-
314
-
Use `pnpm run build-types-check` to check that the bundled types do not rely on types in `devDependencies`.
315
-
316
-
For types shared between client and node, they should be added into `packages/vite/types`. These types are not bundled and are published as is (though they are still considered internal). Dependency types within this directory (e.g. `packages/vite/types/chokidar.d.ts`) are deprecated and should be added to `packages/vite/src/types` instead.
317
-
318
-
### Think Before Adding Yet Another Option
319
-
320
-
We already have many config options, and we should avoid fixing an issue by adding yet another one. Before adding an option, consider whether the problem:
321
-
322
-
- is really worth addressing
323
-
- can be fixed with a smarter default
324
-
- has workaround using existing options
325
-
- can be addressed with a plugin instead
326
-
327
-
## Release
331
+
### Release
328
332
329
333
If you have publish access, the steps below explain how to cut a release for a package. There are two phases for the release step: "Release" and "Publish".
330
334
@@ -343,7 +347,3 @@ If you have publish access, the steps below explain how to cut a release for a p
343
347
3. Click on the "Review deployments" button in the yellow box, a popup will appear.
344
348
4. Check "Release" and click "Approve and deploy".
345
349
5. The package will start publishing to npm.
346
-
347
-
## Docs Translation Contribution
348
-
349
-
To add a new language to the Vite docs, see [`vite-docs-template`](https://github.com/tony19/vite-docs-template/blob/main/.github/CONTRIBUTING.md).
0 commit comments