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.
Files changed (197) hide show
  1. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -2
  2. package/dist/cjs/node/prerender/runPrerender.js +1 -0
  3. package/dist/cjs/node/runtime/globalContext.js +10 -0
  4. package/dist/cjs/node/runtime/index.js +3 -3
  5. package/dist/cjs/node/runtime/page-files/setup.js +3 -1
  6. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -9
  7. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  8. package/dist/cjs/node/runtime/renderPage/csp.js +47 -0
  9. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  10. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -1
  11. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  12. package/dist/cjs/node/runtime/renderPage/headersResponse.js +48 -0
  13. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  14. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  15. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +8 -6
  16. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  17. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  18. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +5 -3
  19. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  20. package/dist/cjs/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  21. package/dist/cjs/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  22. package/dist/cjs/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  23. package/dist/cjs/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  24. package/dist/cjs/node/runtime/{html → renderPage/html}/stream.js +1 -1
  25. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +17 -38
  26. package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  27. package/dist/cjs/node/runtime/renderPage.js +1 -1
  28. package/dist/cjs/node/vite/onLoad.js +1 -1
  29. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
  30. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  31. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  32. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  33. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  34. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  35. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +17 -9
  36. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  37. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  38. package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
  39. package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
  40. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +62 -57
  41. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +107 -93
  42. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +27 -13
  43. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +107 -84
  44. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +40 -21
  45. package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
  46. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +59 -33
  47. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  48. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
  49. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +54 -36
  50. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  51. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  52. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
  53. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +20 -22
  54. package/dist/cjs/shared/createGlobalContextShared.js +4 -22
  55. package/dist/cjs/shared/createPageContextShared.js +2 -2
  56. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  57. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  58. package/dist/cjs/utils/assert.js +16 -1
  59. package/dist/cjs/utils/assertNodeVersion.js +3 -1
  60. package/dist/cjs/utils/assertVersion.js +26 -5
  61. package/dist/cjs/utils/joinEnglish.js +2 -1
  62. package/dist/cjs/utils/virtualFileId.js +15 -11
  63. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +40 -17
  64. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
  65. package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
  66. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +99 -85
  67. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +39 -11
  68. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
  69. package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
  70. package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
  71. package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  72. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +44 -29
  73. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +40 -17
  74. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
  75. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +39 -11
  76. package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  77. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +39 -11
  78. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
  79. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
  80. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -3
  81. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
  82. package/dist/esm/node/prerender/resolvePrerenderConfig.js +4 -3
  83. package/dist/esm/node/prerender/runPrerender.d.ts +61 -16
  84. package/dist/esm/node/prerender/runPrerender.js +2 -1
  85. package/dist/esm/node/runtime/globalContext.d.ts +167 -42
  86. package/dist/esm/node/runtime/globalContext.js +11 -1
  87. package/dist/esm/node/runtime/index.d.ts +3 -3
  88. package/dist/esm/node/runtime/index.js +3 -3
  89. package/dist/esm/node/runtime/page-files/setup.js +3 -1
  90. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
  91. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -9
  92. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +56 -12
  93. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  94. package/dist/esm/node/runtime/renderPage/csp.d.ts +12 -0
  95. package/dist/esm/node/runtime/renderPage/csp.js +45 -0
  96. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +2 -2
  97. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  98. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
  99. package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -1
  100. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +2 -2
  101. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  102. package/dist/esm/node/runtime/renderPage/headersResponse.d.ts +10 -0
  103. package/dist/esm/node/runtime/renderPage/headersResponse.js +46 -0
  104. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.d.ts +1 -1
  105. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  106. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.d.ts +1 -1
  107. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  108. package/dist/esm/node/runtime/renderPage/html/injectAssets/inferHtmlTags.d.ts +10 -0
  109. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +7 -5
  110. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  111. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  112. package/dist/esm/node/runtime/renderPage/html/injectAssets/mergeScriptTags.d.ts +3 -0
  113. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +6 -4
  114. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.d.ts +2 -2
  115. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  116. package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  117. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.d.ts +1 -1
  118. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  119. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.d.ts +6 -5
  120. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  121. package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  122. package/dist/esm/node/runtime/{html → renderPage/html}/stream.js +1 -1
  123. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +66 -17
  124. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -39
  125. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
  126. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +122 -32
  127. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  128. package/dist/esm/node/runtime/renderPage.d.ts +56 -12
  129. package/dist/esm/node/runtime/renderPage.js +1 -1
  130. package/dist/esm/node/vite/onLoad.js +1 -1
  131. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
  132. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  133. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  134. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  135. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  136. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  137. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +18 -10
  138. package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  139. package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  140. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
  141. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  142. package/dist/esm/node/vite/plugins/pluginEnvVars.js +62 -57
  143. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +107 -91
  144. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +27 -13
  145. package/dist/esm/node/vite/plugins/pluginFileEnv.js +107 -84
  146. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +41 -22
  147. package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
  148. package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
  149. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +58 -33
  150. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  151. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
  152. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +56 -38
  153. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  154. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  155. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
  156. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -8
  157. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +22 -24
  158. package/dist/esm/shared/createGlobalContextShared.d.ts +75 -19
  159. package/dist/esm/shared/createGlobalContextShared.js +5 -23
  160. package/dist/esm/shared/createPageContextShared.d.ts +2 -7
  161. package/dist/esm/shared/createPageContextShared.js +2 -2
  162. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  163. package/dist/esm/shared/hooks/execHook.d.ts +2 -2
  164. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  165. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +91 -31
  166. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  167. package/dist/esm/types/Config/ConfigResolved.d.ts +8 -0
  168. package/dist/esm/types/Config.d.ts +14 -6
  169. package/dist/esm/types/PageContext.d.ts +8 -25
  170. package/dist/esm/types/VikeNamespace.d.ts +0 -27
  171. package/dist/esm/types/index.d.ts +2 -2
  172. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  173. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  174. package/dist/esm/utils/assert.js +16 -1
  175. package/dist/esm/utils/assertNodeVersion.js +3 -1
  176. package/dist/esm/utils/assertVersion.d.ts +4 -3
  177. package/dist/esm/utils/assertVersion.js +23 -5
  178. package/dist/esm/utils/joinEnglish.js +2 -1
  179. package/dist/esm/utils/virtualFileId.d.ts +4 -0
  180. package/dist/esm/utils/virtualFileId.js +14 -11
  181. package/package.json +5 -5
  182. package/dist/cjs/types/Config/helpers.js +0 -2
  183. package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +0 -9
  184. package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +0 -2
  185. package/dist/esm/types/Config/PageContextConfig.d.ts +0 -15
  186. package/dist/esm/types/Config/helpers.d.ts +0 -10
  187. package/dist/esm/types/Config/helpers.js +0 -1
  188. /package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  189. /package/dist/cjs/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
  190. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.d.ts +0 -0
  191. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.d.ts +0 -0
  192. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.d.ts +0 -0
  193. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  194. /package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.d.ts +0 -0
  195. /package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.d.ts +0 -0
  196. /package/dist/esm/node/runtime/{html → renderPage/html}/stream.d.ts +0 -0
  197. /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(config) {
16
- const rollupOutputs = getRollupOutputs(config);
17
- // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
18
- rollupOutputs.forEach((rollupOutput) => {
19
- if (!('entryFileNames' in rollupOutput)) {
20
- rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
21
- }
22
- if (!('chunkFileNames' in rollupOutput)) {
23
- rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
24
- }
25
- if (!('assetFileNames' in rollupOutput)) {
26
- rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
27
- rollupOutput.assetFileNames.isTheOneSetByVike = true;
28
- assert(rollupOutput.assetFileNames.isTheOneSetByVike);
29
- }
30
- else {
31
- // If a user needs this:
32
- // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
33
- // - It's needed for getHash() of handleAssetsManifest()
34
- // - Asset URLs should always contain a hash: it's paramount for caching assets.
35
- // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
36
- assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
37
- }
38
- {
39
- const manualChunksOriginal = rollupOutput.manualChunks;
40
- rollupOutput.manualChunks = function (id, ...args) {
41
- if (manualChunksOriginal) {
42
- if (isCallable(manualChunksOriginal)) {
43
- const result = manualChunksOriginal.call(this, id, ...args);
44
- if (result !== undefined)
45
- return result;
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
- const filePath = getModuleFilePathAbsolute(id, config);
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
- else {
76
- let name;
77
- const isVirtualModule = id.match(/virtual:([^:]+):/);
78
- if (isVirtualModule) {
79
- name = isVirtualModule[1];
80
- assert(name);
81
- }
82
- else if (
83
- // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
84
- id.startsWith('/__uno')) {
85
- name = 'uno';
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 = 'style';
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(config_) {
10
- config = config_;
9
+ configResolved: {
10
+ handler(config_) {
11
+ config = config_;
12
+ },
11
13
  },
12
- generateBundle(options, bundle) {
13
- if (!isViteServerSide(config, this.environment))
14
- return;
15
- const isEsm = rollupIsEsm(options);
16
- const fileName = 'package.json';
17
- if (bundle[fileName])
18
- return; // E.g. already generated by Telefunc / vike
19
- this.emitFile({
20
- fileName,
21
- type: 'asset',
22
- source: getPackageJsonContent(isEsm),
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
  }
@@ -1,7 +1,6 @@
1
1
  export { pluginModuleBanner };
2
- import { removeVirtualFileIdPrefix } from '../../utils.js';
2
+ import { assert, removeVirtualFileIdPrefix } from '../../utils.js';
3
3
  import { getMagicString } from '../../shared/getMagicString.js';
4
- import { isViteServerSide_extraSafe } from '../../shared/isViteServerSide.js';
5
4
  // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
6
5
  // But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
7
6
  function pluginModuleBanner() {
@@ -10,17 +9,26 @@ function pluginModuleBanner() {
10
9
  name: 'vike:build:pluginModuleBanner',
11
10
  enforce: 'post',
12
11
  apply: 'build',
13
- configResolved(config_) {
14
- config = config_;
12
+ applyToEnvironment(environment) {
13
+ const { config } = environment;
14
+ const { consumer } = config;
15
+ const { minify } = config.build;
16
+ assert(minify === false || minify, { minify, consumer });
17
+ return !minify;
18
+ },
19
+ configResolved: {
20
+ handler(config_) {
21
+ config = config_;
22
+ },
15
23
  },
16
24
  transform: {
17
25
  order: 'post',
18
- handler(code, id, options) {
19
- if (!isViteServerSide_extraSafe(config, this.environment, options) &&
20
- // Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
21
- config.build.minify) {
22
- return;
23
- }
26
+ /* Using a Rolldown hook filter doesn't make sense here — we use applyToEnvironment() to conditionally apply this plugin.
27
+ filter: {},
28
+ */
29
+ handler(code, id) {
30
+ const { minify } = this.environment.config.build;
31
+ assert(minify === false, { minify });
24
32
  if (id.startsWith('\0'))
25
33
  id = id;
26
34
  id = removeVirtualFileIdPrefix(id);
@@ -17,8 +17,10 @@ function pluginProdBuildEntry() {
17
17
  name: 'vike:build:pluginProdBuildEntry',
18
18
  apply: 'build',
19
19
  enforce: 'post',
20
- async configResolved(config_) {
21
- config = config_;
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
- async configResolved(config) {
9
- const onWarnOriginal = config.build.rollupOptions.onwarn;
10
- config.build.rollupOptions.onwarn = function (warning, warn) {
11
- // Suppress
12
- if (suppressUnusedImport(warning))
13
- return;
14
- if (suppressEmptyBundle(warning))
15
- return;
16
- if (suppressUseClientDirective(warning))
17
- return;
18
- // Pass through
19
- if (onWarnOriginal) {
20
- onWarnOriginal.apply(this, arguments);
21
- }
22
- else {
23
- warn(warning);
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, findPackageJson, hasProp, isDevCheck, isDocker, isObject, isVitest, } from '../utils.js';
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(config) {
46
- assertViteRoot(config._rootResolvedEarly, config);
47
- assertSingleInstance(config);
48
- installRequireShim_setUserRootDir(config.root);
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 (!isVersionOrAbove(version, '5.0.12')) return
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
- return {
22
- appType: 'custom',
23
- // TO-DO/next-major-release: remove (AFAICT we only need to use config.optimizeDeps for the old design)
24
- optimizeDeps: {
25
- exclude: [
26
- // We exclude Vike's client runtime to be able to use Vite's import.meta.glob()
27
- 'vike/client',
28
- 'vike/client/router',
29
- // It seems like client-side/isomorphic imports also need to be excluded, in order to avoid the following:
30
- // ```
31
- // Client runtime loaded twice https://vike.dev/client-runtime-duplicated
32
- // ```
33
- 'vike/routing',
34
- 'vike/getPageContext',
35
- // We exclude @brillout/json-serializer and @brillout/picocolors to avoid:
36
- // ```
37
- // 9:28:58 AM [vite] ✨ new dependencies optimized: @brillout/json-serializer/parse
38
- // 9:28:58 AM [vite] ✨ optimized dependencies changed. reloading
39
- // ```
40
- '@brillout/json-serializer/parse',
41
- '@brillout/json-serializer/stringify',
42
- '@brillout/picocolors',
43
- // We exclude all packages that depend on any optimizeDeps.exclude entry because, otherwise, the entry cannot be resolved when using pnpm. For example:
44
- // ```
45
- // Failed to resolve import "@brillout/json-serializer/parse" from "../../packages/vike-react-query/dist/renderer/VikeReactQueryWrapper.js". Does the file exist?
46
- // 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
47
- // 344| import { parse as parse2 } from "@brillout/json-serializer/parse";
48
- // ```
49
- // The source map is confusing, the import actually lives at node_modules/.vite/deps/vike-react-query_renderer_VikeReactQueryWrapper.js which contains:
50
- // ```js
51
- // // ../../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
52
- // import { parse as parse2 } from "@brillout/json-serializer/parse";
53
- // ```
54
- 'react-streaming',
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
- async configResolved(config_) {
60
- config = config_;
61
- await determineOptimizeDeps(config);
62
- await determineFsAllowList(config);
63
- if (!isErrorDebug()) {
64
- await installHttpRequestAsyncStore();
65
- improveViteLogs(config);
66
- }
67
- logDockerHint(config.server.host);
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
  {