vike 0.4.238 → 0.4.239-commit-050a4a3
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/runtime/globalContext.js +1 -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 +4 -2
- 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 +63 -57
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +101 -91
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +24 -16
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +67 -57
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +26 -19
- package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +41 -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 +50 -37
- 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/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +39 -16
- 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 +97 -83
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +38 -10
- 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 +43 -28
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +39 -16
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +38 -10
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +38 -10
- 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 +57 -14
- package/dist/esm/node/runtime/globalContext.d.ts +154 -40
- package/dist/esm/node/runtime/globalContext.js +1 -0
- 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 +52 -10
- 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 +62 -15
- 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 +114 -28
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
- package/dist/esm/node/runtime/renderPage.d.ts +52 -10
- 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 +4 -2
- 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 +63 -57
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +101 -91
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +24 -16
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +67 -57
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +26 -19
- package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +41 -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 +51 -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 +73 -17
- 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/package.json +2 -2
- 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
|
@@ -33,24 +33,26 @@ function pluginExtractAssets() {
|
|
|
33
33
|
// In dev, things just work. (Because Vite's module graph erroneously conflates the Vite server-side importees with the client-side importees.)
|
|
34
34
|
apply: 'build',
|
|
35
35
|
enforce: 'post',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
transform: {
|
|
37
|
+
async handler(src, id, options) {
|
|
38
|
+
id = normalizeId(id);
|
|
39
|
+
if (!extractAssetsRE.test(id)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (isFixEnabled) {
|
|
43
|
+
// I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
44
|
+
assertV1Design(vikeConfig._pageConfigs, true);
|
|
45
|
+
assert(false);
|
|
46
|
+
}
|
|
47
|
+
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
48
|
+
assert(includeAssetsImportedByServer);
|
|
49
|
+
assert(!isViteServerSide_extraSafe(config, this.environment, options));
|
|
50
|
+
const importStatements = await getImportStatements(src);
|
|
51
|
+
const moduleNames = getImportedModules(importStatements);
|
|
52
|
+
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
53
|
+
debugTransformResult(id, code, importStatements);
|
|
54
|
+
return rollupSourceMapRemove(code);
|
|
55
|
+
},
|
|
54
56
|
},
|
|
55
57
|
},
|
|
56
58
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -61,89 +63,97 @@ function pluginExtractAssets() {
|
|
|
61
63
|
// - rollup's `alias` plugin; https://github.com/rollup/plugins/blob/5363f55aa1933b6c650832b08d6a54cb9ea64539/packages/alias/src/index.ts
|
|
62
64
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
63
65
|
enforce: 'pre',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
66
|
+
resolveId: {
|
|
67
|
+
async handler(source, importer, options) {
|
|
68
|
+
if (isViteServerSide_extraSafe(config, this.environment, options)) {
|
|
69
|
+
// When building for the server, there should never be a `?extractAssets` query
|
|
70
|
+
assert(!extractAssetsRE.test(source));
|
|
71
|
+
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
// If there is no `importer` then `module` is an entry.
|
|
75
|
+
// We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
|
|
76
|
+
if (!importer) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// We only append `?extractAssets` if the parent module has `?extractAssets`
|
|
80
|
+
if (!extractAssetsRE.test(importer)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
84
|
+
assert(includeAssetsImportedByServer);
|
|
85
|
+
let resolution = null;
|
|
86
|
+
try {
|
|
87
|
+
resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
// Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
|
|
91
|
+
if (!resolution)
|
|
92
|
+
return emptyModule(source, importer);
|
|
93
|
+
const { id: file, external } = resolution;
|
|
94
|
+
// Nothing is externalized when building for the client-side
|
|
95
|
+
assert(external === false);
|
|
96
|
+
// We include:
|
|
97
|
+
// - CSS(/LESS/SCSS/...) files
|
|
98
|
+
// - Asset files (`.svg`, `.pdf`, ...)
|
|
99
|
+
// - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
|
|
100
|
+
if (styleFileRE.test(file) || isAsset(file) || urlRE.test(file)) {
|
|
101
|
+
debugOperation('INCLUDED', file, importer);
|
|
102
|
+
return resolution;
|
|
103
|
+
}
|
|
104
|
+
// We erase `source` if its file doesn't contain JavaScript
|
|
105
|
+
if (!isScriptFile(file)) {
|
|
106
|
+
return emptyModule(file, importer);
|
|
107
|
+
}
|
|
108
|
+
// If the import path resolves to a file in `node_modules/`, we ignore that file:
|
|
109
|
+
// - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
|
|
110
|
+
// - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
|
|
111
|
+
assertPosixPath(file);
|
|
112
|
+
if (file.includes('/node_modules/')) {
|
|
113
|
+
return emptyModule(file, importer);
|
|
114
|
+
}
|
|
115
|
+
// When a library is symlinked, it lives outside `root`.
|
|
116
|
+
assertPosixPath(config.root);
|
|
117
|
+
if (!file.startsWith(config.root)) {
|
|
118
|
+
return emptyModule(file, importer);
|
|
119
|
+
}
|
|
120
|
+
return appendExtractAssetsQuery(file, importer);
|
|
121
|
+
},
|
|
118
122
|
},
|
|
119
123
|
},
|
|
120
124
|
{
|
|
121
125
|
name: 'vike:pluginExtractAssets-3',
|
|
122
126
|
apply: 'build',
|
|
123
|
-
load
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
load: {
|
|
128
|
+
handler(id) {
|
|
129
|
+
if (!isVirtualFileId(id))
|
|
130
|
+
return undefined;
|
|
131
|
+
id = removeVirtualFileIdPrefix(id);
|
|
132
|
+
if (id === EMPTY_MODULE_ID) {
|
|
133
|
+
return '// Erased by vike:pluginExtractAssets';
|
|
134
|
+
}
|
|
135
|
+
},
|
|
130
136
|
},
|
|
131
|
-
config
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
config: {
|
|
138
|
+
handler() {
|
|
139
|
+
if (debug.isActivated) {
|
|
140
|
+
return { logLevel: 'silent' };
|
|
141
|
+
}
|
|
142
|
+
},
|
|
135
143
|
},
|
|
136
144
|
},
|
|
137
145
|
{
|
|
138
146
|
name: 'vike:pluginExtractAssets-4',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
configResolved: {
|
|
148
|
+
async handler(config_) {
|
|
149
|
+
config = config_;
|
|
150
|
+
vikeConfig = await getVikeConfigInternal();
|
|
151
|
+
isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
152
|
+
if (!isFixEnabled) {
|
|
153
|
+
// https://github.com/vikejs/vike/issues/1060
|
|
154
|
+
assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
|
|
155
|
+
}
|
|
156
|
+
},
|
|
147
157
|
},
|
|
148
158
|
},
|
|
149
159
|
];
|
|
@@ -14,25 +14,33 @@ function pluginExtractExportNames() {
|
|
|
14
14
|
return {
|
|
15
15
|
name: 'vike:pluginExtractExportNames',
|
|
16
16
|
enforce: 'post',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
transform: {
|
|
18
|
+
async handler(src, id, options) {
|
|
19
|
+
id = normalizeId(id);
|
|
20
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
21
|
+
if (extractExportNamesRE.test(id)) {
|
|
22
|
+
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
23
|
+
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
24
|
+
return code;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
|
-
configureServer
|
|
27
|
-
|
|
28
|
+
configureServer: {
|
|
29
|
+
handler() {
|
|
30
|
+
isDev = true;
|
|
31
|
+
},
|
|
28
32
|
},
|
|
29
|
-
configResolved
|
|
30
|
-
|
|
33
|
+
configResolved: {
|
|
34
|
+
handler(config_) {
|
|
35
|
+
config = config_;
|
|
36
|
+
},
|
|
31
37
|
},
|
|
32
|
-
config
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
config: {
|
|
39
|
+
handler() {
|
|
40
|
+
if (debug.isActivated) {
|
|
41
|
+
return { logLevel: 'silent' };
|
|
42
|
+
}
|
|
43
|
+
},
|
|
36
44
|
},
|
|
37
45
|
};
|
|
38
46
|
}
|
|
@@ -13,68 +13,78 @@ function pluginFileEnv() {
|
|
|
13
13
|
let viteDevServer;
|
|
14
14
|
return {
|
|
15
15
|
name: 'vike:pluginFileEnv',
|
|
16
|
-
load
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
load: {
|
|
17
|
+
handler(id, options) {
|
|
18
|
+
// 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.
|
|
19
|
+
if (!viteDevServer)
|
|
20
|
+
return;
|
|
21
|
+
if (!isV1Design())
|
|
22
|
+
return;
|
|
23
|
+
if (skip(id))
|
|
24
|
+
return;
|
|
25
|
+
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
26
|
+
if (id.endsWith('?direct'))
|
|
27
|
+
id = id.slice(0, -1 * '?direct'.length);
|
|
28
|
+
const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
|
|
29
|
+
assert(moduleInfo);
|
|
30
|
+
const importers = Array.from(moduleInfo.importers)
|
|
31
|
+
.map((m) => m.id)
|
|
32
|
+
.filter((id) => id !== null);
|
|
33
|
+
assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
|
|
34
|
+
// 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).
|
|
35
|
+
true);
|
|
36
|
+
},
|
|
35
37
|
},
|
|
36
38
|
// 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
|
-
if (skip(id))
|
|
43
|
-
return;
|
|
44
|
-
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
45
|
-
if (!isWrongEnv(id, isServerSide))
|
|
46
|
-
return;
|
|
47
|
-
const { importers } = this.getModuleInfo(id);
|
|
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
|
-
*/
|
|
39
|
+
transform: {
|
|
40
|
+
async handler(code, id, options) {
|
|
41
|
+
id = normalizeId(id);
|
|
42
|
+
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
43
|
+
if (viteDevServer)
|
|
68
44
|
return;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
45
|
+
if (skip(id))
|
|
46
|
+
return;
|
|
47
|
+
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
48
|
+
if (!isWrongEnv(id, isServerSide))
|
|
49
|
+
return;
|
|
50
|
+
const { importers } = this.getModuleInfo(id);
|
|
51
|
+
// Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
|
|
52
|
+
const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
|
|
53
|
+
// We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
|
|
54
|
+
const { exportNames } = await getExportNames(code);
|
|
55
|
+
return rollupSourceMapRemove([
|
|
56
|
+
`throw new Error(${JSON.stringify(errMsg)});`,
|
|
57
|
+
...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
|
|
58
|
+
].join('\n'));
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
generateBundle: {
|
|
62
|
+
handler() {
|
|
63
|
+
Array.from(this.getModuleIds())
|
|
64
|
+
.filter((id) => !skip(id))
|
|
65
|
+
.forEach((moduleId) => {
|
|
66
|
+
const mod = this.getModuleInfo(moduleId);
|
|
67
|
+
const { importers } = mod;
|
|
68
|
+
if (importers.length === 0) {
|
|
69
|
+
// Dynamic imports can only be verified at runtime
|
|
70
|
+
/* This assertion can fail: https://github.com/vikejs/vike/issues/2227
|
|
71
|
+
assert(dynamicImporters.length > 0)
|
|
72
|
+
*/
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
assertFileEnv(moduleId, isViteServerSide(config, this.environment), importers, false);
|
|
76
|
+
});
|
|
77
|
+
},
|
|
72
78
|
},
|
|
73
|
-
configResolved
|
|
74
|
-
|
|
79
|
+
configResolved: {
|
|
80
|
+
handler(config_) {
|
|
81
|
+
config = config_;
|
|
82
|
+
},
|
|
75
83
|
},
|
|
76
|
-
configureServer
|
|
77
|
-
|
|
84
|
+
configureServer: {
|
|
85
|
+
handler(viteDevServer_) {
|
|
86
|
+
viteDevServer = viteDevServer_;
|
|
87
|
+
},
|
|
78
88
|
},
|
|
79
89
|
};
|
|
80
90
|
function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
|
|
@@ -23,27 +23,34 @@ function pluginNonRunnableDev() {
|
|
|
23
23
|
let config;
|
|
24
24
|
return {
|
|
25
25
|
name: 'vike:pluginNonRunnableDev',
|
|
26
|
-
configureServer
|
|
27
|
-
|
|
26
|
+
configureServer: {
|
|
27
|
+
handler(viteDevServer) {
|
|
28
|
+
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
29
|
+
},
|
|
28
30
|
},
|
|
29
|
-
configResolved
|
|
30
|
-
|
|
31
|
+
configResolved: {
|
|
32
|
+
handler(config_) {
|
|
33
|
+
config = config_;
|
|
34
|
+
},
|
|
31
35
|
},
|
|
32
|
-
transform
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
magicString
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
transform: {
|
|
37
|
+
handler(code, id) {
|
|
38
|
+
if (!config._isDev)
|
|
39
|
+
return;
|
|
40
|
+
const idWithoutQuery = id.split('?')[0];
|
|
41
|
+
if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
|
|
42
|
+
return;
|
|
43
|
+
if (isRunnableDevEnvironment(this.environment))
|
|
44
|
+
return;
|
|
45
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
46
|
+
if (idWithoutQuery === distFileIsNonRunnableDev) {
|
|
47
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
|
|
48
|
+
}
|
|
49
|
+
if (idWithoutQuery === distFileGlobalContext) {
|
|
50
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
51
|
+
}
|
|
52
|
+
return getMagicStringResult();
|
|
53
|
+
},
|
|
47
54
|
},
|
|
48
55
|
};
|
|
49
56
|
}
|
|
@@ -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) {
|
|
@@ -9,41 +9,49 @@ function pluginReplaceConstants() {
|
|
|
9
9
|
name: 'vike:pluginReplaceConstants',
|
|
10
10
|
enforce: 'post',
|
|
11
11
|
apply: 'build',
|
|
12
|
-
configResolved
|
|
13
|
-
|
|
12
|
+
configResolved: {
|
|
13
|
+
handler(config_) {
|
|
14
|
+
config = config_;
|
|
15
|
+
},
|
|
14
16
|
},
|
|
15
|
-
transform
|
|
16
|
-
id
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
assertPosixPath(config.root);
|
|
21
|
-
if (!id.startsWith(config.root))
|
|
22
|
-
return;
|
|
23
|
-
if (!code.includes('import.meta.env.'))
|
|
24
|
-
return;
|
|
25
|
-
const isBuild = config.command === 'build';
|
|
26
|
-
assert(isBuild);
|
|
27
|
-
// Used by vike.dev
|
|
28
|
-
// https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
|
|
29
|
-
// @ts-expect-error
|
|
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)))
|
|
17
|
+
transform: {
|
|
18
|
+
handler(code, id, options) {
|
|
19
|
+
id = normalizeId(id);
|
|
20
|
+
assertPosixPath(id);
|
|
21
|
+
if (id.includes('/node_modules/'))
|
|
40
22
|
return;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
assertPosixPath(config.root);
|
|
24
|
+
if (!id.startsWith(config.root))
|
|
25
|
+
return;
|
|
26
|
+
if (!code.includes('import.meta.env.'))
|
|
27
|
+
return;
|
|
28
|
+
const isBuild = config.command === 'build';
|
|
29
|
+
assert(isBuild);
|
|
30
|
+
// Used by vike.dev
|
|
31
|
+
// https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
|
|
32
|
+
// @ts-expect-error
|
|
33
|
+
if (config._skipVikeReplaceConstants?.(id))
|
|
34
|
+
return;
|
|
35
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
36
|
+
const constantsMap = [];
|
|
37
|
+
constantsMap.push({
|
|
38
|
+
constants: [
|
|
39
|
+
'pageContext.isClientSide',
|
|
40
|
+
'globalContext.isClientSide',
|
|
41
|
+
'pageContext.globalContext.isClientSide',
|
|
42
|
+
],
|
|
43
|
+
replacement: !isViteServerSide_extraSafe(config, this.environment, options),
|
|
44
|
+
});
|
|
45
|
+
constantsMap.forEach(({ constants, replacement }) => {
|
|
46
|
+
if (!constants.some((c) => code.includes(c)))
|
|
47
|
+
return;
|
|
48
|
+
const regExp = getConstantRegExp(constants);
|
|
49
|
+
magicString.replaceAll(regExp, JSON.stringify(replacement));
|
|
50
|
+
});
|
|
51
|
+
if (!magicString.hasChanged())
|
|
52
|
+
return null;
|
|
53
|
+
return getMagicStringResult();
|
|
54
|
+
},
|
|
47
55
|
},
|
|
48
56
|
};
|
|
49
57
|
}
|
|
@@ -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',
|