Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1292,10 +1292,8 @@ function wrapEnvironmentResolveId(
}

if ('handler' in hook) {
return {
...hook,
handler,
} as Plugin['resolveId']
hook.handler = handler
return hook
} else {
return handler
}
Expand All @@ -1318,10 +1316,8 @@ function wrapEnvironmentLoad(
}

if ('handler' in hook) {
return {
...hook,
handler,
} as Plugin['load']
hook.handler = handler
return hook
} else {
return handler
}
Expand All @@ -1345,10 +1341,8 @@ function wrapEnvironmentTransform(
}

if ('handler' in hook) {
return {
...hook,
handler,
} as Plugin['transform']
hook.handler = handler
return hook
} else {
return handler
}
Expand Down Expand Up @@ -1388,10 +1382,8 @@ function wrapEnvironmentHook<HookName extends keyof Plugin>(
}

if ('handler' in hook) {
return {
...hook,
handler,
} as Plugin[HookName]
hook.handler = handler
return hook
} else {
return handler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ test('module type should be supported', async () => {
expect(await page.textContent('#module-type-json-virtual-post')).toBe('js')
})

test('lazy hook filter should be applied', async () => {
expect(await page.textContent('#lazy-hook-filter')).toBe('success')
})

tests()
3 changes: 3 additions & 0 deletions playground/transform-plugin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ <h2>Module Type</h2>
<div id="module-type-json-virtual-pre"></div>
<div id="module-type-json-virtual-post"></div>

<h2>Lazy Hook Filter</h2>
<div id="lazy-hook-filter"></div>

<script type="module" src="./index.js"></script>
4 changes: 4 additions & 0 deletions playground/transform-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ document.getElementById('module-type-json-virtual-pre').innerHTML =
barJson.moduleTypePre
document.getElementById('module-type-json-virtual-post').innerHTML =
barJson.moduleTypePost

// 'LAZY_HOOK_FILTER_CONTENT' is replaced by lazy-hook-filter plugin
document.getElementById('lazy-hook-filter').innerHTML =
'LAZY_HOOK_FILTER_CONTENT'
17 changes: 16 additions & 1 deletion playground/transform-plugin/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ const moduleTypePlugins = [
},
]

const lazyHookFilterPlugin = {
name: 'lazy-hook-filter',
options() {
lazyHookFilterPlugin.transform.filter = { id: '**/index.js' }
},
transform: {
filter: /** @type {import('vite').Rolldown.HookFilter} */ ({
id: { exclude: ['**/*.js'] },
}),
handler(code) {
return code.replaceAll('LAZY_HOOK_FILTER_CONTENT', 'success')
},
},
}

export default defineConfig({
plugins: [transformPlugin, moduleTypePlugins],
plugins: [transformPlugin, moduleTypePlugins, lazyHookFilterPlugin],
})
Loading