Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v6 - Environment API #16471

Merged
merged 276 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
276 commits
Select commit Hold shift + click to select a range
72150d6
fix: rework backcompat patching of environment config
patak-dev Apr 26, 2024
064f747
chore: merge main
patak-dev Apr 26, 2024
e6fa9d9
release: v6.0.0-alpha.4
patak-dev Apr 26, 2024
a44810a
fix: use environment.plugins during build, support create hook
patak-dev Apr 26, 2024
a8adcac
release: v6.0.0-alpha.5
patak-dev Apr 26, 2024
00079da
fix: custom environment preload injection (#16541)
hi-ogawa Apr 28, 2024
e8473a6
release: v6.0.0-alpha.6
patak-dev Apr 28, 2024
a6fc1dd
feat: this.environment in renderChunk and generateBundle
patak-dev Apr 29, 2024
8231283
feat: remove config.build from dynamicImportVars plugin
patak-dev Apr 29, 2024
bda0dc5
feat: this.environment in buildStart, rework more internal plugins
patak-dev Apr 29, 2024
05943cf
release: v6.0.0-alpha.7
patak-dev Apr 29, 2024
7566aae
feat: define and html plugins
patak-dev Apr 29, 2024
30b2da7
docs: environment.config -> environment.options
patak-dev Apr 29, 2024
527621e
refactor: environment hooks guard
patak-dev Apr 29, 2024
12d467f
fix: keep plugins with create hook
patak-dev Apr 30, 2024
1d9caef
release: v6.0.0-alpha.8
patak-dev Apr 30, 2024
f6dce10
chore: update
patak-dev May 1, 2024
1bcb67d
refactor: move reload on tsconfig change to the server
patak-dev May 1, 2024
6b74221
refactor: bounded plugins factory instead of create hook
patak-dev May 1, 2024
b8ef8ff
fix: module-runner bundle issue with chokidar dep
patak-dev May 1, 2024
d54a88e
chore: merge main
patak-dev May 1, 2024
a09353e
chore: fix lock
patak-dev May 1, 2024
848af54
fix: lint
patak-dev May 1, 2024
2e6abb3
release: v6.0.0-alpha.9
patak-dev May 1, 2024
d213865
feat: sharedDuringBuild for bounded plugins
patak-dev May 2, 2024
57871a4
release: v6.0.0-alpha.10
patak-dev May 2, 2024
35d2d87
docs: shared during build plugins
patak-dev May 2, 2024
1ec07a4
refactor: BoundedPlugin -> IsolatedPlugin
patak-dev May 2, 2024
cf9a79c
chore: merge main
patak-dev May 2, 2024
372a3ad
chore: merge main
patak-dev May 4, 2024
8851d9d
release: v6.0.0-alpha.11
patak-dev May 4, 2024
ffb4aa7
docs: add a note about the "run" method
sheremet-va May 9, 2024
0b3cf69
chore: export ssrTransform
sheremet-va May 20, 2024
a5efd56
fix: remove enforce inside IsolatedPlugins
patak-dev May 20, 2024
8c5674e
chore: respect ssr flag in clientInjectsions transform
patak-dev May 20, 2024
371f7a0
release: v6.0.0-alpha.12
patak-dev May 20, 2024
82111bf
fix: types
patak-dev May 20, 2024
2ae2fca
release: v6.0.0-alpha.13
patak-dev May 20, 2024
3546d1e
fix: revert resolveId importer require
sheremet-va May 20, 2024
34d8518
fix: export isFileLoadingAllowed
sheremet-va May 20, 2024
8ee7fcd
fix: rely on the current environment in resolveId, if known
sheremet-va May 20, 2024
54c219e
feat: back to environmentPlugins hook (#16732)
patak-dev May 20, 2024
3f30147
chore: merge main
patak-dev May 20, 2024
2b2d010
release: v6.0.0-alpha.14
patak-dev May 20, 2024
acb208e
fix hmr connected message on client
ArnaudBarre May 20, 2024
7e9dd25
fix: only join base url in none ssr env
antfu May 20, 2024
0166bfe
fix: svelte back compat
patak-dev May 20, 2024
d231966
release: v6.0.0-alpha.15
patak-dev May 20, 2024
46f21b8
fix: back compat for server.pluginContainer.buildStart
patak-dev May 20, 2024
431455f
chore: remove extra symbol
sheremet-va May 21, 2024
63de43a
fix: keep plugin with environmentPlugins hook
patak-dev May 21, 2024
21225c9
feat: improve Plugin option types
patak-dev May 21, 2024
53734a8
feat: provide `environment` in every hook context
antfu May 21, 2024
89ec69c
fix: argument rollup types for plugin context instead of wrapping
antfu May 21, 2024
a3ee7f5
fix: avoid duplicating values in shared optimizeDeps config (#16737)
dominikg May 21, 2024
4d03124
feat(types): expose PluginEnvironment type
antfu May 22, 2024
d86553a
chore: rename to BaseEnvironment (#16797)
ArnaudBarre May 23, 2024
e36f2f3
feat: only shared plugins (#17289)
patak-dev May 23, 2024
778e39d
fix: backcompat with config.optimizeDeps
patak-dev May 23, 2024
bcb1959
feat: createWeakData
patak-dev May 23, 2024
c7d02ac
release: v6.0.0-alpha.16
patak-dev May 23, 2024
478a9aa
fix: optimizeDeps back compat
patak-dev May 23, 2024
006cfb7
feat: per-environment optimizeDeps entries and force
patak-dev May 23, 2024
5f36aa6
chore: refactor isDepsOptimizerEnabled
patak-dev May 23, 2024
2b69389
feat: reporter as shared plugin using createWeakData (#17293)
patak-dev May 23, 2024
e339959
fix(types): avoid referencing `WeakKey` type
antfu May 24, 2024
11bddb0
fix: handleHotUpdate compat (#17295)
patak-dev May 24, 2024
5c655e6
fix: DepOptimizationConfig
patak-dev May 24, 2024
624e751
fix: dep optimization options
patak-dev May 24, 2024
87bbb04
refactor!: rename to HMRPayload to HotPayload and remove HMRBroadcast…
ArnaudBarre May 24, 2024
09a032e
chore: merge main
patak-dev May 24, 2024
e45881c
release: v6.0.0-alpha.17
patak-dev May 24, 2024
c43c987
refactor: reporter using custom per env api (#17297)
patak-dev May 24, 2024
398a49c
feat(types): `defineVitePlugin` utils (#17298)
antfu May 24, 2024
909fe28
fix: lastHMRTimestamp compat
patak-dev May 24, 2024
b7cbd3d
fix: missing HMRPayload export
ArnaudBarre May 24, 2024
bdd1b91
feat: non-nullable this.environment (#17302)
patak-dev May 24, 2024
611ce5c
fix: check lastHMRTimestamp for entries in moduleRunner
sheremet-va May 24, 2024
d8aa74c
docs: assign code for each deprecation changes, provide option to opt…
antfu May 25, 2024
ca940e8
chore: refactor code style
antfu May 25, 2024
1af7081
chore: ignore test-dts in tsconfig
antfu May 25, 2024
7d78761
test(v6): test ssrLoadModule and virtual module invalidation (#17313)
hi-ogawa May 25, 2024
fd46a2a
fix: correctly invalidate module in the module runner if it was inval…
sheremet-va May 25, 2024
e91e269
fix: check last invalidation time
sheremet-va May 25, 2024
da354ea
fix: default value of `depOptimization`
antfu May 25, 2024
5b76647
chore: typo
antfu May 26, 2024
754bcef
Merge branch 'main' into v6/environment-api
antfu May 28, 2024
03bc590
fix: improve invalidation sync in the module runner
sheremet-va May 28, 2024
a63263c
fix: do not invalidate modules in the runner if not invalidated on th…
sheremet-va May 28, 2024
28e22c6
chore: cleanup
sheremet-va May 28, 2024
c373251
chore: prettier
sheremet-va May 28, 2024
909782f
refactor: plugin container (#17288)
antfu May 29, 2024
6ebb7b9
chore: merge
antfu May 29, 2024
2b3329d
chore: fix build
antfu May 29, 2024
97bfcd2
docs: update
patak-dev Jun 3, 2024
169dd12
docs: update
patak-dev Jun 3, 2024
7fd9596
docs: update
patak-dev Jun 3, 2024
630a75a
docs: update
patak-dev Jun 3, 2024
ef87aa2
docs: update
patak-dev Jun 3, 2024
1f163bf
docs: update
patak-dev Jun 3, 2024
8649049
docs: update
patak-dev Jun 3, 2024
217b2f4
docs: add more context before jumping into details
patak-dev Jun 3, 2024
ec90bd3
docs: update
patak-dev Jun 3, 2024
1e07003
docs: typo
patak-dev Jun 3, 2024
3635ed8
feat: expose createIdResolver
patak-dev Jun 4, 2024
bfe2670
chore: merge main
patak-dev Jun 4, 2024
bbca0b4
release: v6.0.0-alpha.18
patak-dev Jun 4, 2024
40f45f6
chore: merge main
patak-dev Jun 18, 2024
0330e24
chore: merge main
patak-dev Jul 18, 2024
2eaeae9
fix: keep `.hot` for now as a wrapper around `ws`
sheremet-va Jul 19, 2024
8794c49
feat: support `resolve.alias` per environment in Environment API (#17…
lazarv Jul 19, 2024
ccc73a9
fix(module-runner): check if module is curcular using the importers t…
sheremet-va Jul 19, 2024
55904ab
chpre: run prettier
sheremet-va Jul 19, 2024
667c304
fix: this.environment in hotUpdate
patak-dev Jul 19, 2024
fe68914
docs: vd00x to vt00x and hotUpdate future deprecation
patak-dev Jul 19, 2024
01246e5
fix(module-runner): normalize absolute path
sheremet-va Jul 19, 2024
0da251b
chore: fix types
sheremet-va Jul 19, 2024
c661ed5
chore: remove unused type
sheremet-va Jul 19, 2024
8a9d2fd
chore: fix types
sheremet-va Jul 19, 2024
4e81092
chore: add node:sqlite to prefixedbuiltins
sheremet-va Jul 19, 2024
024fe62
docs: vt001/vt002
patak-dev Jul 20, 2024
87bfdec
docs: move stages table into future deprecation warning
patak-dev Jul 20, 2024
51d2736
chore: merge main
patak-dev Jul 20, 2024
90185f7
feat: environment.options.ssr
patak-dev Jul 20, 2024
ecfd810
chore: shared build plugins, vt005
patak-dev Jul 22, 2024
69da154
chore: update sharedConfigBuild
patak-dev Jul 22, 2024
bbc809d
chore: typo
patak-dev Jul 22, 2024
e833edf
chore: ongoing -> current
patak-dev Jul 22, 2024
4b1080a
fix(v6): fix maximum call stack error in `ModuleRunner.isCurcularImpo…
hi-ogawa Jul 23, 2024
d9130ce
docs: use slugs instead of codes for major changes
patak-dev Jul 23, 2024
0ea6ce3
chore: merge main
patak-dev Jul 23, 2024
904087d
feat: environment api config options rework (#17756)
patak-dev Jul 25, 2024
e6979c3
chore: update `environment-react-ssr` build script (#17767)
userquin Jul 26, 2024
26e1c0b
chore: merge main
patak-dev Jul 26, 2024
7a25ff1
chore: cleanup this.environment
patak-dev Jul 26, 2024
a863e9e
chore: remove deprecations
patak-dev Jul 26, 2024
9f8747e
chore: remove unusued condition
patak-dev Jul 26, 2024
0f67e42
chore: reduce diff
patak-dev Jul 26, 2024
9a8c41f
chore: remove unneded condition
patak-dev Jul 26, 2024
6d196f7
chore: merge main
patak-dev Jul 27, 2024
f24b448
release: v6.0.0-alpha.19
patak-dev Jul 27, 2024
f2aee17
fix: single config for single build (#17787)
patak-dev Jul 29, 2024
94576b9
feat: resolved createEnvironment (#17791)
patak-dev Jul 30, 2024
d34aa02
chore: merge main
patak-dev Jul 30, 2024
177a853
test(v6): test nested virtual module invalidation (#17318)
hi-ogawa Aug 1, 2024
c5365d1
refactor: use nanoid instead of copying it (#17864)
sapphi-red Aug 19, 2024
8114815
chore: fix typos and tweak styles
sapphi-red Aug 20, 2024
010a817
docs: consistent major changes titles
patak-dev Aug 20, 2024
a0779d2
chore: remove outdated test config change
patak-dev Aug 20, 2024
2ea6a4b
docs: update backward compatibility section
patak-dev Aug 20, 2024
aafd9ad
chore: remove unneeded this.environment check
patak-dev Aug 20, 2024
ec00425
test: import simple to avoid error during diff
sheremet-va Aug 20, 2024
8b33ca2
docs: update misc (#17863)
sapphi-red Aug 20, 2024
d4d75c2
docs: reload after invalidate (#17861)
sapphi-red Aug 20, 2024
7ad8380
chore: merge main
patak-dev Aug 20, 2024
23b2251
chore: avoid changing preprocessCSS API
patak-dev Aug 20, 2024
07f8b64
chore: client to ssr env in test
patak-dev Aug 20, 2024
26c9f81
chore: lock environment.mode to dev
patak-dev Aug 20, 2024
fcbb602
fix: warmupFile
patak-dev Aug 20, 2024
80a9ad8
chore: make TransformOptions html internal
patak-dev Aug 20, 2024
336514f
chore: lint
patak-dev Aug 20, 2024
cba1f22
chore: remove outdated TODO
patak-dev Aug 20, 2024
af37913
chore: remove resolved TODO
patak-dev Aug 20, 2024
d397b18
chore: rework plugin comment
patak-dev Aug 20, 2024
300935e
chore: remove resolved TODO
patak-dev Aug 21, 2024
23379c5
test: add back pluginContainer buildEnd meta test
patak-dev Aug 21, 2024
4a58c83
fix: don't check server.fs restrictions for consumer server
patak-dev Aug 21, 2024
80242d4
docs: add --app to cli docs
patak-dev Aug 21, 2024
7de3dd5
docs: reword
patak-dev Aug 21, 2024
723ba88
chore: remove resolved TODOs
patak-dev Aug 21, 2024
71f608b
chore: remove force related TODO
patak-dev Aug 21, 2024
d017536
chore: remove client-only scanner TODO
patak-dev Aug 21, 2024
5e84c51
feat: per-environment optimizeDeps.entries
patak-dev Aug 21, 2024
8eec83b
refactor: move safeModulePaths and fsDenyGlob to config
patak-dev Aug 21, 2024
a6da076
fix: revert to hmrPayload.d.ts
patak-dev Aug 21, 2024
bdaa31f
fix: hmrPayload
patak-dev Aug 21, 2024
b3e094a
chore: avoid exposing internal picomatch Matcher type
patak-dev Aug 21, 2024
cdb5568
chore: remove TODO
patak-dev Aug 21, 2024
ac0cd90
refactor: manifest and ssrManifest plugins shared config support
patak-dev Aug 23, 2024
a79bfec
refactor: terser plugin partial shared config support
patak-dev Aug 23, 2024
9449edf
refactor: toOutputFilePathInJS using environment
patak-dev Aug 23, 2024
b80cccc
chore: clarify shared config support for build plugins
patak-dev Aug 23, 2024
74dc901
refactor: vite build cli implementation
patak-dev Aug 23, 2024
76b0384
feat: build.lib per environment
patak-dev Aug 23, 2024
9d5a3ff
fix: use correct createEnvironment for build()
patak-dev Aug 23, 2024
8557195
chore: remove unneded lib mode workaround
patak-dev Aug 23, 2024
baae343
chore: avoid config object in resolveChokidarOptions
patak-dev Aug 23, 2024
410d7bc
refactor: per-environment prepareOutDir
patak-dev Aug 23, 2024
787129a
refactor: per-environment onRollupWarning
patak-dev Aug 23, 2024
badfcec
feat: watch per environment at build
patak-dev Aug 23, 2024
5b1da24
chore: merge main
patak-dev Aug 23, 2024
05f3ab8
fix: patch root config.build for single ssr and client build
patak-dev Aug 23, 2024
60f90a0
revert: esbuild tsconfck reload changes
patak-dev Aug 24, 2024
449a890
refactor: set build.ssr using consumer server
patak-dev Aug 24, 2024
24c23c4
refactor: use consumer instead of environment name for defaults
patak-dev Aug 24, 2024
4a27c46
refactor: use consumer for optimize deps strategy
patak-dev Aug 24, 2024
7552d23
chore: remove nodeCompatible
patak-dev Aug 24, 2024
fed1575
feat: per-environment define
patak-dev Aug 24, 2024
fae8754
docs: api-environment instead of api-vite-environment
patak-dev Aug 24, 2024
897b244
chore: add empty _importGlobMap to avoid hard error in VitePress
patak-dev Aug 24, 2024
fae1071
docs: migration from v5 notes
patak-dev Aug 24, 2024
2207c89
chore: mark environment._options as internal
patak-dev Aug 24, 2024
8c307e0
chore: reduce build options lib diff
patak-dev Aug 24, 2024
53b4efd
chore: reduce diff
patak-dev Aug 24, 2024
6844cd8
release: v6.0.0-alpha.20
patak-dev Aug 24, 2024
439f166
chore: merge main
patak-dev Aug 24, 2024
9346df2
fix: mergeConfig for resolve.noExternal
patak-dev Aug 24, 2024
58d3874
chore: clean up, remove staled TODOs
patak-dev Aug 24, 2024
40544b4
chore: remove unused load fallback plugin
patak-dev Aug 24, 2024
dbee92f
chore: remove TODO
patak-dev Aug 24, 2024
c088986
fix: call buildStart for ssr pluginContainer
patak-dev Aug 24, 2024
b4a05fd
chore: fix typos
sapphi-red Aug 26, 2024
34308fa
fix: backward compat for setting values in resolvedConfig hook (#17947)
sapphi-red Aug 26, 2024
4ef767a
fix: perEnvironmentStartEndDuringDev plugin flag
patak-dev Aug 26, 2024
c27b0d5
fix: moduleGraph.getModulesByFile compat (#17952)
patak-dev Aug 26, 2024
030ed81
fix: moduleGraph back compat
patak-dev Aug 26, 2024
1f77e94
fix: buildStart guard
patak-dev Aug 26, 2024
308554d
chore: merge main
patak-dev Aug 27, 2024
7c6c588
release: v6.0.0-alpha.21
patak-dev Aug 27, 2024
66bfe7b
fix: cache parallel moduleInfo calls (#17957)
sheremet-va Aug 28, 2024
9a369aa
fix: use `optimizeDeps.entries` (#17962)
sapphi-red Aug 28, 2024
06a0409
chore: merge main
patak-dev Aug 28, 2024
e242043
release: v6.0.0-alpha.22
patak-dev Aug 28, 2024
b3061c1
fix: buildStart/resolveId loop
patak-dev Aug 28, 2024
32dd372
fix: pluginContainer.getModuleInfo()
patak-dev Aug 28, 2024
1c3282f
refactor: simplify some code and reduce diff (#17969)
sapphi-red Aug 29, 2024
e700f48
fix(v6): fix `ViteDevServer.environments` type (#17967)
hi-ogawa Aug 29, 2024
0c1cfab
fix: createResolver compat (#17972)
patak-dev Aug 29, 2024
219581c
refactor: cache by url, not by import-url (#17974)
sheremet-va Aug 29, 2024
d7f46e9
release: v6.0.0-alpha.23
patak-dev Aug 30, 2024
2173328
chore: remove staled or not directly related TODOs
patak-dev Aug 31, 2024
1113322
refactor: apply fixes from review
bluwy Sep 2, 2024
628c7a6
refactor: remove `injectInvalidationTimestamp` option (#17994)
sheremet-va Sep 2, 2024
de62669
chore: merge main
patak-dev Sep 2, 2024
c8ea58a
fix: make patch config params internal
patak-dev Sep 2, 2024
bb9e12b
chore: update preprocessCSS comment
bluwy Sep 3, 2024
0f26342
fix: mark ScanEnvironment internal (#18008)
bluwy Sep 3, 2024
6443e48
refactor: update future options (#18011)
bluwy Sep 3, 2024
6d128aa
refactor: environment.reloadModule()
patak-dev Sep 3, 2024
132a250
docs: fix typo
sapphi-red Sep 4, 2024
cb24d3c
fix: expose `createServerHotChannel` and validate `createNodeDevEnvir…
sheremet-va Sep 4, 2024
a7bf7af
docs: `createNodeDevEnvironment` requires `hot` option (#18027)
sapphi-red Sep 4, 2024
a836ea9
fix: always resolve runner's entry point (#18013)
sheremet-va Sep 4, 2024
5e9fec4
docs: add a note about transport between the server and the runner (#…
sheremet-va Sep 4, 2024
bbc5da9
chore: merge main
patak-dev Sep 4, 2024
64ef6e4
refactor: update isFileServingAllowed (#18029)
bluwy Sep 4, 2024
9b8c2af
docs: update changes page (#18026)
bluwy Sep 4, 2024
0250864
feat: global only alias (#18005)
patak-dev Sep 4, 2024
fa819d2
release: v6.0.0-alpha.24
patak-dev Sep 4, 2024
9d421b9
chore: bust alpha changelog, as these commits will be squashed
patak-dev Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,13 @@ export default defineConfig({
link: '/guide/philosophy',
},
{
text: 'Migration from v4',
text: 'Migration from v5',
link: '/guide/migration',
},
{
text: 'Major Changes',
link: '/changes/',
},
],
},
{
Expand All @@ -283,8 +287,8 @@ export default defineConfig({
link: '/guide/api-javascript',
},
{
text: 'Vite Runtime API',
link: '/guide/api-vite-runtime',
text: 'Environment API',
link: '/guide/api-environment',
},
{
text: 'Config Reference',
Expand Down Expand Up @@ -332,6 +336,45 @@ export default defineConfig({
],
},
],
'/changes/': [
{
text: 'Major Changes',
link: '/changes/',
},
{
text: 'Current',
items: [],
},
{
text: 'Future',
items: [
{
text: 'this.environment in Hooks',
link: '/changes/this-environment-in-hooks',
},
{
text: 'HMR hotUpdate Plugin Hook',
link: '/changes/hotupdate-hook',
},
{
text: 'Move to per-environment APIs',
link: '/changes/per-environment-apis',
},
{
text: 'SSR using ModuleRunner API',
link: '/changes/ssr-using-modulerunner',
},
{
text: 'Shared plugins during build',
link: '/changes/shared-plugins-during-build',
},
],
},
{
text: 'Past',
items: [],
},
],
},

outline: {
Expand Down
4 changes: 3 additions & 1 deletion docs/blog/announcing-vite5-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ The new API brings many benefits:

The initial idea [was proposed by Pooya Parsa](https://github.com/nuxt/vite/pull/201) and implemented by [Anthony Fu](https://github.com/antfu) as the [vite-node](https://github.com/vitest-dev/vitest/tree/main/packages/vite-node#readme) package to [power Nuxt 3 Dev SSR](https://antfu.me/posts/dev-ssr-on-nuxt) and later also used as the base for [Vitest](https://vitest.dev). So the general idea of vite-node has been battle-tested for quite some time now. This is a new iteration of the API by [Vladimir Sheremet](https://github.com/sheremet-va), who had already re-implemented vite-node in Vitest and took the learnings to make the API even more powerful and flexible when adding it to Vite Core. The PR was one year in the makings, you can see the evolution and discussions with ecosystem maintainers [here](https://github.com/vitejs/vite/issues/12165).

Read more in the [Vite Runtime API guide](/guide/api-vite-runtime) and [give us feedback](https://github.com/vitejs/vite/discussions/15774).
::: info
The Vite Runtime API evolved into the Module Runner API, released in Vite 6 as part of the [Environment API](/guide/api-environment).
:::

## Features

Expand Down
122 changes: 122 additions & 0 deletions docs/changes/hotupdate-hook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# HMR `hotUpdate` Plugin Hook

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
:::

We're planning to deprecate the `handleHotUpdate` plugin hook in favor of [`hotUpdate` hook](/guide/api-environment#the-hotupdate-hook) to be [Environment API](/guide/api-environment.md) aware, and handle additional watch events with `create` and `delete`.

Affected scope: `Vite Plugin Authors`

::: warning Future Deprecation
`hotUpdate` was first introduced in `v6.0`. The deprecation of `handleHotUpdate` is planned for `v7.0`. We don't yet recommend moving away from `handleHotUpdate` yet. If you want to experiment and give us feedback, you can use the `future.deprecationWarnings.pluginHookHandleHotUpdate` to `true` in your vite config.
:::

## Motivation

The [`handleHotUpdate` hook](/guide/api-plugin.md#handlehotupdate) allows to perform custom HMR update handling. A list of modules to be updated is passed in the `HmrContext`

```ts
interface HmrContext {
file: string
timestamp: number
modules: Array<ModuleNode>
read: () => string | Promise<string>
server: ViteDevServer
}
```

This hook is called once for all environments, and the passed modules have mixed information from the Client and SSR environments only. Once frameworks move to custom environments, a new hook that is called for each of them is needed.

The new `hotUpdate` hook works in the same way as `handleHotUpdate` but it is called for each environment and receives a new `HotUpdateContext` instance:

```ts
interface HotUpdateContext {
type: 'create' | 'update' | 'delete'
file: string
timestamp: number
modules: Array<EnvironmentModuleNode>
read: () => string | Promise<string>
server: ViteDevServer
}
```

The current dev environment can be accessed like in other Plugin hooks with `this.environment`. The `modules` list will now be module nodes from the current environment only. Each environment update can define different update strategies.

This hook is also now called for additional watch events and not only for `'update'`. Use `type` to differentiate between them.

## Migration Guide

Filter and narrow down the affected module list so that the HMR is more accurate.

```js
handleHotUpdate({ modules }) {
return modules.filter(condition)
}

// Migrate to:

hotUpdate({ modules }) {
return modules.filter(condition)
}
```

Return an empty array and perform a full reload:

```js
handleHotUpdate({ server, modules, timestamp }) {
// Invalidate modules manually
const invalidatedModules = new Set()
for (const mod of modules) {
server.moduleGraph.invalidateModule(
mod,
invalidatedModules,
timestamp,
true
)
}
server.ws.send({ type: 'full-reload' })
return []
}

// Migrate to:

hotUpdate({ modules, timestamp }) {
// Invalidate modules manually
const invalidatedModules = new Set()
for (const mod of modules) {
this.environment.moduleGraph.invalidateModule(
mod,
invalidatedModules,
timestamp,
true
)
}
this.environment.hot.send({ type: 'full-reload' })
return []
}
```

Return an empty array and perform complete custom HMR handling by sending custom events to the client:

```js
handleHotUpdate({ server }) {
server.ws.send({
type: 'custom',
event: 'special-update',
data: {}
})
return []
}

// Migrate to...

hotUpdate() {
this.environment.hot.send({
type: 'custom',
event: 'special-update',
data: {}
})
return []
}
```
23 changes: 23 additions & 0 deletions docs/changes/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Major Changes

This is a list of major changes in Vite and planned future deprecations/removals.

## Current

We're reaching out to framework, plugin authors, and users to apply these changes. Deprecation or usage warnings will guide you where possible.

## Future

These are experimental APIs that intend to improve upon current usage patterns. There are more experimental APIs that the ones listed here. For a complete list of experimental features, please checkout the [Experimental Label in Vite GitHub Discussions](https://github.com/vitejs/vite/discussions/categories/feedback?discussions_q=label%3Aexperimental+category%3AFeedback).

We don't recommend switching to these APIs yet. They are included in Vite to help us gather feedback. Please check these proposals and let us know how they work in your use case using the linked Discussions in each.

- [`this.environment` in Hooks](/changes/this-environment-in-hooks)
- [HMR `hotUpdate` Plugin Hook](/changes/hotupdate-hook)
- [Move to per-environment APIs](/changes/per-environment-apis)
- [SSR using `ModuleRunner` API](/changes/ssr-using-modulerunner)
- [Shared plugins during build](/changes/shared-plugins-during-build)

## Past

The following are changes done in the past, where the usage that replaced are no longer used by a significant portion of users.
25 changes: 25 additions & 0 deletions docs/changes/per-environment-apis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Move to per-environment APIs

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
:::

Multiple APIs from ViteDevServer related to module graph has replaced with more isolated Environment APIs.

- `server.moduleGraph` -> [`environment.moduleGraph`](/guide/api-environment#separate-module-graphs)
- `server.transformRequest` -> `environment.transformRequest`
- `server.warmupRequest` -> `environment.warmupRequest`

Affect scope: `Vite Plugin Authors`

::: warning Future Deprecation
The Environment instance was first introduced at `v6.0`. The deprecation of `server.moduleGraph` and other methods that are now in environments is planned for `v7.0`. We don't recommend moving away from server methods yet. To identify your usage, set `future.deprecationWarnings` in your vite config.
:::

## Motivation

// TODO:

## Migration Guide

// TODO:
22 changes: 22 additions & 0 deletions docs/changes/shared-plugins-during-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Shared Plugins during Build

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
:::

// TODO:
See [Shared plugins during build](/guide/api-environment.md#shared-plugins-during-build).

Affect scope: `Vite Plugin Authors`

::: warning Future Default Change
`builder.sharedConfigBuild` was first introduce in `v6.0`. You can set it true to check how your plugins work with a shared config. We're looking for feedback about changing the default in a future major once the plugin ecosystem is ready.
:::

## Motivation

// TODO:

## Migration Guide

// TODO:
21 changes: 21 additions & 0 deletions docs/changes/ssr-using-modulerunner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SSR using `ModuleRunner` API

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
:::

`server.ssrLoadModule` has been replaced by [Module Runner](/guide/api-environment#modulerunner).

Affect scope: `Vite Plugin Authors`

::: warning Future Deprecation
`ModuleRunner` was first introduce in `v6.0`. The deprecation of `server.ssrLoadModule` is planned for a future major. To identify your usage, set `future.deprecationWarnings.ssrLoadModule` to `true` in your vite config.
:::

## Motivation

// TODO:

## Migration Guide

// TODO:
43 changes: 43 additions & 0 deletions docs/changes/this-environment-in-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# `this.environment` in Hooks

::: tip Feedback
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
:::

Before Vite 6, only two environments were available: `client` and `ssr`. A single `options.ssr` plugin hook argument in `resolveId`, `load` and `transform` allowed plugin authors to differentiate between these two environments when processing modules in plugin hooks. In Vite 6, a Vite application can define any number of named environments as needed. We're introducing `this.environment` in the plugin context to interact with the environment of the current module in hooks.

Affect scope: `Vite Plugin Authors`

::: warning Future Deprecation
`this.environment` was introduced in `v6.0`. The deprecation of `options.ssr` is planned for `v7.0`. At that point we'll start recommending migrating your plugins to use the new API. To identify your usage, set `future.deprecationWarnings.pluginHookSsrArgument` to `true` in your vite config.
:::

## Motivation

`this.environment` not only allow the plugin hook implementation to know the current environment name, it also gives access to the environment config options, module graph information, and transform pipeline (`environment.config`, `environment.moduleGraph`, `environment.transformRequest()`). Having the environment instance available in the context allows plugin authors to avoid the dependency of the whole dev server (typically cached at startup through the `configureServer` hook).

## Migration Guide

For the existing plugin to do a quick migration, replace the `options.ssr` argument with `this.environment.name !== 'client'` in the `resolveId`, `load` and `transform` hooks:

```ts
import { Plugin } from 'vite'

export function myPlugin(): Plugin {
return {
name: 'my-plugin',
resolveId(id, importer, options) {
const isSSR = options.ssr // [!code --]
const isSSR = this.environment.name !== 'client' // [!code ++]

if (isSSR) {
// SSR specific logic
} else {
// Client specific logic
}
},
}
}
```

For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name.
9 changes: 8 additions & 1 deletion docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,19 @@ When set to `true`, the build will also generate an SSR manifest for determining

Produce SSR-oriented build. The value can be a string to directly specify the SSR entry, or `true`, which requires specifying the SSR entry via `rollupOptions.input`.

## build.emitAssets

- **Type:** `boolean`
- **Default:** `false`

During non-client builds, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in other environments build. It is responsibility of the framework to merge the assets with a post build step.

## build.ssrEmitAssets

- **Type:** `boolean`
- **Default:** `false`

During the SSR build, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in both the client and SSR build. It is responsibility of the framework to merge the assets with a post build step.
During the SSR build, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in both the client and SSR build. It is responsibility of the framework to merge the assets with a post build step. This option will be replaced by `build.emitAssets` once Environment API is stable.

## build.minify

Expand Down
Loading