vike 0.4.238 → 0.4.239-commit-33e55d4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +10 -0
- package/dist/cjs/node/runtime/index.js +3 -3
- package/dist/cjs/node/runtime/page-files/setup.js +3 -1
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -9
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/csp.js +47 -0
- package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/headersResponse.js +48 -0
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +8 -6
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +5 -3
- package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
- package/dist/cjs/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
- package/dist/cjs/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
- package/dist/cjs/node/runtime/{html → renderPage/html}/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +17 -38
- package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +17 -9
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
- package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +62 -57
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +107 -93
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +27 -13
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +107 -84
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +40 -21
- package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +59 -33
- package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +54 -36
- package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +20 -22
- package/dist/cjs/shared/createGlobalContextShared.js +4 -22
- package/dist/cjs/shared/createPageContextShared.js +2 -2
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +62 -43
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +16 -1
- package/dist/cjs/utils/assertNodeVersion.js +3 -1
- package/dist/cjs/utils/assertVersion.js +26 -5
- package/dist/cjs/utils/joinEnglish.js +2 -1
- package/dist/cjs/utils/virtualFileId.js +15 -11
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +40 -17
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +99 -85
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +39 -11
- package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +44 -29
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +40 -17
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +39 -11
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +39 -11
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -3
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +4 -3
- package/dist/esm/node/prerender/runPrerender.d.ts +61 -16
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +167 -42
- package/dist/esm/node/runtime/globalContext.js +11 -1
- package/dist/esm/node/runtime/index.d.ts +3 -3
- package/dist/esm/node/runtime/index.js +3 -3
- package/dist/esm/node/runtime/page-files/setup.js +3 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -9
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +56 -12
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/csp.d.ts +12 -0
- package/dist/esm/node/runtime/renderPage/csp.js +45 -0
- package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -1
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/headersResponse.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/headersResponse.js +46 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
- package/dist/esm/node/runtime/renderPage/html/injectAssets/inferHtmlTags.d.ts +10 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +7 -5
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/html/injectAssets/mergeScriptTags.d.ts +3 -0
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +6 -4
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
- package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.d.ts +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.d.ts +6 -5
- package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
- package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
- package/dist/esm/node/runtime/{html → renderPage/html}/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +66 -17
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -39
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +122 -32
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
- package/dist/esm/node/runtime/renderPage.d.ts +56 -12
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +18 -10
- package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
- package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
- package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +62 -57
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +107 -91
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +27 -13
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +107 -84
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +41 -22
- package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +58 -33
- package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +56 -38
- package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -8
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +22 -24
- package/dist/esm/shared/createGlobalContextShared.d.ts +75 -19
- package/dist/esm/shared/createGlobalContextShared.js +5 -23
- package/dist/esm/shared/createPageContextShared.d.ts +2 -7
- package/dist/esm/shared/createPageContextShared.js +2 -2
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +91 -31
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +62 -43
- package/dist/esm/types/Config/ConfigResolved.d.ts +8 -0
- package/dist/esm/types/Config.d.ts +14 -6
- package/dist/esm/types/PageContext.d.ts +8 -25
- package/dist/esm/types/VikeNamespace.d.ts +0 -27
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +16 -1
- package/dist/esm/utils/assertNodeVersion.js +3 -1
- package/dist/esm/utils/assertVersion.d.ts +4 -3
- package/dist/esm/utils/assertVersion.js +23 -5
- package/dist/esm/utils/joinEnglish.js +2 -1
- package/dist/esm/utils/virtualFileId.d.ts +4 -0
- package/dist/esm/utils/virtualFileId.js +14 -11
- package/package.json +5 -5
- package/dist/cjs/types/Config/helpers.js +0 -2
- package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +0 -9
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +0 -2
- package/dist/esm/types/Config/PageContextConfig.d.ts +0 -15
- package/dist/esm/types/Config/helpers.d.ts +0 -10
- package/dist/esm/types/Config/helpers.js +0 -1
- /package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
- /package/dist/cjs/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.d.ts +0 -0
- /package/dist/esm/node/runtime/{html → renderPage/html}/stream.d.ts +0 -0
- /package/dist/esm/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
|
@@ -8,73 +8,100 @@ import { getExportNames } from '../shared/parseEsModule.js';
|
|
|
8
8
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
9
9
|
import { isV1Design } from '../shared/resolveVikeConfigInternal.js';
|
|
10
10
|
import { isViteServerSide, isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
11
|
+
const skipNodeModules = '/node_modules/'; // Only apply `.server.js` and `.client.js` to user files
|
|
12
|
+
const filterRolldown = {
|
|
13
|
+
id: {
|
|
14
|
+
include: ['client', 'server'].map((env) => `**/*${getSuffix(env)}*`),
|
|
15
|
+
exclude: [`**${skipNodeModules}**`],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filterFunction = (id) => {
|
|
19
|
+
if (id.includes(skipNodeModules))
|
|
20
|
+
return false;
|
|
21
|
+
if (!id.includes(getSuffix('client')) && !id.includes(getSuffix('server')))
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
11
25
|
function pluginFileEnv() {
|
|
12
26
|
let config;
|
|
13
27
|
let viteDevServer;
|
|
14
28
|
return {
|
|
15
29
|
name: 'vike:pluginFileEnv',
|
|
16
|
-
load
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
load: {
|
|
31
|
+
filter: filterRolldown,
|
|
32
|
+
handler(id, options) {
|
|
33
|
+
// In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
|
|
34
|
+
if (!viteDevServer)
|
|
35
|
+
return;
|
|
36
|
+
if (!isV1Design())
|
|
37
|
+
return;
|
|
38
|
+
if (skip(id, config.root))
|
|
39
|
+
return;
|
|
40
|
+
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
41
|
+
if (id.endsWith('?direct'))
|
|
42
|
+
id = id.slice(0, -1 * '?direct'.length);
|
|
43
|
+
const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
|
|
44
|
+
assert(moduleInfo);
|
|
45
|
+
const importers = Array.from(moduleInfo.importers)
|
|
46
|
+
.map((m) => m.id)
|
|
47
|
+
.filter((id) => id !== null);
|
|
48
|
+
assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
|
|
49
|
+
// In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
|
|
50
|
+
true);
|
|
51
|
+
},
|
|
35
52
|
},
|
|
36
53
|
// In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
|
|
49
|
-
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
50
|
-
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
51
|
-
const { exportNames } = await getExportNames(code);
|
|
52
|
-
return rollupSourceMapRemove([
|
|
53
|
-
`throw new Error(${JSON.stringify(errMsg)});`,
|
|
54
|
-
...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
|
|
55
|
-
].join('\n'));
|
|
56
|
-
},
|
|
57
|
-
generateBundle() {
|
|
58
|
-
Array.from(this.getModuleIds())
|
|
59
|
-
.filter((id) => !skip(id))
|
|
60
|
-
.forEach((moduleId) => {
|
|
61
|
-
const mod = this.getModuleInfo(moduleId);
|
|
62
|
-
const { importers } = mod;
|
|
63
|
-
if (importers.length === 0) {
|
|
64
|
-
// Dynamic imports can only be verified at runtime
|
|
65
|
-
/* This assertion can fail: https://github.com/vikejs/vike/issues/2227
|
|
66
|
-
assert(dynamicImporters.length > 0)
|
|
67
|
-
*/
|
|
54
|
+
transform: {
|
|
55
|
+
filter: filterRolldown,
|
|
56
|
+
async handler(code, id, options) {
|
|
57
|
+
id = normalizeId(id);
|
|
58
|
+
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
59
|
+
if (viteDevServer)
|
|
60
|
+
return;
|
|
61
|
+
if (skip(id, config.root))
|
|
62
|
+
return;
|
|
63
|
+
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
64
|
+
if (!isWrongEnv(id, isServerSide))
|
|
68
65
|
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const { importers } = this.getModuleInfo(id);
|
|
67
|
+
// Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
|
|
68
|
+
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
69
|
+
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
70
|
+
const { exportNames } = await getExportNames(code);
|
|
71
|
+
return rollupSourceMapRemove([
|
|
72
|
+
`throw new Error(${JSON.stringify(errMsg)});`,
|
|
73
|
+
...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
|
|
74
|
+
].join('\n'));
|
|
75
|
+
},
|
|
72
76
|
},
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
generateBundle: {
|
|
78
|
+
handler() {
|
|
79
|
+
Array.from(this.getModuleIds())
|
|
80
|
+
.filter(filterFunction)
|
|
81
|
+
.filter((id) => !skip(id, config.root))
|
|
82
|
+
.forEach((moduleId) => {
|
|
83
|
+
const mod = this.getModuleInfo(moduleId);
|
|
84
|
+
const { importers } = mod;
|
|
85
|
+
if (importers.length === 0) {
|
|
86
|
+
// Dynamic imports can only be verified at runtime
|
|
87
|
+
/* This assertion can fail: https://github.com/vikejs/vike/issues/2227
|
|
88
|
+
assert(dynamicImporters.length > 0)
|
|
89
|
+
*/
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
assertFileEnv(moduleId, isViteServerSide(config, this.environment), importers, false);
|
|
93
|
+
});
|
|
94
|
+
},
|
|
75
95
|
},
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
configResolved: {
|
|
97
|
+
handler(config_) {
|
|
98
|
+
config = config_;
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
configureServer: {
|
|
102
|
+
handler(viteDevServer_) {
|
|
103
|
+
viteDevServer = viteDevServer_;
|
|
104
|
+
},
|
|
78
105
|
},
|
|
79
106
|
};
|
|
80
107
|
function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
|
|
@@ -114,31 +141,27 @@ function pluginFileEnv() {
|
|
|
114
141
|
}
|
|
115
142
|
return errMsg;
|
|
116
143
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
function getModulePath(moduleId) {
|
|
142
|
-
return moduleId.split('?')[0];
|
|
143
|
-
}
|
|
144
|
+
}
|
|
145
|
+
function isWrongEnv(moduleId, isServerSide) {
|
|
146
|
+
const modulePath = getModulePath(moduleId);
|
|
147
|
+
const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
|
|
148
|
+
return modulePath.includes(suffixWrong);
|
|
149
|
+
}
|
|
150
|
+
function skip(id, userRootDir) {
|
|
151
|
+
assert(filterFunction(id));
|
|
152
|
+
// TO-DO/next-major-release: remove
|
|
153
|
+
if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
|
|
154
|
+
return true;
|
|
155
|
+
if (getModulePath(id).endsWith('.css'))
|
|
156
|
+
return true;
|
|
157
|
+
// Skip linked dependencies
|
|
158
|
+
if (!id.startsWith(userRootDir))
|
|
159
|
+
return true;
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
function getSuffix(env) {
|
|
163
|
+
return `.${env}.`;
|
|
164
|
+
}
|
|
165
|
+
function getModulePath(moduleId) {
|
|
166
|
+
return moduleId.split('?')[0];
|
|
144
167
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
export { pluginNonRunnableDev };
|
|
2
|
-
import { createViteRPC, assertIsNotProductionRuntime, requireResolveDistFile, isRunnableDevEnvironment, } from '../utils.js';
|
|
2
|
+
import { createViteRPC, assertIsNotProductionRuntime, requireResolveDistFile, isRunnableDevEnvironment, assert, escapeRegex, isDevCheck, } from '../utils.js';
|
|
3
3
|
import { retrievePageAssetsDev } from '../../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
4
4
|
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
5
5
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
6
6
|
assertIsNotProductionRuntime();
|
|
7
|
+
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js');
|
|
8
|
+
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js');
|
|
9
|
+
const filterRolldown = {
|
|
10
|
+
id: {
|
|
11
|
+
include: [distFileIsNonRunnableDev, distFileGlobalContext].map((filePath) => new RegExp(`^${escapeRegex(filePath)}($|${escapeRegex('?')}.*)`)),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const filterFunction = (id) => {
|
|
15
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
16
|
+
return idWithoutQuery === distFileIsNonRunnableDev || idWithoutQuery === distFileGlobalContext;
|
|
17
|
+
};
|
|
7
18
|
function getViteRpcFunctions(viteDevServer) {
|
|
8
19
|
return {
|
|
9
20
|
async transformIndexHtmlRPC(html) {
|
|
@@ -18,32 +29,40 @@ function getViteRpcFunctions(viteDevServer) {
|
|
|
18
29
|
};
|
|
19
30
|
}
|
|
20
31
|
function pluginNonRunnableDev() {
|
|
21
|
-
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js');
|
|
22
|
-
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js');
|
|
23
32
|
let config;
|
|
24
33
|
return {
|
|
25
34
|
name: 'vike:pluginNonRunnableDev',
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
36
|
+
configureServer: {
|
|
37
|
+
handler(viteDevServer) {
|
|
38
|
+
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
39
|
+
},
|
|
28
40
|
},
|
|
29
|
-
configResolved
|
|
30
|
-
|
|
41
|
+
configResolved: {
|
|
42
|
+
handler(config_) {
|
|
43
|
+
config = config_;
|
|
44
|
+
},
|
|
31
45
|
},
|
|
32
|
-
transform
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
transform: {
|
|
47
|
+
filter: filterRolldown,
|
|
48
|
+
handler(code, id) {
|
|
49
|
+
assert(config._isDev);
|
|
50
|
+
assert(filterFunction(id));
|
|
51
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
52
|
+
if (isRunnableDevEnvironment(this.environment))
|
|
53
|
+
return;
|
|
54
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
55
|
+
if (idWithoutQuery === distFileIsNonRunnableDev) {
|
|
56
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
|
|
57
|
+
}
|
|
58
|
+
if (idWithoutQuery === distFileGlobalContext) {
|
|
59
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
60
|
+
}
|
|
61
|
+
return getMagicStringResult();
|
|
62
|
+
},
|
|
47
63
|
},
|
|
48
64
|
};
|
|
49
65
|
}
|
|
66
|
+
function getIdWithoutQuery(id) {
|
|
67
|
+
return id.split('?')[0];
|
|
68
|
+
}
|
|
@@ -14,32 +14,38 @@ function pluginPreview() {
|
|
|
14
14
|
return {
|
|
15
15
|
name: 'vike:pluginPreview',
|
|
16
16
|
apply: applyPreview,
|
|
17
|
-
config
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
config: {
|
|
18
|
+
handler() {
|
|
19
|
+
return {
|
|
20
|
+
appType: 'custom',
|
|
21
|
+
};
|
|
22
|
+
},
|
|
21
23
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
configResolved: {
|
|
25
|
+
async handler(config_) {
|
|
26
|
+
config = config_;
|
|
27
|
+
vikeConfig = await getVikeConfigInternal();
|
|
28
|
+
logDockerHint(config.preview.host);
|
|
29
|
+
// vikeConfig = await getVikeConfig(config)
|
|
30
|
+
},
|
|
27
31
|
},
|
|
28
|
-
configurePreviewServer
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
configurePreviewServer: {
|
|
33
|
+
handler(server) {
|
|
34
|
+
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
35
|
+
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
36
|
+
config.appType = 'mpa'
|
|
37
|
+
*/
|
|
38
|
+
return () => {
|
|
39
|
+
const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = vikeConfig.prerenderContext;
|
|
40
|
+
assertDist(isPrerenderingEnabledForAllPages);
|
|
41
|
+
// We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
|
|
42
|
+
addStaticAssetsMiddleware(server.middlewares);
|
|
43
|
+
if (!isPrerenderingEnabledForAllPages) {
|
|
44
|
+
addSsrMiddleware(server.middlewares, config, true, isPrerenderingEnabled);
|
|
45
|
+
}
|
|
46
|
+
addStatic404Middleware(server.middlewares);
|
|
47
|
+
};
|
|
48
|
+
},
|
|
43
49
|
},
|
|
44
50
|
};
|
|
45
51
|
function assertDist(isPrerenderingEnabledForAllPages) {
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export { pluginReplaceConstants };
|
|
2
|
+
export { filterFunction };
|
|
3
|
+
export { filterRolldown };
|
|
2
4
|
import type { Plugin } from 'vite';
|
|
5
|
+
declare const filterRolldown: {
|
|
6
|
+
id: {
|
|
7
|
+
exclude: string;
|
|
8
|
+
};
|
|
9
|
+
code: {
|
|
10
|
+
include: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
declare const filterFunction: (id: string, code: string) => boolean;
|
|
3
14
|
declare function pluginReplaceConstants(): Plugin;
|
|
@@ -1,49 +1,74 @@
|
|
|
1
1
|
export { pluginReplaceConstants };
|
|
2
|
+
export { filterFunction };
|
|
3
|
+
export { filterRolldown };
|
|
2
4
|
import { assert, assertPosixPath } from '../utils.js';
|
|
3
5
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
4
6
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
5
7
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
8
|
+
const skipNodeModules = '/node_modules/';
|
|
9
|
+
const skipIrrelevant = 'import.meta.env.';
|
|
10
|
+
const filterRolldown = {
|
|
11
|
+
id: {
|
|
12
|
+
exclude: `**${skipNodeModules}**`,
|
|
13
|
+
},
|
|
14
|
+
code: {
|
|
15
|
+
include: skipIrrelevant,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filterFunction = (id, code) => {
|
|
19
|
+
if (id.includes(skipNodeModules))
|
|
20
|
+
return false;
|
|
21
|
+
if (!code.includes(skipIrrelevant))
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
6
25
|
function pluginReplaceConstants() {
|
|
7
26
|
let config;
|
|
8
27
|
return {
|
|
9
28
|
name: 'vike:pluginReplaceConstants',
|
|
10
29
|
enforce: 'post',
|
|
11
30
|
apply: 'build',
|
|
12
|
-
configResolved
|
|
13
|
-
|
|
31
|
+
configResolved: {
|
|
32
|
+
handler(config_) {
|
|
33
|
+
config = config_;
|
|
34
|
+
},
|
|
14
35
|
},
|
|
15
|
-
transform
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (config._skipVikeReplaceConstants?.(id))
|
|
31
|
-
return;
|
|
32
|
-
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
33
|
-
const constantsMap = [];
|
|
34
|
-
constantsMap.push({
|
|
35
|
-
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
36
|
-
replacement: !isViteServerSide_extraSafe(config, this.environment, options),
|
|
37
|
-
});
|
|
38
|
-
constantsMap.forEach(({ constants, replacement }) => {
|
|
39
|
-
if (!constants.some((c) => code.includes(c)))
|
|
36
|
+
transform: {
|
|
37
|
+
filter: filterRolldown,
|
|
38
|
+
handler(code, id, options) {
|
|
39
|
+
id = normalizeId(id);
|
|
40
|
+
assertPosixPath(id);
|
|
41
|
+
assertPosixPath(config.root);
|
|
42
|
+
if (!id.startsWith(config.root))
|
|
43
|
+
return; // skip linked dependencies
|
|
44
|
+
assert(filterFunction(id, code));
|
|
45
|
+
const isBuild = config.command === 'build';
|
|
46
|
+
assert(isBuild);
|
|
47
|
+
// Used by vike.dev
|
|
48
|
+
// https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
if (config._skipVikeReplaceConstants?.(id))
|
|
40
51
|
return;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
53
|
+
const constantsMap = [];
|
|
54
|
+
constantsMap.push({
|
|
55
|
+
constants: [
|
|
56
|
+
'pageContext.isClientSide',
|
|
57
|
+
'globalContext.isClientSide',
|
|
58
|
+
'pageContext.globalContext.isClientSide',
|
|
59
|
+
],
|
|
60
|
+
replacement: !isViteServerSide_extraSafe(config, this.environment, options),
|
|
61
|
+
});
|
|
62
|
+
constantsMap.forEach(({ constants, replacement }) => {
|
|
63
|
+
if (!constants.some((c) => code.includes(c)))
|
|
64
|
+
return;
|
|
65
|
+
const regExp = getConstantRegExp(constants);
|
|
66
|
+
magicString.replaceAll(regExp, JSON.stringify(replacement));
|
|
67
|
+
});
|
|
68
|
+
if (!magicString.hasChanged())
|
|
69
|
+
return null;
|
|
70
|
+
return getMagicStringResult();
|
|
71
|
+
},
|
|
47
72
|
},
|
|
48
73
|
};
|
|
49
74
|
}
|
|
@@ -20,8 +20,10 @@ function pluginSetGlobalContext() {
|
|
|
20
20
|
markSetup_viteDevServer();
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
|
-
configurePreviewServer
|
|
24
|
-
|
|
23
|
+
configurePreviewServer: {
|
|
24
|
+
handler() {
|
|
25
|
+
markSetup_vitePreviewServer();
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
28
|
config: {
|
|
27
29
|
order: 'pre',
|
package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { generateVirtualFileGlobalEntryWithOldDesign };
|
|
2
|
-
import { assert, assertPosixPath, scriptFileExtensionPattern, debugGlob,
|
|
2
|
+
import { assert, assertPosixPath, scriptFileExtensionPattern, debugGlob, isVersionMatch, assertWarning, } from '../../utils.js';
|
|
3
3
|
import { parseVirtualFileId } from '../../../shared/virtualFileId.js';
|
|
4
4
|
import { version as viteVersion } from 'vite';
|
|
5
5
|
import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
@@ -139,7 +139,7 @@ function getGlobs(globRoots, isBuild, fileType, query, isV1Design) {
|
|
|
139
139
|
const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
|
|
140
140
|
const globOptions = { eager: isEager };
|
|
141
141
|
if (query) {
|
|
142
|
-
const isNewViteInterface =
|
|
142
|
+
const isNewViteInterface = isVersionMatch(viteVersion, ['5.1.0']);
|
|
143
143
|
if (isNewViteInterface &&
|
|
144
144
|
// When used for the old design, the new syntax breaks Vike's CI (surprinsigly so). I couldn't reproduce locally (I didn't dig much).
|
|
145
145
|
isV1Design) {
|
|
@@ -2,61 +2,77 @@ export { pluginVirtualFiles };
|
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
3
|
import { generateVirtualFilePageEntry } from './pluginVirtualFiles/generateVirtualFilePageEntry.js';
|
|
4
4
|
import { generateVirtualFileGlobalEntryWithOldDesign } from './pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js';
|
|
5
|
-
import { assert, assertPosixPath, isScriptFile, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, } from '../utils.js';
|
|
5
|
+
import { assert, assertPosixPath, isScriptFile, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, escapeRegex, virtualFileIdPrefix1, virtualFileIdPrefix2, } from '../utils.js';
|
|
6
6
|
import { parseVirtualFileId } from '../../shared/virtualFileId.js';
|
|
7
7
|
import { reloadVikeConfig, isV1Design, getVikeConfigInternalOptional } from '../shared/resolveVikeConfigInternal.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { logConfigInfo } from '../shared/loggerNotProd.js';
|
|
10
10
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
11
|
-
import { updateUserFiles } from '../../runtime/globalContext.js';
|
|
11
|
+
import { isRunnable, updateUserFiles } from '../../runtime/globalContext.js';
|
|
12
12
|
import { isPlusFile } from '../shared/resolveVikeConfigInternal/crawlPlusFiles.js';
|
|
13
13
|
import { isTemporaryBuildFile } from '../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
14
14
|
import { getVikeConfigError } from '../../shared/getVikeConfigError.js';
|
|
15
|
+
const filterRolldown = {
|
|
16
|
+
id: {
|
|
17
|
+
include: new RegExp(`^(${escapeRegex(virtualFileIdPrefix1)}|${escapeRegex(virtualFileIdPrefix2)})`),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const filterFunction = (id) => isVirtualFileId(id);
|
|
15
21
|
function pluginVirtualFiles() {
|
|
16
22
|
let config;
|
|
17
23
|
return {
|
|
18
24
|
name: 'vike:pluginVirtualFiles',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
configResolved: {
|
|
26
|
+
async handler(config_) {
|
|
27
|
+
config = config_;
|
|
28
|
+
// TO-DO/next-major-release: remove
|
|
29
|
+
if (!isV1Design())
|
|
30
|
+
config.experimental.importGlobRestoreExtension = true;
|
|
31
|
+
},
|
|
24
32
|
},
|
|
25
|
-
resolveId
|
|
26
|
-
|
|
33
|
+
resolveId: {
|
|
34
|
+
filter: filterRolldown,
|
|
35
|
+
handler(id) {
|
|
36
|
+
assert(filterFunction(id));
|
|
27
37
|
return addVirtualFileIdPrefix(id);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
async handleHotUpdate(ctx) {
|
|
31
|
-
try {
|
|
32
|
-
return await handleHotUpdate(ctx, config);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
// Vite swallows errors thrown by handleHotUpdate()
|
|
36
|
-
console.error(err);
|
|
37
|
-
throw err;
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
39
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const isDev = config._isDev;
|
|
45
|
-
assert(typeof isDev === 'boolean');
|
|
46
|
-
const idParsed = parseVirtualFileId(id);
|
|
47
|
-
if (idParsed) {
|
|
48
|
-
if (idParsed.type === 'page-entry') {
|
|
49
|
-
const code = await generateVirtualFilePageEntry(id, isDev);
|
|
50
|
-
return code;
|
|
40
|
+
handleHotUpdate: {
|
|
41
|
+
async handler(ctx) {
|
|
42
|
+
try {
|
|
43
|
+
return await handleHotUpdate(ctx, config);
|
|
51
44
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
catch (err) {
|
|
46
|
+
// Vite swallows errors thrown by handleHotUpdate()
|
|
47
|
+
console.error(err);
|
|
48
|
+
throw err;
|
|
55
49
|
}
|
|
56
|
-
}
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
load: {
|
|
53
|
+
filter: filterRolldown,
|
|
54
|
+
async handler(id, options) {
|
|
55
|
+
assert(filterFunction(id));
|
|
56
|
+
id = removeVirtualFileIdPrefix(id);
|
|
57
|
+
const isDev = config._isDev;
|
|
58
|
+
assert(typeof isDev === 'boolean');
|
|
59
|
+
const idParsed = parseVirtualFileId(id);
|
|
60
|
+
if (idParsed) {
|
|
61
|
+
if (idParsed.type === 'page-entry') {
|
|
62
|
+
const code = await generateVirtualFilePageEntry(id, isDev);
|
|
63
|
+
return code;
|
|
64
|
+
}
|
|
65
|
+
if (idParsed.type === 'global-entry') {
|
|
66
|
+
const code = await generateVirtualFileGlobalEntryWithOldDesign(id, options, config, this.environment, isDev);
|
|
67
|
+
return code;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
57
71
|
},
|
|
58
|
-
configureServer
|
|
59
|
-
|
|
72
|
+
configureServer: {
|
|
73
|
+
handler(server) {
|
|
74
|
+
handleFileAddRemove(server, config);
|
|
75
|
+
},
|
|
60
76
|
},
|
|
61
77
|
};
|
|
62
78
|
}
|
|
@@ -125,7 +141,9 @@ async function handleHotUpdate(ctx, config) {
|
|
|
125
141
|
// Ensure we invalidate `file` *before* server.ssrLoadModule() in updateUserFiles()
|
|
126
142
|
// Vite already invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
127
143
|
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
128
|
-
|
|
144
|
+
if (isRunnable(server)) {
|
|
145
|
+
await updateUserFiles();
|
|
146
|
+
}
|
|
129
147
|
}
|
|
130
148
|
}
|
|
131
149
|
}
|