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
|
@@ -5,6 +5,7 @@ import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
|
5
5
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
6
6
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
7
7
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
8
|
+
import { filterRolldown, filterFunction } from './pluginReplaceConstants.js';
|
|
8
9
|
// TO-DO/eventually:
|
|
9
10
|
// - Make import.meta.env work inside +config.js
|
|
10
11
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -20,66 +21,70 @@ function pluginEnvVars() {
|
|
|
20
21
|
return {
|
|
21
22
|
name: 'vike:pluginEnvVars',
|
|
22
23
|
enforce: 'post',
|
|
23
|
-
configResolved
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
configResolved: {
|
|
25
|
+
handler(config_) {
|
|
26
|
+
config = config_;
|
|
27
|
+
envsAll = loadEnv(config.mode, config.envDir || config.root, '');
|
|
28
|
+
config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
29
|
+
},
|
|
27
30
|
},
|
|
28
|
-
transform
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
31
|
+
transform: {
|
|
32
|
+
filter: filterRolldown,
|
|
33
|
+
handler(code, id, options) {
|
|
34
|
+
id = normalizeId(id);
|
|
35
|
+
assertPosixPath(id);
|
|
36
|
+
assertPosixPath(config.root);
|
|
37
|
+
if (!id.startsWith(config.root))
|
|
38
|
+
return; // skip linked dependencies
|
|
39
|
+
assert(filterFunction(id, code));
|
|
40
|
+
const isBuild = config.command === 'build';
|
|
41
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
42
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
43
|
+
// Find & check
|
|
44
|
+
const replacements = Object.entries(envsAll)
|
|
45
|
+
.filter(([key]) => {
|
|
46
|
+
// Already handled by Vite
|
|
47
|
+
const envPrefix = !config.envPrefix ? [] : isArray(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
48
|
+
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
49
|
+
})
|
|
50
|
+
.map(([envName, envVal]) => {
|
|
51
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
52
|
+
const envStatementRegExpStr = escapeRegex(envStatement) + '\\b';
|
|
53
|
+
// Security check
|
|
54
|
+
{
|
|
55
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
56
|
+
if (isPrivate && isClientSide) {
|
|
57
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
58
|
+
return;
|
|
59
|
+
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
60
|
+
const errMsgAddendum = isBuild
|
|
61
|
+
? ''
|
|
62
|
+
: ' (Vike will prevent your app from building for production)';
|
|
63
|
+
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
64
|
+
const errMsg = `${envStatement} is used in client-side file ${modulePath} which means that the environment variable ${envName} will be included in client-side bundles and, therefore, ${envName} will be publicly exposed which can be a security leak${errMsgAddendum}. Use ${envStatement} only in server-side files, or rename ${envName} to ${keyPublic}, see https://vike.dev/env`;
|
|
65
|
+
if (isBuild) {
|
|
66
|
+
assertUsage(false, errMsg);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
70
|
+
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
71
|
+
assertWarning(false, errMsg, { onlyOnce: true });
|
|
72
|
+
}
|
|
68
73
|
}
|
|
74
|
+
// Double check
|
|
75
|
+
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
return getMagicStringResult();
|
|
77
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
78
|
+
})
|
|
79
|
+
.filter(isNotNullish);
|
|
80
|
+
// Apply
|
|
81
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
82
|
+
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
83
|
+
});
|
|
84
|
+
if (!magicString.hasChanged())
|
|
85
|
+
return null;
|
|
86
|
+
return getMagicStringResult();
|
|
87
|
+
},
|
|
83
88
|
},
|
|
84
89
|
};
|
|
85
90
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// TO-DO/next-major-release: remove
|
|
1
2
|
// Remove this workaround if the other workaround config.build.ssrEmitAssets turns out to be reliable.
|
|
2
3
|
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
3
4
|
// Workaround to make client-side bundles include the CSS imports living in server-side-only code.
|
|
@@ -22,6 +23,12 @@ const rawRE = /(\?|&)raw(?:&|$)/;
|
|
|
22
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
23
24
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
24
25
|
const debug = createDebugger('vike:pluginExtractAssets');
|
|
26
|
+
const filterRolldown = {
|
|
27
|
+
id: {
|
|
28
|
+
include: extractAssetsRE,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const filterFunction = (id) => extractAssetsRE.test(id);
|
|
25
32
|
function pluginExtractAssets() {
|
|
26
33
|
let config;
|
|
27
34
|
let vikeConfig;
|
|
@@ -33,24 +40,25 @@ function pluginExtractAssets() {
|
|
|
33
40
|
// In dev, things just work. (Because Vite's module graph erroneously conflates the Vite server-side importees with the client-side importees.)
|
|
34
41
|
apply: 'build',
|
|
35
42
|
enforce: 'post',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
transform: {
|
|
44
|
+
filter: filterRolldown,
|
|
45
|
+
async handler(src, id, options) {
|
|
46
|
+
id = normalizeId(id);
|
|
47
|
+
assert(filterFunction(id));
|
|
48
|
+
if (isFixEnabled) {
|
|
49
|
+
// I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
50
|
+
assertV1Design(vikeConfig._pageConfigs, true);
|
|
51
|
+
assert(false);
|
|
52
|
+
}
|
|
53
|
+
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
54
|
+
assert(includeAssetsImportedByServer);
|
|
55
|
+
assert(!isViteServerSide_extraSafe(config, this.environment, options));
|
|
56
|
+
const importStatements = await getImportStatements(src);
|
|
57
|
+
const moduleNames = getImportedModules(importStatements);
|
|
58
|
+
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
59
|
+
debugTransformResult(id, code, importStatements);
|
|
60
|
+
return rollupSourceMapRemove(code);
|
|
61
|
+
},
|
|
54
62
|
},
|
|
55
63
|
},
|
|
56
64
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -61,89 +69,97 @@ function pluginExtractAssets() {
|
|
|
61
69
|
// - rollup's `alias` plugin; https://github.com/rollup/plugins/blob/5363f55aa1933b6c650832b08d6a54cb9ea64539/packages/alias/src/index.ts
|
|
62
70
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
63
71
|
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
|
-
|
|
72
|
+
resolveId: {
|
|
73
|
+
async handler(source, importer, options) {
|
|
74
|
+
if (isViteServerSide_extraSafe(config, this.environment, options)) {
|
|
75
|
+
// When building for the server, there should never be a `?extractAssets` query
|
|
76
|
+
assert(!extractAssetsRE.test(source));
|
|
77
|
+
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// If there is no `importer` then `module` is an entry.
|
|
81
|
+
// 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`).
|
|
82
|
+
if (!importer) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// We only append `?extractAssets` if the parent module has `?extractAssets`
|
|
86
|
+
if (!extractAssetsRE.test(importer)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
90
|
+
assert(includeAssetsImportedByServer);
|
|
91
|
+
let resolution = null;
|
|
92
|
+
try {
|
|
93
|
+
resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
|
|
94
|
+
}
|
|
95
|
+
catch { }
|
|
96
|
+
// 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?)
|
|
97
|
+
if (!resolution)
|
|
98
|
+
return emptyModule(source, importer);
|
|
99
|
+
const { id: file, external } = resolution;
|
|
100
|
+
// Nothing is externalized when building for the client-side
|
|
101
|
+
assert(external === false);
|
|
102
|
+
// We include:
|
|
103
|
+
// - CSS(/LESS/SCSS/...) files
|
|
104
|
+
// - Asset files (`.svg`, `.pdf`, ...)
|
|
105
|
+
// - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
|
|
106
|
+
if (styleFileRE.test(file) || isAsset(file) || urlRE.test(file)) {
|
|
107
|
+
debugOperation('INCLUDED', file, importer);
|
|
108
|
+
return resolution;
|
|
109
|
+
}
|
|
110
|
+
// We erase `source` if its file doesn't contain JavaScript
|
|
111
|
+
if (!isScriptFile(file)) {
|
|
112
|
+
return emptyModule(file, importer);
|
|
113
|
+
}
|
|
114
|
+
// If the import path resolves to a file in `node_modules/`, we ignore that file:
|
|
115
|
+
// - 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.)
|
|
116
|
+
// - 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.)
|
|
117
|
+
assertPosixPath(file);
|
|
118
|
+
if (file.includes('/node_modules/')) {
|
|
119
|
+
return emptyModule(file, importer);
|
|
120
|
+
}
|
|
121
|
+
// When a library is symlinked, it lives outside `root`.
|
|
122
|
+
assertPosixPath(config.root);
|
|
123
|
+
if (!file.startsWith(config.root)) {
|
|
124
|
+
return emptyModule(file, importer);
|
|
125
|
+
}
|
|
126
|
+
return appendExtractAssetsQuery(file, importer);
|
|
127
|
+
},
|
|
118
128
|
},
|
|
119
129
|
},
|
|
120
130
|
{
|
|
121
131
|
name: 'vike:pluginExtractAssets-3',
|
|
122
132
|
apply: 'build',
|
|
123
|
-
load
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
load: {
|
|
134
|
+
handler(id) {
|
|
135
|
+
if (!isVirtualFileId(id))
|
|
136
|
+
return undefined;
|
|
137
|
+
id = removeVirtualFileIdPrefix(id);
|
|
138
|
+
if (id === EMPTY_MODULE_ID) {
|
|
139
|
+
return '// Erased by vike:pluginExtractAssets';
|
|
140
|
+
}
|
|
141
|
+
},
|
|
130
142
|
},
|
|
131
|
-
config
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
config: {
|
|
144
|
+
handler() {
|
|
145
|
+
if (debug.isActivated) {
|
|
146
|
+
return { logLevel: 'silent' };
|
|
147
|
+
}
|
|
148
|
+
},
|
|
135
149
|
},
|
|
136
150
|
},
|
|
137
151
|
{
|
|
138
152
|
name: 'vike:pluginExtractAssets-4',
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
configResolved: {
|
|
154
|
+
async handler(config_) {
|
|
155
|
+
config = config_;
|
|
156
|
+
vikeConfig = await getVikeConfigInternal();
|
|
157
|
+
isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
158
|
+
if (!isFixEnabled) {
|
|
159
|
+
// https://github.com/vikejs/vike/issues/1060
|
|
160
|
+
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');
|
|
161
|
+
}
|
|
162
|
+
},
|
|
147
163
|
},
|
|
148
164
|
},
|
|
149
165
|
];
|
|
@@ -8,31 +8,45 @@ import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
|
8
8
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
9
9
|
const debug = createDebugger('vike:pluginExtractExportNames');
|
|
10
10
|
const globalObject = getGlobalObject('plugins/pluginExtractExportNames.ts', {});
|
|
11
|
+
const filterRolldown = {
|
|
12
|
+
id: {
|
|
13
|
+
include: extractExportNamesRE,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const filterFunction = (id) => extractExportNamesRE.test(id);
|
|
11
17
|
function pluginExtractExportNames() {
|
|
12
18
|
let isDev = false;
|
|
13
19
|
let config;
|
|
14
20
|
return {
|
|
15
21
|
name: 'vike:pluginExtractExportNames',
|
|
16
22
|
enforce: 'post',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
transform: {
|
|
24
|
+
filter: filterRolldown,
|
|
25
|
+
async handler(src, id, options) {
|
|
26
|
+
id = normalizeId(id);
|
|
27
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
28
|
+
assert(filterFunction(id));
|
|
21
29
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
22
30
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
23
31
|
return code;
|
|
24
|
-
}
|
|
32
|
+
},
|
|
25
33
|
},
|
|
26
|
-
configureServer
|
|
27
|
-
|
|
34
|
+
configureServer: {
|
|
35
|
+
handler() {
|
|
36
|
+
isDev = true;
|
|
37
|
+
},
|
|
28
38
|
},
|
|
29
|
-
configResolved
|
|
30
|
-
|
|
39
|
+
configResolved: {
|
|
40
|
+
handler(config_) {
|
|
41
|
+
config = config_;
|
|
42
|
+
},
|
|
31
43
|
},
|
|
32
|
-
config
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
config: {
|
|
45
|
+
handler() {
|
|
46
|
+
if (debug.isActivated) {
|
|
47
|
+
return { logLevel: 'silent' };
|
|
48
|
+
}
|
|
49
|
+
},
|
|
36
50
|
},
|
|
37
51
|
};
|
|
38
52
|
}
|