Skip to content

Commit 4f582c9

Browse files
authored
fix: rollup watch crash on Windows (#13339)
1 parent b0ebf5c commit 4f582c9

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ export function renderAssetUrlInJS(
132132
return s
133133
}
134134

135+
// During build, if we don't use a virtual file for public assets, rollup will
136+
// watch for these ids resulting in watching the root of the file system in Windows,
137+
const viteBuildPublicIdPrefix = '\0vite:asset:public'
138+
135139
/**
136140
* Also supports loading plain strings with import text from './foo.txt?raw'
137141
*/
@@ -154,11 +158,17 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
154158
// will fail to resolve in the main resolver. handle them here.
155159
const publicFile = checkPublicFile(id, config)
156160
if (publicFile) {
157-
return id
161+
return config.command === 'build'
162+
? `${viteBuildPublicIdPrefix}${id}`
163+
: id
158164
}
159165
},
160166

161167
async load(id) {
168+
if (id.startsWith(viteBuildPublicIdPrefix)) {
169+
id = id.slice(viteBuildPublicIdPrefix.length)
170+
}
171+
162172
if (id[0] === '\0') {
163173
// Rollup convention, this id should be handled by the
164174
// plugin that marked it with \0
@@ -255,7 +265,7 @@ export async function fileToUrl(
255265
function fileToDevUrl(id: string, config: ResolvedConfig) {
256266
let rtn: string
257267
if (checkPublicFile(id, config)) {
258-
// in public dir, keep the url as-is
268+
// in public dir during dev, keep the url as-is
259269
rtn = id
260270
} else if (id.startsWith(config.root)) {
261271
// in project root, infer short public path

0 commit comments

Comments
 (0)