Skip to content

Commit 8bed1de

Browse files
authored
fix: addWatchFile doesn't work if base is specified (fixes #19792) (#19794)
1 parent 0a0c50a commit 8bed1de

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
806806
await Promise.all(
807807
[...pluginImports].map((id) => normalizeUrl(id, 0, true)),
808808
)
809-
).forEach(([url]) => importedUrls.add(url))
809+
).forEach(([url]) => importedUrls.add(stripBase(url, base)))
810810
}
811811
// HMR transforms are no-ops in SSR, so an `accept` call will
812812
// never be injected. Avoid updating the `isSelfAccepting`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { tests } from '../tests'
2+
3+
tests()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, test } from 'vitest'
2+
import { editFile, isBuild, page, untilUpdated } from '~utils'
3+
4+
export const tests = () => {
5+
test('should re-run transform when dependencies are edited', async () => {
6+
expect(await page.textContent('#transform-count')).toBe('1')
7+
8+
if (isBuild) return
9+
editFile('plugin-dep.js', (str) => str)
10+
await untilUpdated(() => page.textContent('#transform-count'), '2')
11+
12+
editFile('plugin-dep-load.js', (str) => str)
13+
await untilUpdated(() => page.textContent('#transform-count'), '3')
14+
})
15+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
import { expect, test } from 'vitest'
2-
import { editFile, isBuild, page, untilUpdated } from '~utils'
1+
import { tests } from './tests'
32

4-
test('should re-run transform when dependencies are edited', async () => {
5-
expect(await page.textContent('#transform-count')).toBe('1')
6-
7-
if (isBuild) return
8-
editFile('plugin-dep.js', (str) => str)
9-
await untilUpdated(() => page.textContent('#transform-count'), '2')
10-
11-
editFile('plugin-dep-load.js', (str) => str)
12-
await untilUpdated(() => page.textContent('#transform-count'), '3')
13-
})
3+
tests()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite'
2+
import baseConfig from './vite.config.js'
3+
4+
export default defineConfig({
5+
...baseConfig,
6+
base: '/vite/',
7+
})

0 commit comments

Comments
 (0)