vike 0.4.266 → 0.4.267-commit-7884d91

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.
Files changed (159) hide show
  1. package/dist/client/runtime-client-routing/createPageContextClient.d.ts +4 -0
  2. package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +4 -0
  3. package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +22 -2
  4. package/dist/client/runtime-client-routing/getPageContextFromHooks.js +4 -5
  5. package/dist/client/runtime-client-routing/history.d.ts +19 -19
  6. package/dist/client/runtime-client-routing/history.js +89 -83
  7. package/dist/client/runtime-client-routing/renderPageClient.d.ts +472 -9
  8. package/dist/client/runtime-client-routing/renderPageClient.js +12 -11
  9. package/dist/client/runtime-client-routing/setScrollPosition.js +6 -5
  10. package/dist/client/runtime-client-routing/streamedValues.d.ts +5 -0
  11. package/dist/client/runtime-client-routing/streamedValues.js +23 -0
  12. package/dist/client/runtime-server-routing/createPageContextClient.d.ts +4 -0
  13. package/dist/client/runtime-server-routing/entry.js +1 -1
  14. package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +4 -0
  15. package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +4 -0
  16. package/dist/client/shared/getJsonSerializedInHtml.d.ts +2 -2
  17. package/dist/client/shared/getJsonSerializedInHtml.js +9 -6
  18. package/dist/client/shared/streamedValues/asyncIterable.d.ts +4 -0
  19. package/dist/client/shared/streamedValues/asyncIterable.js +26 -0
  20. package/dist/client/shared/streamedValues/lines.d.ts +11 -0
  21. package/dist/client/shared/streamedValues/lines.js +19 -0
  22. package/dist/client/shared/streamedValues/promise.d.ts +4 -0
  23. package/dist/client/shared/streamedValues/promise.js +19 -0
  24. package/dist/client/shared/streamedValues/readableStream.d.ts +4 -0
  25. package/dist/client/shared/streamedValues/readableStream.js +44 -0
  26. package/dist/client/shared/streamedValues/registry.d.ts +21 -0
  27. package/dist/client/shared/streamedValues/registry.js +40 -0
  28. package/dist/client/shared/streamedValues.d.ts +7 -0
  29. package/dist/client/shared/streamedValues.js +82 -0
  30. package/dist/node/api/resolveViteConfigUser.js +2 -2
  31. package/dist/node/prerender/runPrerender.d.ts +12 -4
  32. package/dist/node/prerender/runPrerender.js +71 -15
  33. package/dist/node/vite/assertEnvVite.js +2 -2
  34. package/dist/node/vite/index.js +2 -0
  35. package/dist/node/vite/plugins/build/handleAssetsManifest.js +8 -3
  36. package/dist/node/vite/plugins/build/pluginBuildApp.js +25 -26
  37. package/dist/node/vite/plugins/build/pluginBuildConfig.d.ts +2 -2
  38. package/dist/node/vite/plugins/build/pluginBuildConfig.js +24 -16
  39. package/dist/node/vite/plugins/build/pluginDistFileNames.js +70 -50
  40. package/dist/node/vite/plugins/build/pluginEnvironmentEntries.d.ts +6 -0
  41. package/dist/node/vite/plugins/build/pluginEnvironmentEntries.js +71 -0
  42. package/dist/node/vite/plugins/build/pluginSuppressRollupWarning.js +19 -17
  43. package/dist/node/vite/plugins/pluginCommon.js +9 -6
  44. package/dist/node/vite/plugins/pluginDev/logSkillHint.js +6 -4
  45. package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +1 -1
  46. package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +6 -4
  47. package/dist/node/vite/plugins/pluginUniversalDeploy.js +3 -2
  48. package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -1
  49. package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +29 -12
  50. package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -2
  51. package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +7 -7
  52. package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +7 -5
  53. package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +4 -10
  54. package/dist/node/vite/plugins/pluginVirtualFiles.js +20 -0
  55. package/dist/node/vite/shared/addSsrMiddleware.js +13 -1
  56. package/dist/node/vite/shared/getAssetsDir.d.ts +3 -2
  57. package/dist/node/vite/shared/getAssetsDir.js +3 -3
  58. package/dist/node/vite/shared/isViteCli.d.ts +3 -3
  59. package/dist/node/vite/shared/isViteCli.js +80 -84
  60. package/dist/node/vite/shared/isViteServerSide.js +2 -7
  61. package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFiles.d.ts +2 -2
  62. package/dist/node/vite/shared/resolveVikeConfigInternal/getPlusFiles.js +3 -3
  63. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.d.ts +4 -4
  64. package/dist/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.js +9 -9
  65. package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.d.ts +1 -1
  66. package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +12 -6
  67. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +3 -1
  68. package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +18 -46
  69. package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.d.ts +3 -3
  70. package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +333 -212
  71. package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -1
  72. package/dist/node/vite/shared/resolveVikeConfigInternal.js +97 -26
  73. package/dist/server/runtime/globalContext.d.ts +20 -0
  74. package/dist/server/runtime/renderPageServer/analyzePage.js +3 -3
  75. package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +20 -7
  76. package/dist/server/runtime/renderPageServer/createHttpResponse.js +34 -15
  77. package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +4 -0
  78. package/dist/server/runtime/renderPageServer/csp.d.ts +2 -1
  79. package/dist/server/runtime/renderPageServer/csp.js +2 -1
  80. package/dist/server/runtime/renderPageServer/execHookOnError.js +1 -1
  81. package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.d.ts +9 -0
  82. package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.js +17 -5
  83. package/dist/server/runtime/renderPageServer/getHttpResponseBody.d.ts +2 -2
  84. package/dist/server/runtime/renderPageServer/getHttpResponseBody.js +17 -2
  85. package/dist/server/runtime/renderPageServer/getPageContextJson.d.ts +8 -0
  86. package/dist/server/runtime/renderPageServer/getPageContextJson.js +47 -0
  87. package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.d.ts +2 -0
  88. package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.js +1 -1
  89. package/dist/server/runtime/renderPageServer/headersResponse.d.ts +11 -2
  90. package/dist/server/runtime/renderPageServer/headersResponse.js +22 -2
  91. package/dist/server/runtime/renderPageServer/html/injectAssets/getHtmlTags.js +5 -4
  92. package/dist/server/runtime/renderPageServer/html/injectAssets.d.ts +3 -2
  93. package/dist/server/runtime/renderPageServer/html/injectAssets.js +7 -1
  94. package/dist/server/runtime/renderPageServer/html/renderHtml.js +4 -2
  95. package/dist/server/runtime/renderPageServer/html/serializeContext.d.ts +5 -1
  96. package/dist/server/runtime/renderPageServer/html/serializeContext.js +12 -9
  97. package/dist/server/runtime/renderPageServer/html/stream.d.ts +13 -6
  98. package/dist/server/runtime/renderPageServer/html/stream.js +121 -31
  99. package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.d.ts +30 -0
  100. package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.js +92 -0
  101. package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +4 -0
  102. package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.js +5 -1
  103. package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.d.ts +15 -0
  104. package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.js +61 -0
  105. package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +314 -1
  106. package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.js +21 -12
  107. package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.d.ts +4 -0
  108. package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.js +12 -0
  109. package/dist/server/runtime/renderPageServer/streamedValues/lines.d.ts +10 -0
  110. package/dist/server/runtime/renderPageServer/streamedValues/lines.js +49 -0
  111. package/dist/server/runtime/renderPageServer/streamedValues/promise.d.ts +4 -0
  112. package/dist/server/runtime/renderPageServer/streamedValues/promise.js +14 -0
  113. package/dist/server/runtime/renderPageServer/streamedValues/pump.d.ts +10 -0
  114. package/dist/server/runtime/renderPageServer/streamedValues/pump.js +67 -0
  115. package/dist/server/runtime/renderPageServer/streamedValues/readableStream.d.ts +4 -0
  116. package/dist/server/runtime/renderPageServer/streamedValues/readableStream.js +12 -0
  117. package/dist/server/runtime/renderPageServer/streamedValues/registry.d.ts +28 -0
  118. package/dist/server/runtime/renderPageServer/streamedValues/registry.js +33 -0
  119. package/dist/server/runtime/renderPageServer.d.ts +4 -0
  120. package/dist/server/runtime/renderPageServer.js +17 -8
  121. package/dist/shared-server-client/createGlobalContextShared.d.ts +8 -0
  122. package/dist/shared-server-client/createGlobalContextShared.js +2 -1
  123. package/dist/shared-server-client/getPageContextPublicShared.js +0 -2
  124. package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.d.ts +8 -0
  125. package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.js +17 -7
  126. package/dist/shared-server-client/hooks/execHook.d.ts +1 -1
  127. package/dist/shared-server-client/hooks/execHook.js +2 -2
  128. package/dist/shared-server-client/route/abort.d.ts +1 -1
  129. package/dist/shared-server-client/route/abort.js +4 -2
  130. package/dist/shared-server-client/streamedValues.d.ts +22 -0
  131. package/dist/shared-server-client/streamedValues.js +24 -0
  132. package/dist/shared-server-node/vike-environments.d.ts +4 -0
  133. package/dist/shared-server-node/vike-environments.js +10 -0
  134. package/dist/shared-server-node/virtualFileId.d.ts +7 -5
  135. package/dist/shared-server-node/virtualFileId.js +42 -42
  136. package/dist/types/Config.d.ts +9 -1
  137. package/dist/types/PageConfig.d.ts +13 -5
  138. package/dist/types/PageContext.d.ts +18 -1
  139. package/dist/utils/PROJECT_VERSION.d.ts +1 -1
  140. package/dist/utils/PROJECT_VERSION.js +1 -1
  141. package/dist/utils/assertNodeVersion.d.ts +2 -0
  142. package/dist/utils/assertNodeVersion.js +4 -1
  143. package/dist/utils/assertViteVersion.d.ts +1 -3
  144. package/dist/utils/assertViteVersion.js +6 -9
  145. package/dist/utils/debug.d.ts +1 -1
  146. package/dist/utils/debug.js +1 -1
  147. package/dist/utils/deepEqual.d.ts +2 -1
  148. package/dist/utils/deepEqual.js +21 -6
  149. package/dist/utils/getContentTypeFromUrl.d.ts +2 -0
  150. package/dist/utils/getContentTypeFromUrl.js +39 -0
  151. package/dist/utils/injectRollupInputs.d.ts +2 -2
  152. package/dist/utils/injectRollupInputs.js +2 -2
  153. package/dist/utils/isDev.js +2 -7
  154. package/dist/utils/parseUrl-extras.js +4 -0
  155. package/dist/utils/requireResolve.d.ts +0 -6
  156. package/dist/utils/requireResolve.js +0 -8
  157. package/package.json +9 -10
  158. package/dist/shared-server-client/addIs404ToPageProps.d.ts +0 -2
  159. package/dist/shared-server-client/addIs404ToPageProps.js +0 -17
