Skip to content

Commit d098bfc

Browse files
committed
wip: full bundle dev env
1 parent 7319874 commit d098bfc

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

packages/vite/src/node/plugins/asset.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
304304
}
305305
}
306306
},
307+
308+
watchChange(id) {
309+
assetCache.get(this.environment)?.delete(id)
310+
},
307311
}
308312
}
309313

packages/vite/src/node/server/environments/fullBundleEnvironment.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { RolldownBuild, RolldownOptions } from 'rolldown'
22
import type { Update } from 'types/hmrPayload'
33
import colors from 'picocolors'
4+
import type { FSWatcher } from 'chokidar'
45
import {
56
ChunkMetadataMap,
67
clearLine,
@@ -11,7 +12,7 @@ import { getHmrImplementation } from '../../plugins/clientInjections'
1112
import { DevEnvironment, type DevEnvironmentContext } from '../environment'
1213
import type { ResolvedConfig } from '../../config'
1314
import type { ViteDevServer } from '../../server'
14-
import { arraify, createDebugger } from '../../utils'
15+
import { arraify, createDebugger, tryStatSync } from '../../utils'
1516
import { prepareError } from '../middlewares/error'
1617
import { getShortName } from '../hmr'
1718

@@ -65,6 +66,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
6566
private state: BundleState = { type: 'initial' }
6667
private invalidateCalledModules = new Set<string>()
6768

69+
watcher!: FSWatcher
6870
watchFiles = new Set<string>()
6971
memoryFiles = new MemoryFiles()
7072

@@ -82,8 +84,9 @@ export class FullBundleDevEnvironment extends DevEnvironment {
8284
super(name, config, { ...context, disableDepsOptimizer: true })
8385
}
8486

85-
override async listen(_server: ViteDevServer): Promise<void> {
87+
override async listen(server: ViteDevServer): Promise<void> {
8688
this.hot.listen()
89+
this.watcher = server.watcher
8790

8891
debug?.('INITIAL: setup bundle options')
8992
const rollupOptions = await this.getRolldownOptions()
@@ -368,8 +371,19 @@ export class FullBundleDevEnvironment extends DevEnvironment {
368371
}
369372

370373
// TODO: should this be done for hmr patch file generation?
371-
for (const file of await bundle.watchFiles) {
372-
this.watchFiles.add(file)
374+
const bundleWatchFiles = new Set(await bundle.watchFiles)
375+
for (const file of this.watchFiles) {
376+
if (!bundleWatchFiles.has(file)) {
377+
this.watcher.unwatch(file)
378+
}
379+
}
380+
for (const file of bundleWatchFiles) {
381+
if (!this.watchFiles.has(file)) {
382+
if (tryStatSync(file)) {
383+
this.watcher.add(file)
384+
}
385+
this.watchFiles.add(file)
386+
}
373387
}
374388
if (signal.aborted) return
375389
const postGenerateTime = Date.now()

playground/hmr/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ export default defineConfig({
88
hmrPartialAccept: true,
99
},
1010
build: {
11+
rollupOptions: {
12+
input: [
13+
path.resolve(import.meta.dirname, './index.html'),
14+
path.resolve(import.meta.dirname, './missing-import/index.html'),
15+
path.resolve(
16+
import.meta.dirname,
17+
'./unicode-path/中文-にほんご-한글-🌕🌖🌗/index.html',
18+
),
19+
path.resolve(import.meta.dirname, './counter/index.html'),
20+
path.resolve(
21+
import.meta.dirname,
22+
'./self-accept-within-circular/index.html',
23+
),
24+
path.resolve(import.meta.dirname, './css-deps/index.html'),
25+
],
26+
},
1127
assetsInlineLimit(filePath) {
1228
if (filePath.endsWith('logo-no-inline.svg')) {
1329
return false

0 commit comments

Comments
 (0)