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
|
@@ -12,88 +12,90 @@ function pluginDistFileNames() {
|
|
|
12
12
|
name: 'vike:build:pluginDistFileNames',
|
|
13
13
|
apply: 'build',
|
|
14
14
|
enforce: 'post',
|
|
15
|
-
configResolved
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
else {
|
|
48
|
-
assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
|
|
52
|
-
// TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
|
|
53
|
-
if (id.endsWith('.css')) {
|
|
54
|
-
const userRootDir = config.root;
|
|
55
|
-
if (id.startsWith(userRootDir)) {
|
|
56
|
-
assertPosixPath(id);
|
|
57
|
-
assertModuleId(id);
|
|
58
|
-
let name;
|
|
59
|
-
const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
|
|
60
|
-
if (isNodeModules) {
|
|
61
|
-
name = isNodeModules[1];
|
|
15
|
+
configResolved: {
|
|
16
|
+
handler(config) {
|
|
17
|
+
const rollupOutputs = getRollupOutputs(config);
|
|
18
|
+
// We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
|
|
19
|
+
rollupOutputs.forEach((rollupOutput) => {
|
|
20
|
+
if (!('entryFileNames' in rollupOutput)) {
|
|
21
|
+
rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
|
|
22
|
+
}
|
|
23
|
+
if (!('chunkFileNames' in rollupOutput)) {
|
|
24
|
+
rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
|
|
25
|
+
}
|
|
26
|
+
if (!('assetFileNames' in rollupOutput)) {
|
|
27
|
+
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
|
|
28
|
+
rollupOutput.assetFileNames.isTheOneSetByVike = true;
|
|
29
|
+
assert(rollupOutput.assetFileNames.isTheOneSetByVike);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// If a user needs this:
|
|
33
|
+
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
34
|
+
// - It's needed for getHash() of handleAssetsManifest()
|
|
35
|
+
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
36
|
+
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
37
|
+
assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
|
|
38
|
+
}
|
|
39
|
+
{
|
|
40
|
+
const manualChunksOriginal = rollupOutput.manualChunks;
|
|
41
|
+
rollupOutput.manualChunks = function (id, ...args) {
|
|
42
|
+
if (manualChunksOriginal) {
|
|
43
|
+
if (isCallable(manualChunksOriginal)) {
|
|
44
|
+
const result = manualChunksOriginal.call(this, id, ...args);
|
|
45
|
+
if (result !== undefined)
|
|
46
|
+
return result;
|
|
62
47
|
}
|
|
63
48
|
else {
|
|
64
|
-
|
|
65
|
-
name = filePath;
|
|
66
|
-
name = name.split('.').slice(0, -1).join('.'); // remove file extension
|
|
67
|
-
name = name.split('/').filter(Boolean).join('_');
|
|
49
|
+
assertUsage(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
|
|
68
50
|
}
|
|
69
|
-
// Make fileHash the same between local development and CI
|
|
70
|
-
const idStable = path.posix.relative(userRootDir, id);
|
|
71
|
-
// Don't remove `?` queries because each `id` should belong to a unique bundle.
|
|
72
|
-
const hash = getIdHash(idStable);
|
|
73
|
-
return `${name}-${hash}`;
|
|
74
51
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
52
|
+
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
|
|
53
|
+
// TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
|
|
54
|
+
if (id.endsWith('.css')) {
|
|
55
|
+
const userRootDir = config.root;
|
|
56
|
+
if (id.startsWith(userRootDir)) {
|
|
57
|
+
assertPosixPath(id);
|
|
58
|
+
assertModuleId(id);
|
|
59
|
+
let name;
|
|
60
|
+
const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
|
|
61
|
+
if (isNodeModules) {
|
|
62
|
+
name = isNodeModules[1];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const filePath = getModuleFilePathAbsolute(id, config);
|
|
66
|
+
name = filePath;
|
|
67
|
+
name = name.split('.').slice(0, -1).join('.'); // remove file extension
|
|
68
|
+
name = name.split('/').filter(Boolean).join('_');
|
|
69
|
+
}
|
|
70
|
+
// Make fileHash the same between local development and CI
|
|
71
|
+
const idStable = path.posix.relative(userRootDir, id);
|
|
72
|
+
// Don't remove `?` queries because each `id` should belong to a unique bundle.
|
|
73
|
+
const hash = getIdHash(idStable);
|
|
74
|
+
return `${name}-${hash}`;
|
|
86
75
|
}
|
|
87
76
|
else {
|
|
88
|
-
name
|
|
77
|
+
let name;
|
|
78
|
+
const isVirtualModule = id.match(/virtual:([^:]+):/);
|
|
79
|
+
if (isVirtualModule) {
|
|
80
|
+
name = isVirtualModule[1];
|
|
81
|
+
assert(name);
|
|
82
|
+
}
|
|
83
|
+
else if (
|
|
84
|
+
// https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
|
|
85
|
+
id.startsWith('/__uno')) {
|
|
86
|
+
name = 'uno';
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
name = 'style';
|
|
90
|
+
}
|
|
91
|
+
const hash = getIdHash(id);
|
|
92
|
+
return `${name}-${hash}`;
|
|
89
93
|
}
|
|
90
|
-
const hash = getIdHash(id);
|
|
91
|
-
return `${name}-${hash}`;
|
|
92
94
|
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
},
|
|
97
99
|
},
|
|
98
100
|
};
|
|
99
101
|
}
|
|
@@ -6,21 +6,25 @@ function pluginDistPackageJsonFile() {
|
|
|
6
6
|
return {
|
|
7
7
|
name: 'vike:build:pluginDistPackageJsonFile',
|
|
8
8
|
apply: 'build',
|
|
9
|
-
configResolved
|
|
10
|
-
|
|
9
|
+
configResolved: {
|
|
10
|
+
handler(config_) {
|
|
11
|
+
config = config_;
|
|
12
|
+
},
|
|
11
13
|
},
|
|
12
|
-
generateBundle
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
generateBundle: {
|
|
15
|
+
handler(options, bundle) {
|
|
16
|
+
if (!isViteServerSide(config, this.environment))
|
|
17
|
+
return;
|
|
18
|
+
const isEsm = rollupIsEsm(options);
|
|
19
|
+
const fileName = 'package.json';
|
|
20
|
+
if (bundle[fileName])
|
|
21
|
+
return; // E.g. already generated by Telefunc / vike
|
|
22
|
+
this.emitFile({
|
|
23
|
+
fileName,
|
|
24
|
+
type: 'asset',
|
|
25
|
+
source: getPackageJsonContent(isEsm),
|
|
26
|
+
});
|
|
27
|
+
},
|
|
24
28
|
},
|
|
25
29
|
};
|
|
26
30
|
}
|
|
@@ -10,8 +10,10 @@ function pluginModuleBanner() {
|
|
|
10
10
|
name: 'vike:build:pluginModuleBanner',
|
|
11
11
|
enforce: 'post',
|
|
12
12
|
apply: 'build',
|
|
13
|
-
configResolved
|
|
14
|
-
|
|
13
|
+
configResolved: {
|
|
14
|
+
handler(config_) {
|
|
15
|
+
config = config_;
|
|
16
|
+
},
|
|
15
17
|
},
|
|
16
18
|
transform: {
|
|
17
19
|
order: 'post',
|
|
@@ -17,8 +17,10 @@ function pluginProdBuildEntry() {
|
|
|
17
17
|
name: 'vike:build:pluginProdBuildEntry',
|
|
18
18
|
apply: 'build',
|
|
19
19
|
enforce: 'post',
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
configResolved: {
|
|
21
|
+
async handler(config_) {
|
|
22
|
+
config = config_;
|
|
23
|
+
},
|
|
22
24
|
},
|
|
23
25
|
},
|
|
24
26
|
...serverProductionEntryPlugin({
|
|
@@ -5,24 +5,26 @@ function pluginSuppressRollupWarning() {
|
|
|
5
5
|
name: 'vike:build:pluginSuppressRollupWarning',
|
|
6
6
|
apply: 'build',
|
|
7
7
|
enforce: 'post',
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
onWarnOriginal
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
configResolved: {
|
|
9
|
+
async handler(config) {
|
|
10
|
+
const onWarnOriginal = config.build.rollupOptions.onwarn;
|
|
11
|
+
config.build.rollupOptions.onwarn = function (warning, warn) {
|
|
12
|
+
// Suppress
|
|
13
|
+
if (suppressUnusedImport(warning))
|
|
14
|
+
return;
|
|
15
|
+
if (suppressEmptyBundle(warning))
|
|
16
|
+
return;
|
|
17
|
+
if (suppressUseClientDirective(warning))
|
|
18
|
+
return;
|
|
19
|
+
// Pass through
|
|
20
|
+
if (onWarnOriginal) {
|
|
21
|
+
onWarnOriginal.apply(this, arguments);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
warn(warning);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
},
|
|
26
28
|
},
|
|
27
29
|
};
|
|
28
30
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { pluginCommon };
|
|
2
|
-
import { assert, assertUsage, assertWarning,
|
|
2
|
+
import { assert, assertUsage, assertWarning, hasProp, isDevCheck, isDocker, isObject, isVitest, } from '../utils.js';
|
|
3
3
|
import { assertRollupInput } from './pluginBuild/pluginBuildConfig.js';
|
|
4
4
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
|
-
import path from 'node:path';
|
|
7
6
|
import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
|
|
8
7
|
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
9
8
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
@@ -42,10 +41,12 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
42
41
|
},
|
|
43
42
|
{
|
|
44
43
|
name: pluginName,
|
|
45
|
-
configResolved
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
configResolved: {
|
|
45
|
+
handler(config) {
|
|
46
|
+
assertViteRoot(config._rootResolvedEarly, config);
|
|
47
|
+
assertSingleInstance(config);
|
|
48
|
+
installRequireShim_setUserRootDir(config.root);
|
|
49
|
+
},
|
|
49
50
|
},
|
|
50
51
|
},
|
|
51
52
|
{
|
|
@@ -64,7 +65,6 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
64
65
|
workaroundCI(config);
|
|
65
66
|
assertRollupInput(config);
|
|
66
67
|
assertResolveAlias(config);
|
|
67
|
-
assertEsm(config.root);
|
|
68
68
|
assertVikeCliOrApi(config);
|
|
69
69
|
temp_supportOldInterface(config);
|
|
70
70
|
await emitServerEntryOnlyIfNeeded(config);
|
|
@@ -107,7 +107,7 @@ function setDefault(setting, value, configFromUser, configFromVike) {
|
|
|
107
107
|
/*
|
|
108
108
|
import { version } from 'vite'
|
|
109
109
|
function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
|
|
110
|
-
if (!
|
|
110
|
+
if (!isVersionMatch(version, ['5.0.12'])) return
|
|
111
111
|
// @ts-ignore Not released yet: https://github.com/vitejs/vite/pull/10939/files#diff-5a3d42620df2c6b17e25f440ffdb67683dee7ef57317674d19f41d5f30502310L5
|
|
112
112
|
config.ssr.external ??= true
|
|
113
113
|
}
|
|
@@ -120,20 +120,6 @@ function workaroundCI(config) {
|
|
|
120
120
|
(_b = config.preview).host ?? (_b.host = true);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function assertEsm(userViteRoot) {
|
|
124
|
-
const found = findPackageJson(userViteRoot);
|
|
125
|
-
if (!found)
|
|
126
|
-
return;
|
|
127
|
-
const { packageJson, packageJsonPath } = found;
|
|
128
|
-
let dir = path.posix.dirname(packageJsonPath);
|
|
129
|
-
if (dir !== '/') {
|
|
130
|
-
assert(!dir.endsWith('/'));
|
|
131
|
-
dir = dir + '/';
|
|
132
|
-
}
|
|
133
|
-
assert(dir.endsWith('/'));
|
|
134
|
-
dir = pc.dim(dir);
|
|
135
|
-
assertWarning(packageJson.type === 'module', `We recommend setting ${dir}package.json#type to "module", see https://vike.dev/CJS`, { onlyOnce: true });
|
|
136
|
-
}
|
|
137
123
|
function assertSingleInstance(config) {
|
|
138
124
|
const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
|
|
139
125
|
assertUsage(numberOfInstances === 1, `Vike's Vite plugin (${pc.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);
|
|
@@ -17,54 +17,58 @@ function pluginDev() {
|
|
|
17
17
|
{
|
|
18
18
|
name: 'vike:pluginDev',
|
|
19
19
|
apply: applyDev,
|
|
20
|
-
config
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
20
|
+
config: {
|
|
21
|
+
handler() {
|
|
22
|
+
return {
|
|
23
|
+
appType: 'custom',
|
|
24
|
+
// TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
|
|
25
|
+
optimizeDeps: {
|
|
26
|
+
exclude: [
|
|
27
|
+
// We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
|
|
28
|
+
'vike/client',
|
|
29
|
+
'vike/client/router',
|
|
30
|
+
// It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
|
|
31
|
+
// ```
|
|
32
|
+
// Client runtime loaded twice https://vike.dev/client-runtime-duplicated
|
|
33
|
+
// ```
|
|
34
|
+
'vike/routing',
|
|
35
|
+
'vike/getPageContext',
|
|
36
|
+
// We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
|
|
37
|
+
// ```
|
|
38
|
+
// 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
|
|
39
|
+
// 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
|
|
40
|
+
// ```
|
|
41
|
+
'@brillout/json-serializer/parse',
|
|
42
|
+
'@brillout/json-serializer/stringify',
|
|
43
|
+
'@brillout/picocolors',
|
|
44
|
+
// We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
|
|
45
|
+
// ```
|
|
46
|
+
// Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
|
|
47
|
+
// 343| // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
|
|
48
|
+
// 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
|
|
49
|
+
// ```
|
|
50
|
+
// The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
|
|
51
|
+
// ```js
|
|
52
|
+
// // ../../node_modules/.pnpm/react-streaming@0.3.16_react-dom@18.2.0_react@18.2.0/node_modules/react-streaming/dist/esm/client/useAsync.js
|
|
53
|
+
// import { parse as parse2 } from "@brillout/json-serializer/parse";
|
|
54
|
+
// ```
|
|
55
|
+
'react-streaming',
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
58
60
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
configResolved: {
|
|
62
|
+
async handler(config_) {
|
|
63
|
+
config = config_;
|
|
64
|
+
await determineOptimizeDeps(config);
|
|
65
|
+
await determineFsAllowList(config);
|
|
66
|
+
if (!isErrorDebug()) {
|
|
67
|
+
await installHttpRequestAsyncStore();
|
|
68
|
+
improveViteLogs(config);
|
|
69
|
+
}
|
|
70
|
+
logDockerHint(config.server.host);
|
|
71
|
+
},
|
|
68
72
|
},
|
|
69
73
|
},
|
|
70
74
|
{
|
|
@@ -20,66 +20,72 @@ function pluginEnvVars() {
|
|
|
20
20
|
return {
|
|
21
21
|
name: 'vike:pluginEnvVars',
|
|
22
22
|
enforce: 'post',
|
|
23
|
-
configResolved
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
configResolved: {
|
|
24
|
+
handler(config_) {
|
|
25
|
+
config = config_;
|
|
26
|
+
envsAll = loadEnv(config.mode, config.envDir || config.root, '');
|
|
27
|
+
config.plugins.sort(lowerFirst((plugin) => (plugin.name === 'vite:define' ? 1 : 0)));
|
|
28
|
+
},
|
|
27
29
|
},
|
|
28
|
-
transform
|
|
29
|
-
id
|
|
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
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
transform: {
|
|
31
|
+
handler(code, id, options) {
|
|
32
|
+
id = normalizeId(id);
|
|
33
|
+
assertPosixPath(id);
|
|
34
|
+
if (id.includes('/node_modules/'))
|
|
35
|
+
return;
|
|
36
|
+
assertPosixPath(config.root);
|
|
37
|
+
if (!id.startsWith(config.root))
|
|
38
|
+
return;
|
|
39
|
+
if (!code.includes('import.meta.env.'))
|
|
40
|
+
return;
|
|
41
|
+
const isBuild = config.command === 'build';
|
|
42
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
43
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
44
|
+
// Find & check
|
|
45
|
+
const replacements = Object.entries(envsAll)
|
|
46
|
+
.filter(([key]) => {
|
|
47
|
+
// Already handled by Vite
|
|
48
|
+
const envPrefix = !config.envPrefix ? [] : isArray(config.envPrefix) ? config.envPrefix : [config.envPrefix];
|
|
49
|
+
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
50
|
+
})
|
|
51
|
+
.map(([envName, envVal]) => {
|
|
52
|
+
const envStatement = `import.meta.env.${envName}`;
|
|
53
|
+
const envStatementRegExpStr = escapeRegex(envStatement) + '\\b';
|
|
54
|
+
// Security check
|
|
55
|
+
{
|
|
56
|
+
const isPrivate = !envName.startsWith(PUBLIC_ENV_PREFIX) && !PUBLIC_ENV_ALLOWLIST.includes(envName);
|
|
57
|
+
if (isPrivate && isClientSide) {
|
|
58
|
+
if (!new RegExp(envStatementRegExpStr).test(code))
|
|
59
|
+
return;
|
|
60
|
+
const modulePath = getModuleFilePathAbsolute(id, config);
|
|
61
|
+
const errMsgAddendum = isBuild
|
|
62
|
+
? ''
|
|
63
|
+
: ' (Vike will prevent your app from building for production)';
|
|
64
|
+
const keyPublic = `${PUBLIC_ENV_PREFIX}${envName}`;
|
|
65
|
+
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`;
|
|
66
|
+
if (isBuild) {
|
|
67
|
+
assertUsage(false, errMsg);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// - Only a warning for faster development DX (e.g. when user toggles `ssr: boolean` or `onBeforeRenderIsomorph: boolean`).
|
|
71
|
+
// - But only showing a warning can be confusing: https://github.com/vikejs/vike/issues/1641
|
|
72
|
+
assertWarning(false, errMsg, { onlyOnce: true });
|
|
73
|
+
}
|
|
68
74
|
}
|
|
75
|
+
// Double check
|
|
76
|
+
assert(!(isPrivate && isClientSide) || !isBuild);
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
return getMagicStringResult();
|
|
78
|
+
return { regExpStr: envStatementRegExpStr, replacement: envVal };
|
|
79
|
+
})
|
|
80
|
+
.filter(isNotNullish);
|
|
81
|
+
// Apply
|
|
82
|
+
replacements.forEach(({ regExpStr, replacement }) => {
|
|
83
|
+
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
84
|
+
});
|
|
85
|
+
if (!magicString.hasChanged())
|
|
86
|
+
return null;
|
|
87
|
+
return getMagicStringResult();
|
|
88
|
+
},
|
|
83
89
|
},
|
|
84
90
|
};
|
|
85
91
|
}
|