Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/plugins/pluginDevProxyModuleTopLevelAwait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import { Plugin } from 'vite';

export function PluginDevProxyModuleTopLevelAwait(): Plugin {
const filterFunction = createFilter();
const processedFlag = '/* already-processed-by-dev-proxy-module-top-level-await */';

return {
name: 'dev-proxy-module-top-level-await',
apply: 'serve',
transform(code: string, id: string): { code: string; map: any } | null {
if (code.includes(processedFlag)) {
return null;
}
if (!code.includes('/*mf top-level-await placeholder replacement mf*/')) {
return null;
}
Expand Down Expand Up @@ -90,8 +95,9 @@ export function PluginDevProxyModuleTopLevelAwait(): Plugin {
}
},
});
const transformedCode = magicString.toString();
return {
code: magicString.toString(),
code: `${processedFlag}\n${transformedCode}`,
map: magicString.generateMap({ hires: true }),
};
},
Expand Down