mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 14:48:41 +00:00
Co-authored-by: Matt Jones <mattjones701@gmail.com>
This commit is contained in:
parent
18c71dcd25
commit
34db08bb8a
@ -231,7 +231,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
throwOutdatedRequest(importer)
|
||||
}
|
||||
|
||||
if (!imports.length) {
|
||||
if (!imports.length && !(this as any)._addedImports) {
|
||||
importerModule.isSelfAccepting = false
|
||||
isDebug &&
|
||||
debug(
|
||||
@ -263,7 +263,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
|
||||
const normalizeUrl = async (
|
||||
url: string,
|
||||
pos: number
|
||||
pos: number,
|
||||
forceSkipImportAnalysis: boolean = false
|
||||
): Promise<[string, string]> => {
|
||||
url = stripBase(url, base)
|
||||
|
||||
@ -364,7 +365,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
const depModule = await moduleGraph.ensureEntryFromUrl(
|
||||
unwrapId(url),
|
||||
ssr,
|
||||
canSkipImportAnalysis(url)
|
||||
canSkipImportAnalysis(url) || forceSkipImportAnalysis
|
||||
)
|
||||
if (depModule.lastHMRTimestamp > 0) {
|
||||
url = injectQuery(url, `t=${depModule.lastHMRTimestamp}`)
|
||||
@ -667,7 +668,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
|
||||
if (pluginImports) {
|
||||
;(
|
||||
await Promise.all(
|
||||
[...pluginImports].map((id) => normalizeUrl(id, 0))
|
||||
[...pluginImports].map((id) => normalizeUrl(id, 0, true))
|
||||
)
|
||||
).forEach(([url]) => importedUrls.add(url))
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
import { expect, test } from 'vitest'
|
||||
import { editFile, page, untilUpdated } from '~utils'
|
||||
|
||||
test('should re-run transform when plugin-dep file is edited', async () => {
|
||||
expect(await page.textContent('#transform-count')).toBe('1')
|
||||
|
||||
await editFile('plugin-dep.js', (str) => str)
|
||||
await untilUpdated(() => page.textContent('#transform-count'), '2')
|
||||
})
|
3
playground/transform-plugin/index.html
Normal file
3
playground/transform-plugin/index.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div id="transform-count"></div>
|
||||
|
||||
<script type="module" src="./index.js"></script>
|
2
playground/transform-plugin/index.js
Normal file
2
playground/transform-plugin/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
// 'TRANSFORM_COUNT' is injected by the transform plugin
|
||||
document.getElementById('transform-count').innerHTML = TRANSFORM_COUNT
|
11
playground/transform-plugin/package.json
Normal file
11
playground/transform-plugin/package.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "test-transform-plugin",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"debug": "node --inspect-brk ../../vite/bin/vite",
|
||||
"serve": "vite preview"
|
||||
}
|
||||
}
|
1
playground/transform-plugin/plugin-dep.js
Normal file
1
playground/transform-plugin/plugin-dep.js
Normal file
@ -0,0 +1 @@
|
||||
// Empty file for detecting changes in tests
|
25
playground/transform-plugin/vite.config.js
Normal file
25
playground/transform-plugin/vite.config.js
Normal file
@ -0,0 +1,25 @@
|
||||
const { resolve } = require('node:path')
|
||||
const { normalizePath } = require('vite')
|
||||
|
||||
let transformCount = 1
|
||||
|
||||
const transformPlugin = {
|
||||
name: 'transform',
|
||||
transform(code, id) {
|
||||
if (id === normalizePath(resolve(__dirname, 'index.js'))) {
|
||||
// Ensure `index.js` is reevaluated if 'plugin-dep.js' is changed
|
||||
this.addWatchFile('./plugin-dep.js')
|
||||
|
||||
return `
|
||||
// Inject TRANSFORM_COUNT
|
||||
let TRANSFORM_COUNT = ${transformCount++};
|
||||
|
||||
${code}
|
||||
`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
plugins: [transformPlugin]
|
||||
}
|
Loading…
Reference in New Issue
Block a user