Skip to content

Commit

Permalink
fix: rollup watch crash on Windows (#13339)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Aug 7, 2023
1 parent b0ebf5c commit 4f582c9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export function renderAssetUrlInJS(
return s
}

// During build, if we don't use a virtual file for public assets, rollup will
// watch for these ids resulting in watching the root of the file system in Windows,
const viteBuildPublicIdPrefix = '\0vite:asset:public'

/**
* Also supports loading plain strings with import text from './foo.txt?raw'
*/
Expand All @@ -154,11 +158,17 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
// will fail to resolve in the main resolver. handle them here.
const publicFile = checkPublicFile(id, config)
if (publicFile) {
return id
return config.command === 'build'
? `${viteBuildPublicIdPrefix}${id}`
: id
}
},

async load(id) {
if (id.startsWith(viteBuildPublicIdPrefix)) {
id = id.slice(viteBuildPublicIdPrefix.length)
}

if (id[0] === '\0') {
// Rollup convention, this id should be handled by the
// plugin that marked it with \0
Expand Down Expand Up @@ -255,7 +265,7 @@ export async function fileToUrl(
function fileToDevUrl(id: string, config: ResolvedConfig) {
let rtn: string
if (checkPublicFile(id, config)) {
// in public dir, keep the url as-is
// in public dir during dev, keep the url as-is
rtn = id
} else if (id.startsWith(config.root)) {
// in project root, infer short public path
Expand Down

0 comments on commit 4f582c9

Please sign in to comment.