@@ -12,6 +12,8 @@ import { getAssetsDir } from '../../shared/getAssetsDir.js';
12
12
  import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js';
13
13
  import '../../assertEnvVite.js';
14
14
  import { isVite8OrAbove } from '../../shared/isVite8OrAbove.js';
15
+ import { isViteServerSide_configEnvironment } from '../../shared/isViteServerSide.js';
16
+ import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
15
17
  function pluginDistFileNames() {
16
18
  return [
17
19
  {
@@ -19,42 +21,65 @@ function pluginDistFileNames() {
19
21
  apply: 'build',
20
22
  enforce: 'post',
21
23
  configResolved: {
22
- handler(config) {
23
- const rollupOutputs = getRollupOutputs(config);
24
- // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
25
- rollupOutputs.forEach((rollupOutput) => {
26
- if (!('entryFileNames' in rollupOutput)) {
27
- rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
28
- }
29
- if (!('chunkFileNames' in rollupOutput)) {
30
- rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
31
- }
32
- if (!('assetFileNames' in rollupOutput)) {
33
- rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
34
- rollupOutput.assetFileNames.isTheOneSetByVike = true;
35
- assert(rollupOutput.assetFileNames.isTheOneSetByVike);
36
- }
37
- else {
38
- // If a user needs this:
39
- // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
40
- // - It's needed for getHash() of handleAssetsManifest()
41
- // - Asset URLs should always contain a hash: it's paramount for caching assets.
42
- // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
43
- assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
44
- }
24
+ async handler(config) {
25
+ const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
26
+ Object.entries(config.environments).forEach(([envName, envConfig]) => {
27
+ // Vike doesn't own the builds of additional environments (e.g. `rsc`): it only emits `entry-environment.mjs` there
28
+ if (additionalEnvironmentNames.includes(envName))
29
+ return;
30
+ const { build } = envConfig;
31
+ copyRollupOutputs(build);
32
+ const isServerSide = isViteServerSide_configEnvironment(envName, envConfig);
33
+ setFileNames(config, build, isServerSide, envName);
34
+ disableCSSBundling(config, build);
45
35
  });
46
- disableCSSBundling(config);
47
36
  },
48
37
  },
49
38
  },
50
39
  ];
51
40
  }
41
+ function setFileNames(config, build, isServerSide, envName) {
42
+ const rollupOutputs = getRollupOutputs(build);
43
+ // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
44
+ rollupOutputs.forEach((rollupOutput) => {
45
+ // Server environments other than `ssr` keep their own entry file names, e.g. @vitejs/plugin-rsc imports its `rsc` entry as `index.js`
46
+ if (!('entryFileNames' in rollupOutput) && (!isServerSide || envName === 'ssr')) {
47
+ rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, build, isServerSide);
48
+ }
49
+ if (!('chunkFileNames' in rollupOutput)) {
50
+ rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, build, isServerSide);
51
+ }
52
+ if (!('assetFileNames' in rollupOutput)) {
53
+ rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config, build);
54
+ rollupOutput.assetFileNames.isTheOneSetByVike = true;
55
+ assert(rollupOutput.assetFileNames.isTheOneSetByVike);
56
+ }
57
+ else {
58
+ // If a user needs this:
59
+ // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
60
+ // - It's needed for getHash() of handleAssetsManifest()
61
+ // - Asset URLs should always contain a hash: it's paramount for caching assets.
62
+ // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
63
+ assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
64
+ }
65
+ });
66
+ }
67
+ // Vike sets entryFileNames/chunkFileNames/assetFileNames on an output object only if the user didn't set them. But the user's output object can be:
68
+ // - The same object for several environments.
69
+ // - Reused across Vite's config resolutions, e.g. an inline config such as VITE_CONFIG.
70
+ // Without a copy, the file names Vike sets for one environment look user-set to the next environment, which then keeps the wrong environment's file names.
71
+ function copyRollupOutputs(build) {
72
+ const { output } = build.rollupOptions;
73
+ if (!output)
74
+ return;
75
+ build.rollupOptions.output = isArray(output) ? output.map((o) => ({ ...o })) : { ...output };
76
+ }
52
77
  function getIdHash(id) {
53
78
  return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
54
79
  }
55
- function getAssetFileName(assetInfo, config) {
80
+ function getAssetFileName(assetInfo, config, build) {
56
81
  const userRootDir = config.root;
57
- const assetsDir = getAssetsDir(config);
82
+ const assetsDir = getAssetsDir(build);
58
83
  const dir = assetsDir + '/static';
59
84
  let { name } = assetInfo;
60
85
  if (!name) {
@@ -78,19 +103,19 @@ function getAssetFileName(assetInfo, config) {
78
103
  name = clean(name, userRootDir);
79
104
  return `${dir}/${name}.[hash][extname]`;
80
105
  }
81
- function getChunkFileName(_chunkInfo, config) {
82
- const isForClientSide = !config.build.ssr;
106
+ function getChunkFileName(_chunkInfo, build, isServerSide) {
107
+ const isForClientSide = !isServerSide;
83
108
  let name = 'chunks/chunk-[hash].js';
84
109
  if (isForClientSide) {
85
- const assetsDir = getAssetsDir(config);
110
+ const assetsDir = getAssetsDir(build);
86
111
  name = `${assetsDir}/${name}`;
87
112
  }
88
113
  return name;
89
114
  }
90
- function getEntryFileName(chunkInfo, config, isEntry) {
115
+ function getEntryFileName(chunkInfo, config, build, isServerSide) {
91
116
  const userRootDir = config.root;
92
- const assetsDir = getAssetsDir(config);
93
- const isForClientSide = !config.build.ssr;
117
+ const assetsDir = getAssetsDir(build);
118
+ const isForClientSide = !isServerSide;
94
119
  let { name } = chunkInfo;
95
120
  assertPosixPath(name);
96
121
  name = clean(name, userRootDir, true,
@@ -100,7 +125,7 @@ function getEntryFileName(chunkInfo, config, isEntry) {
100
125
  return `${assetsDir}/${name}.[hash].js`;
101
126
  }
102
127
  else {
103
- return `${name}.${isEntry ? 'mjs' : 'js'}`;
128
+ return `${name}.mjs`;
104
129
  }
105
130
  }
106
131
  function removePathSeparators(name) {
@@ -188,9 +213,9 @@ function workaroundGlob(name) {
188
213
  return name;
189
214
  }
190
215
  // Workaround for Vite CSS duplication bug: https://github.com/vikejs/vike/issues/1815
191
- function disableCSSBundling(config) {
216
+ function disableCSSBundling(config, build) {
192
217
  if (isVite8OrAbove(config)) {
193
- for (const output of getRolldownOutputs(config)) {
218
+ for (const output of getRolldownOutputs(build)) {
194
219
  assert(output);
195
220
  const { codeSplitting } = output;
196
221
  // `codeSplitting: false` => single-bundle mode; respect the user's choice.
@@ -219,7 +244,7 @@ function disableCSSBundling(config) {
219
244
  }
220
245
  }
221
246
  else {
222
- for (const output of getRollupOutputs(config)) {
247
+ for (const output of getRollupOutputs(build)) {
223
248
  assert(output);
224
249
  wrapManualChunks(output, config, 'rollupOptions');
225
250
  }
@@ -291,28 +316,23 @@ function getCssChunkName(id, config) {
291
316
  return `${name}-${hash}`;
292
317
  }
293
318
  }
294
- function getRollupOutputs(config) {
295
- var _a, _b;
296
- // @ts-expect-error is read-only
297
- config.build ?? (config.build = {});
298
- (_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
299
- (_b = config.build.rollupOptions).output ?? (_b.output = {});
300
- const { output } = config.build.rollupOptions;
319
+ function getRollupOutputs(build) {
320
+ var _a;
321
+ (_a = build.rollupOptions).output ?? (_a.output = {});
322
+ const { output } = build.rollupOptions;
301
323
  if (!isArray(output)) {
302
324
  return [output];
303
325
  }
304
326
  return output;
305
327
  }
306
- function getRolldownOutputs(config) {
307
- var _a, _b;
308
- // @ts-expect-error is read-only
309
- config.build ?? (config.build = {});
328
+ function getRolldownOutputs(build) {
329
+ var _a;
310
330
  // @ts-ignore
311
- (_a = config.build).rolldownOptions ?? (_a.rolldownOptions = {});
331
+ build.rolldownOptions ?? (build.rolldownOptions = {});
312
332
  // @ts-ignore
313
- (_b = config.build.rolldownOptions).output ?? (_b.output = {});
333
+ (_a = build.rolldownOptions).output ?? (_a.output = {});
314
334
  // @ts-ignore
315
- const { output } = config.build.rolldownOptions;
335
+ const { output } = build.rolldownOptions;
316
336
  if (!isArray(output)) {
317
337
  return [output];
318
338
  }
@@ -0,0 +1,6 @@
1
+ export { pluginEnvironmentEntries };
2
+ export { getEnvironmentEntryPlaceholder };
3
+ import type { Plugin } from 'vite';
4
+ import '../../assertEnvVite.js';
5
+ declare function pluginEnvironmentEntries(): Plugin[];
6
+ declare function getEnvironmentEntryPlaceholder(environmentName: string): string;
@@ -0,0 +1,71 @@
1
+ export { pluginEnvironmentEntries };
2
+ export { getEnvironmentEntryPlaceholder };
3
+ // Vike's server environment imports the global entry of every additional environment (e.g. `rsc`), see loadPageContextEnvironments.ts
4
+ // - An additional environment is a separate build, so the server imports its entry by a path relative to the importing chunk, which is known only after chunking (the same marker + renderChunk() as @vitejs/plugin-rsc's import.meta.viteRsc.loadModule())
5
+ import { assertUsage } from '../../../../utils/assert.js';
6
+ import { generateVirtualFileIdAdditionalEnvironment } from '../../../../shared-server-node/virtualFileId.js';
7
+ import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
8
+ import { getMagicString } from '../../shared/getMagicString.js';
9
+ import path from 'node:path';
10
+ import '../../assertEnvVite.js';
11
+ const environmentEntryFileName = 'entry-environment.mjs';
12
+ const environmentEntryPlaceholder = '__VIKE_ENVIRONMENT_ENTRY__';
13
+ const environmentEntryPlaceholderRegex = new RegExp(`(["'\`])${environmentEntryPlaceholder}:(.+?)\\1`, 'g');
14
+ function pluginEnvironmentEntries() {
15
+ return [
16
+ {
17
+ name: 'vike:build:emitEnvironmentEntry',
18
+ apply: 'build',
19
+ buildStart: {
20
+ async handler() {
21
+ const { name, config } = this.environment;
22
+ const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
23
+ if (!additionalEnvironmentNames.includes(name))
24
+ return;
25
+ assertUsage(config.consumer === 'server', `The Vike environment ${name} should be a server-side Vite environment`);
26
+ this.emitFile({
27
+ type: 'chunk',
28
+ id: generateVirtualFileIdAdditionalEnvironment(name),
29
+ fileName: environmentEntryFileName,
30
+ });
31
+ },
32
+ },
33
+ },
34
+ {
35
+ name: 'vike:build:linkEnvironmentEntries',
36
+ apply: 'build',
37
+ resolveId: {
38
+ filter: { id: new RegExp(`^${environmentEntryPlaceholder}:`) },
39
+ handler(id) {
40
+ return { id, external: true };
41
+ },
42
+ },
43
+ renderChunk: {
44
+ handler(code, chunk) {
45
+ return replaceEnvironmentEntryPlaceholders(code, chunk.fileName, this.environment);
46
+ },
47
+ },
48
+ },
49
+ ];
50
+ }
51
+ // The import specifier of the environment's entry, replaced by its relative path once the importer's location is known
52
+ function getEnvironmentEntryPlaceholder(environmentName) {
53
+ return `${environmentEntryPlaceholder}:${environmentName}`;
54
+ }
55
+ // Replace each placeholder with the path of the environment's entry, relative to the chunk
56
+ function replaceEnvironmentEntryPlaceholders(code, chunkFileName, environment) {
57
+ if (!code.includes(environmentEntryPlaceholder))
58
+ return;
59
+ const { config } = environment;
60
+ const chunkDir = path.dirname(path.resolve(config.root, config.build.outDir, chunkFileName));
61
+ const { magicString, getMagicStringResult } = getMagicString(code, chunkFileName);
62
+ for (const match of code.matchAll(environmentEntryPlaceholderRegex)) {
63
+ const outDir = config.environments[match[2]].build.outDir;
64
+ const environmentEntry = path.resolve(config.root, outDir, environmentEntryFileName);
65
+ let importPath = path.relative(chunkDir, environmentEntry).split(path.sep).join('/');
66
+ if (!importPath.startsWith('.'))
67
+ importPath = `./${importPath}`;
68
+ magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(importPath));
69
+ }
70
+ return getMagicStringResult();
71
+ }
@@ -9,23 +9,25 @@ function pluginSuppressRollupWarning() {
9
9
  enforce: 'post',
10
10
  configResolved: {
11
11
  async handler(config) {
12
- const onWarnOriginal = config.build.rollupOptions.onwarn;
13
- config.build.rollupOptions.onwarn = function (warning, warn) {
14
- // Suppress
15
- if (suppressUnusedImport(warning))
16
- return;
17
- if (suppressEmptyBundle(warning))
18
- return;
19
- if (suppressUseClientDirective(warning))
20
- return;
21
- // Pass through
22
- if (onWarnOriginal) {
23
- onWarnOriginal.apply(this, arguments);
24
- }
25
- else {
26
- warn(warning);
27
- }
28
- };
12
+ Object.values(config.environments).forEach(({ build }) => {
13
+ const onWarnOriginal = build.rollupOptions.onwarn;
14
+ build.rollupOptions.onwarn = function (warning, warn) {
15
+ // Suppress
16
+ if (suppressUnusedImport(warning))
17
+ return;
18
+ if (suppressEmptyBundle(warning))
19
+ return;
20
+ if (suppressUseClientDirective(warning))
21
+ return;
22
+ // Pass through
23
+ if (onWarnOriginal) {
24
+ onWarnOriginal.apply(this, arguments);
25
+ }
26
+ else {
27
+ warn(warning);
28
+ }
29
+ };
30
+ });
29
31
  },
30
32
  },
31
33
  },
@@ -8,11 +8,11 @@ import { isObject } from '../../../utils/isObject.js';
8
8
  import { assertRollupInput } from './build/pluginBuildConfig.js';
9
9
  import pc from '@brillout/picocolors';
10
10
  import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
11
- import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
11
+ import { getVikeConfigInternal, setVikeConfigContext, setViteEnvironmentNames, } from '../shared/resolveVikeConfigInternal.js';
12
12
  import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigUser.js';
13
13
  import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
14
14
  import { resolvePrerenderConfigGlobal, isDistServerRemoved } from '../../prerender/resolvePrerenderConfig.js';
15
- import { version as viteVersionVike } from 'vite';
15
+ import { assertViteVersion } from '../../../utils/assertViteVersion.js';
16
16
  import '../assertEnvVite.js';
17
17
  const pluginName = 'vike:pluginCommon';
18
18
  globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
@@ -24,7 +24,9 @@ function pluginCommon(vikeVitePluginOptions) {
24
24
  config: {
25
25
  order: 'pre',
26
26
  async handler(configFromUser, env) {
27
- const viteVersionUser = this?.meta?.viteVersion; // is `undefined` on old Vite versions
27
+ // `this` is `undefined` on Vite 6 or older
28
+ const viteVersion = this?.meta.viteVersion;
29
+ assertViteVersion(viteVersion);
28
30
  const isDev = isDevCheck(env);
29
31
  const isBuild = env.command === 'build';
30
32
  const isPreview = env.isPreview;
@@ -38,7 +40,7 @@ function pluginCommon(vikeVitePluginOptions) {
38
40
  const vikeConfig = await getVikeConfigInternal();
39
41
  return {
40
42
  _isDev: isDev,
41
- _viteVersionResolved: viteVersionUser || viteVersionVike,
43
+ _viteVersionResolved: viteVersion,
42
44
  _rootResolvedEarly: rootResolvedEarly,
43
45
  // TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
44
46
  configVikePromise: Promise.resolve({
@@ -52,9 +54,10 @@ function pluginCommon(vikeVitePluginOptions) {
52
54
  {
53
55
  name: pluginName,
54
56
  configResolved: {
55
- handler(config) {
57
+ async handler(config) {
56
58
  assertViteRoot(config._rootResolvedEarly, config);
57
59
  assertSingleInstance(config);
60
+ await setViteEnvironmentNames(Object.keys(config.environments));
58
61
  },
59
62
  },
60
63
  },
@@ -72,7 +75,7 @@ function pluginCommon(vikeVitePluginOptions) {
72
75
  overrideViteDefaultSsrExternal(config)
73
76
  //*/
74
77
  workaroundCI(config);
75
- assertRollupInput(config);
78
+ assertRollupInput(config.build.rollupOptions.input);
76
79
  assertResolveAlias(config);
77
80
  temp_supportOldInterface(config);
78
81
  await emitServerEntryOnlyIfNeeded(config);
@@ -15,6 +15,7 @@ import { requireResolveOptional } from '../../../../utils/requireResolve.js';
15
15
  import { setTimeoutUnref } from '../../../../utils/setTimeoutUnref.js';
16
16
  import { isObject } from '../../../../utils/isObject.js';
17
17
  import { toPosixPath } from '../../../../utils/path.js';
18
+ import { PROJECT_VERSION } from '../../../../utils/PROJECT_VERSION.js';
18
19
  import { unique } from '../../../../utils/unique.js';
19
20
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
20
21
  import { getCacheValue, setCacheValue } from '../../shared/cache.js';
@@ -37,7 +38,7 @@ const skillName = 'vike';
37
38
  // The skill file shipped by the vike npm package: node_modules/vike/skills/vike/SKILL.md (see packages/vike/scripts/copySkill.mjs)
38
39
  const skillFilePathInsidePackage = 'skills/vike/SKILL.md';
39
40
  // Cache entry at node_modules/.vike/cache.json, see cache.ts
40
- // - `false` => the check didn't log anything last time => skip the check (forever, until node_modules/ is removed)
41
+ // - `{ skip: true, version }` => the check didn't log anything last time, with that Vike version => skip the check until Vike is upgraded (the official skill file may change between Vike versions) or node_modules/ is removed
41
42
  // - Nothing is written as long as the hint is logged => the check is re-run upon every dev start
42
43
  const cacheKey = 'logSkillHint';
43
44
  // Log a hint if the user didn't install Vike's skill for AI agents (vike/SKILL.md), or if it differs from the official one — https://vike.dev/ai#skill
@@ -95,8 +96,9 @@ async function checkSkillUnsafe(userRootDir) {
95
96
  if (!getConfigValueAiSkill(vikeConfig))
96
97
  return;
97
98
  globalObject.alreadyChecked = true;
98
- // The check is skipped forever once it didn't log anything (until node_modules/ is removed) — see cacheKey
99
- if ((await getCacheValue(userRootDir, cacheKey)) === false)
99
+ // The check is skipped once it didn't log anything, until Vike is upgraded (or node_modules/ is removed) — see cacheKey
100
+ const cached = await getCacheValue(userRootDir, cacheKey);
101
+ if (isObject(cached) && cached.skip === true && cached.version === PROJECT_VERSION)
100
102
  return;
101
103
  const skillState = await getSkillState(userRootDir);
102
104
  if (skillState.state === 'missing') {
@@ -110,7 +112,7 @@ async function checkSkillUnsafe(userRootDir) {
110
112
  if (skillState.state === 'installed' ||
111
113
  skillState.state === 'not-using-ai-agents' ||
112
114
  skillState.state === 'vike-not-from-npm') {
113
- await setCacheValue(userRootDir, cacheKey, false);
115
+ await setCacheValue(userRootDir, cacheKey, { skip: true, version: PROJECT_VERSION });
114
116
  return;
115
117
  }
116
118
  checkType(skillState);
@@ -191,7 +191,7 @@ async function getPageDeps(config, pageConfigs, pageConfigGlobal) {
191
191
  [...pageConfigs, pageConfigGlobal].forEach((pageConfig) => {
192
192
  Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
193
193
  const runtimeEnv = {
194
- isForClientSide,
194
+ environmentName: isForClientSide ? 'client' : 'server',
195
195
  isDev: true,
196
196
  // TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
197
197
  isClientRouting: true,
@@ -16,7 +16,10 @@ const filterRolldown = {
16
16
  include: new RegExp(escapeRegex(VIRTUAL_FILE_ID_constantsGlobalThis)),
17
17
  },
18
18
  };
19
- const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis || id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
19
+ const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis ||
20
+ // Vite re-resolves the resolved ID and its URL when a plugin adds the module as a watch file (@vitejs/plugin-rsc)
21
+ id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis) ||
22
+ id === `/@id/__x00__${VIRTUAL_FILE_ID_constantsGlobalThis}`;
20
23
  // ===
21
24
  function pluginReplaceConstantsGlobalThis() {
22
25
  let config;
@@ -63,9 +66,8 @@ function pluginReplaceConstantsGlobalThis() {
63
66
  resolveId: {
64
67
  filter: filterRolldown,
65
68
  handler(id) {
66
- assert(filterFunction(id));
67
- assert(id === VIRTUAL_FILE_ID_constantsGlobalThis);
68
- return addVirtualFileIdPrefix(id);
69
+ assert(filterFunction(id), { id });
70
+ return addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
69
71
  },
70
72
  },
71
73
  load: {
@@ -1,7 +1,7 @@
1
1
  export { pluginUniversalDeploy };
2
2
  import { toRou3 } from 'convert-route';
3
3
  import { addEntry } from '@universal-deploy/store';
4
- import universalDeploy, { resolveTargets } from '@universal-deploy/vite';
4
+ import universalDeploy, { precompress, resolveTargets } from '@universal-deploy/vite';
5
5
  import { pluginServerEntryInject } from './pluginUniversalDeploy/pluginServerEntryInject.js';
6
6
  import { getDeployConfig } from './pluginUniversalDeploy/getDeployConfig.js';
7
7
  import { pluginCommon } from './pluginUniversalDeploy/common.js';
@@ -23,10 +23,11 @@ function pluginUniversalDeploy(vikeConfig) {
23
23
  const target = targets.filter((t) => t !== '@cloudflare/vite-plugin')[0];
24
24
  assertUsage(target === undefined, `${target} requires +server — see https://vike.dev/server`);
25
25
  }),
26
+ precompress(vikeConfig.config.precompress),
26
27
  ];
27
28
  const { serverEntryVike, serverEntryId, serverFilePath } = serverConfig;
28
29
  return [
29
- ...universalDeploy(),
30
+ ...universalDeploy({ node: { precompress: vikeConfig.config.precompress } }),
30
31
  {
31
32
  name: 'vike:pluginUniversalDeploy:entries',
32
33
  config() {
@@ -1,3 +1,4 @@
1
1
  export { generateVirtualFileGlobalEntry };
2
+ import type { RuntimeEnvRuntime } from './getConfigValueSourcesRelevant.js';
2
3
  import '../../assertEnvVite.js';
3
- declare function generateVirtualFileGlobalEntry(isForClientSide: boolean, isDev: boolean, id: string, isClientRouting: boolean): Promise<string>;
4
+ declare function generateVirtualFileGlobalEntry(runtimeEnv: RuntimeEnvRuntime, id: string): Promise<string>;
@@ -4,25 +4,31 @@ import { debug } from './debug.js';
4
4
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
5
5
  import { serializeConfigValues, } from '../../../../shared-server-client/page-configs/serialize/serializeConfigValues.js';
6
6
  import { VIRTUAL_FILE_ID_constantsGlobalThis } from '../pluginReplaceConstantsGlobalThis.js';
7
+ import { getEnvironmentEntryPlaceholder } from '../build/pluginEnvironmentEntries.js';
7
8
  import '../../assertEnvVite.js';
8
- async function generateVirtualFileGlobalEntry(isForClientSide, isDev, id, isClientRouting) {
9
+ async function generateVirtualFileGlobalEntry(runtimeEnv, id) {
9
10
  const vikeConfig = await getVikeConfigInternal(true);
10
- const { _pageConfigs: pageConfigs, _pageConfigGlobal: pageConfigGlobal } = vikeConfig;
11
- return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
11
+ const { _pageConfigs: pageConfigs, _pageConfigGlobal: pageConfigGlobal, _additionalEnvironmentNames: additionalEnvironmentNames, } = vikeConfig;
12
+ return getCode(pageConfigs, pageConfigGlobal, runtimeEnv, id, additionalEnvironmentNames);
12
13
  }
13
- function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
14
+ function getCode(pageConfigs, pageConfigGlobal, runtimeEnv, id, additionalEnvironmentNames) {
14
15
  const lines = [];
15
16
  const importStatements = [];
16
17
  const filesEnv = new Map();
18
+ const { environmentName, isDev } = runtimeEnv;
19
+ const isForClientSide = environmentName === 'client';
17
20
  if (!isForClientSide) {
18
21
  importStatements.push(`import '${VIRTUAL_FILE_ID_constantsGlobalThis}';`);
19
22
  }
20
23
  lines.push('export const pageConfigsSerialized = [');
21
- lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
24
+ lines.push(getCodePageConfigsSerialized(pageConfigs, runtimeEnv, importStatements, filesEnv));
22
25
  lines.push('];');
23
26
  lines.push('export const pageConfigGlobalSerialized = {');
24
- lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
27
+ lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, runtimeEnv, importStatements, filesEnv));
25
28
  lines.push('};');
29
+ if (environmentName === 'server') {
30
+ lines.push(getCodeEnvironmentEntries(additionalEnvironmentNames, isDev, importStatements));
31
+ }
26
32
  if (!isForClientSide && isDev) {
27
33
  // https://vite.dev/guide/api-environment-frameworks.html
28
34
  lines.push('if (import.meta.hot) import.meta.hot.accept();');
@@ -31,10 +37,21 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
31
37
  if (!isForClientSide) {
32
38
  code = `import '${VIRTUAL_FILE_ID_constantsGlobalThis}';\n` + code;
33
39
  }
34
- debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
40
+ debug(id, `${environmentName.toUpperCase()}-SIDE`, code);
35
41
  return code;
36
42
  }
37
- function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
43
+ // The global entries of the additional environments (e.g. `rsc`), loaded by loadPageContextEnvironments.ts
44
+ // - In development, they're loaded with the environment's module runner instead
45
+ function getCodeEnvironmentEntries(additionalEnvironmentNames, isDev, importStatements) {
46
+ const entries = additionalEnvironmentNames.map((name, i) => {
47
+ if (isDev)
48
+ return `${JSON.stringify(name)}: null`;
49
+ importStatements.push(`import * as environmentEntry${i} from ${JSON.stringify(getEnvironmentEntryPlaceholder(name))};`);
50
+ return `${JSON.stringify(name)}: environmentEntry${i}`;
51
+ });
52
+ return `export const environmentEntries = { ${entries.join(', ')} };`;
53
+ }
54
+ function getCodePageConfigsSerialized(pageConfigs, runtimeEnv, importStatements, filesEnv) {
38
55
  const lines = [];
39
56
  pageConfigs.forEach((pageConfig) => {
40
57
  const { pageId, routeFilesystem, isErrorPage } = pageConfig;
@@ -42,20 +59,20 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
42
59
  lines.push(` pageId: ${JSON.stringify(pageId)},`);
43
60
  lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
44
61
  lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
45
- const virtualFileId = JSON.stringify(generateVirtualFileId({ type: 'page-entry', pageId, isForClientSide }));
62
+ const virtualFileId = JSON.stringify(generateVirtualFileId({ type: 'page-entry', pageId, environmentName: runtimeEnv.environmentName }));
46
63
  lines.push(` loadVirtualFilePageEntry: () => ({ moduleId: ${virtualFileId}, moduleExportsPromise: import(${virtualFileId}) }),`);
47
64
  lines.push(` configValuesSerialized: {`);
48
- lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', true));
65
+ lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, runtimeEnv, ' ', true));
49
66
  lines.push(` },`);
50
67
  lines.push(` },`);
51
68
  });
52
69
  const code = lines.join('\n');
53
70
  return code;
54
71
  }
55
- function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
72
+ function getCodePageConfigGlobalSerialized(pageConfigGlobal, runtimeEnv, importStatements, filesEnv) {
56
73
  const lines = [];
57
74
  lines.push(` configValuesSerialized: {`);
58
- lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', null));
75
+ lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv, runtimeEnv, ' ', null));
59
76
  lines.push(` },`);
60
77
  const code = lines.join('\n');
61
78
  return code;
@@ -18,7 +18,8 @@ import '../../assertEnvVite.js';
18
18
  async function generateVirtualFileGlobalEntryWithOldDesign(id, options, config, env, isDev) {
19
19
  const idParsed = parseVirtualFileId(id);
20
20
  assert(idParsed && idParsed.type === 'global-entry');
21
- const { isForClientSide, isClientRouting } = idParsed;
21
+ const { environmentName, isClientRouting } = idParsed;
22
+ const isForClientSide = environmentName === 'client';
22
23
  assert(isForClientSide === !isViteServerSide_extraSafe(config, env, options));
23
24
  const code = await getCode(config, isForClientSide, isClientRouting, isDev, id);
24
25
  return code;
@@ -75,7 +76,7 @@ export const pageFilesExportNamesEager = {};
75
76
  export const pageFilesList = [];
76
77
  export const neverLoaded = {};
77
78
 
78
- ${await generateVirtualFileGlobalEntry(isForClientSide, isDev, id, isClientRouting)}
79
+ ${await generateVirtualFileGlobalEntry({ environmentName: isForClientSide ? 'client' : 'server', isClientRouting, isDev }, id)}
79
80
 
80
81
  `;
81
82
  const vikeConfig = await getVikeConfigInternal();
@@ -18,7 +18,7 @@ async function generateVirtualFilePageEntry(id, isDev) {
18
18
  assert(result.isForClientSide === isForClientSide)
19
19
  }
20
20
  */
21
- const { pageId, isForClientSide } = result;
21
+ const { pageId, environmentName } = result;
22
22
  const vikeConfig = await getVikeConfigInternal(true);
23
23
  const { _pageConfigs: pageConfigs } = vikeConfig;
24
24
  const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
@@ -31,20 +31,20 @@ async function generateVirtualFilePageEntry(id, isDev) {
31
31
  throw getProjectError(`Outdated request. Try again. ${getDebugInfoStr({ id, pageId })}`);
32
32
  }
33
33
  }
34
- const code = getCode(pageConfig, isForClientSide, pageId, resolveIncludeAssetsImportedByServer(vikeConfig.config), isDev);
35
- debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
34
+ const code = getCode(pageConfig, environmentName, pageId, resolveIncludeAssetsImportedByServer(vikeConfig.config), isDev);
35
+ debug(id, `${environmentName.toUpperCase()}-SIDE`, code);
36
36
  return code;
37
37
  }
38
- function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
38
+ function getCode(pageConfig, environmentName, pageId, includeAssetsImportedByServer, isDev) {
39
39
  const lines = [];
40
40
  const importStatements = [];
41
41
  const filesEnv = new Map();
42
42
  const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
43
43
  lines.push('export const configValuesSerialized = {');
44
- lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
44
+ lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { environmentName, isClientRouting, isDev }, '', false));
45
45
  lines.push('};');
46
- if (!handleAssetsManifest_isFixEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
47
- importStatements.push(`import '${extractAssetsAddQuery(generateVirtualFileId({ type: 'page-entry', pageId, isForClientSide: false }))}'`);
46
+ if (!handleAssetsManifest_isFixEnabled() && includeAssetsImportedByServer && environmentName === 'client' && !isDev) {
47
+ importStatements.push(`import '${extractAssetsAddQuery(generateVirtualFileId({ type: 'page-entry', pageId, environmentName: 'server' }))}'`);
48
48
  }
49
49
  const code = [...importStatements, ...lines].join('\n');
50
50
  return code;