fix: add watch in fallback file load (#14938)

This commit is contained in:
翠 / green 2023-11-10 19:00:22 +09:00 committed by GitHub
parent a92bc617cf
commit b24b95119b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 0 deletions

View File

@ -722,6 +722,9 @@ export async function createPluginContainer(
return result return result
} }
} }
watchFiles.add(id)
if (watcher) ensureWatchedFile(watcher, id, root)
return null return null
}, },

View File

@ -0,0 +1,10 @@
import { expect, test } from 'vitest'
import { editFile, isServe, page, untilUpdated } from '~utils'
test.runIf(isServe)('should watch files outside root', async () => {
expect(await page.textContent('#foo')).toBe('foo')
editFile('foo.js', (code) => code.replace("'foo'", "'foobar'"))
await page.waitForEvent('load')
await untilUpdated(async () => await page.textContent('#foo'), 'foobar')
})

View File

@ -0,0 +1 @@
export const foo = 'foo'

View File

@ -0,0 +1,7 @@
<div id="foo"></div>
<script type="module">
import { foo } from '../foo.js'
document.querySelector('#foo').textContent = foo
</script>

View File

@ -0,0 +1,9 @@
import path from 'node:path'
import url from 'node:url'
import { defineConfig } from 'vite'
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
export default defineConfig({
root: path.join(__dirname, './root'),
})