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.
Files changed (191) hide show
  1. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -2
  2. package/dist/cjs/node/runtime/globalContext.js +1 -0
  3. package/dist/cjs/node/runtime/index.js +3 -3
  4. package/dist/cjs/node/runtime/page-files/setup.js +3 -1
  5. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -9
  6. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  7. package/dist/cjs/node/runtime/renderPage/csp.js +47 -0
  8. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  9. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -1
  10. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  11. package/dist/cjs/node/runtime/renderPage/headersResponse.js +48 -0
  12. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  13. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  14. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +8 -6
  15. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  16. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  17. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +5 -3
  18. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  19. package/dist/cjs/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  20. package/dist/cjs/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  21. package/dist/cjs/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  22. package/dist/cjs/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  23. package/dist/cjs/node/runtime/{html → renderPage/html}/stream.js +1 -1
  24. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +17 -38
  25. package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  26. package/dist/cjs/node/runtime/renderPage.js +1 -1
  27. package/dist/cjs/node/vite/onLoad.js +1 -1
  28. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
  29. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  30. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  31. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  32. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  33. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  34. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  35. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  36. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  37. package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
  38. package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
  39. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +63 -57
  40. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +101 -91
  41. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +24 -16
  42. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +67 -57
  43. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +26 -19
  44. package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
  45. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +41 -33
  46. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  47. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
  48. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +50 -37
  49. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  50. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  51. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
  52. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +20 -22
  53. package/dist/cjs/shared/createGlobalContextShared.js +4 -22
  54. package/dist/cjs/shared/createPageContextShared.js +2 -2
  55. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  56. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  57. package/dist/cjs/utils/assert.js +16 -1
  58. package/dist/cjs/utils/assertNodeVersion.js +3 -1
  59. package/dist/cjs/utils/assertVersion.js +26 -5
  60. package/dist/cjs/utils/joinEnglish.js +2 -1
  61. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +39 -16
  62. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
  63. package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
  64. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +97 -83
  65. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +38 -10
  66. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
  67. package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
  68. package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
  69. package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  70. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +43 -28
  71. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +39 -16
  72. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
  73. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +38 -10
  74. package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  75. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +38 -10
  76. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
  77. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
  78. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -3
  79. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
  80. package/dist/esm/node/prerender/resolvePrerenderConfig.js +4 -3
  81. package/dist/esm/node/prerender/runPrerender.d.ts +57 -14
  82. package/dist/esm/node/runtime/globalContext.d.ts +154 -40
  83. package/dist/esm/node/runtime/globalContext.js +1 -0
  84. package/dist/esm/node/runtime/index.d.ts +3 -3
  85. package/dist/esm/node/runtime/index.js +3 -3
  86. package/dist/esm/node/runtime/page-files/setup.js +3 -1
  87. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
  88. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -9
  89. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +52 -10
  90. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  91. package/dist/esm/node/runtime/renderPage/csp.d.ts +12 -0
  92. package/dist/esm/node/runtime/renderPage/csp.js +45 -0
  93. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +2 -2
  94. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  95. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
  96. package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -1
  97. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +2 -2
  98. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  99. package/dist/esm/node/runtime/renderPage/headersResponse.d.ts +10 -0
  100. package/dist/esm/node/runtime/renderPage/headersResponse.js +46 -0
  101. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.d.ts +1 -1
  102. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  103. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.d.ts +1 -1
  104. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  105. package/dist/esm/node/runtime/renderPage/html/injectAssets/inferHtmlTags.d.ts +10 -0
  106. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +7 -5
  107. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  108. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  109. package/dist/esm/node/runtime/renderPage/html/injectAssets/mergeScriptTags.d.ts +3 -0
  110. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +6 -4
  111. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.d.ts +2 -2
  112. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  113. package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  114. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.d.ts +1 -1
  115. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  116. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.d.ts +6 -5
  117. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  118. package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  119. package/dist/esm/node/runtime/{html → renderPage/html}/stream.js +1 -1
  120. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +62 -15
  121. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -39
  122. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
  123. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +114 -28
  124. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  125. package/dist/esm/node/runtime/renderPage.d.ts +52 -10
  126. package/dist/esm/node/runtime/renderPage.js +1 -1
  127. package/dist/esm/node/vite/onLoad.js +1 -1
  128. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
  129. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  130. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  131. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  132. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  133. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  134. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -2
  135. package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  136. package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  137. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
  138. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  139. package/dist/esm/node/vite/plugins/pluginEnvVars.js +63 -57
  140. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +101 -91
  141. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +24 -16
  142. package/dist/esm/node/vite/plugins/pluginFileEnv.js +67 -57
  143. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +26 -19
  144. package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
  145. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +41 -33
  146. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  147. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
  148. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +51 -38
  149. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  150. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  151. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
  152. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -8
  153. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +22 -24
  154. package/dist/esm/shared/createGlobalContextShared.d.ts +73 -17
  155. package/dist/esm/shared/createGlobalContextShared.js +5 -23
  156. package/dist/esm/shared/createPageContextShared.d.ts +2 -7
  157. package/dist/esm/shared/createPageContextShared.js +2 -2
  158. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  159. package/dist/esm/shared/hooks/execHook.d.ts +2 -2
  160. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  161. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +91 -31
  162. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  163. package/dist/esm/types/Config/ConfigResolved.d.ts +8 -0
  164. package/dist/esm/types/Config.d.ts +14 -6
  165. package/dist/esm/types/PageContext.d.ts +8 -25
  166. package/dist/esm/types/VikeNamespace.d.ts +0 -27
  167. package/dist/esm/types/index.d.ts +2 -2
  168. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  169. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  170. package/dist/esm/utils/assert.js +16 -1
  171. package/dist/esm/utils/assertNodeVersion.js +3 -1
  172. package/dist/esm/utils/assertVersion.d.ts +4 -3
  173. package/dist/esm/utils/assertVersion.js +23 -5
  174. package/dist/esm/utils/joinEnglish.js +2 -1
  175. package/package.json +2 -2
  176. package/dist/cjs/types/Config/helpers.js +0 -2
  177. package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +0 -9
  178. package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +0 -2
  179. package/dist/esm/types/Config/PageContextConfig.d.ts +0 -15
  180. package/dist/esm/types/Config/helpers.d.ts +0 -10
  181. package/dist/esm/types/Config/helpers.js +0 -1
  182. /package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  183. /package/dist/cjs/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
  184. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.d.ts +0 -0
  185. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.d.ts +0 -0
  186. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.d.ts +0 -0
  187. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  188. /package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.d.ts +0 -0
  189. /package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.d.ts +0 -0
  190. /package/dist/esm/node/runtime/{html → renderPage/html}/stream.d.ts +0 -0
  191. /package/dist/esm/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
@@ -33,24 +33,26 @@ function pluginExtractAssets() {
33
33
  // In dev, things just work. (Because Vite's module graph erroneously conflates the Vite server-side importees with the client-side importees.)
34
34
  apply: 'build',
35
35
  enforce: 'post',
36
- async transform(src, id, options) {
37
- id = normalizeId(id);
38
- if (!extractAssetsRE.test(id)) {
39
- return;
40
- }
41
- if (isFixEnabled) {
42
- // I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
43
- assertV1Design(vikeConfig._pageConfigs, true);
44
- assert(false);
45
- }
46
- const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
47
- assert(includeAssetsImportedByServer);
48
- assert(!isViteServerSide_extraSafe(config, this.environment, options));
49
- const importStatements = await getImportStatements(src);
50
- const moduleNames = getImportedModules(importStatements);
51
- const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
52
- debugTransformResult(id, code, importStatements);
53
- return rollupSourceMapRemove(code);
36
+ transform: {
37
+ async handler(src, id, options) {
38
+ id = normalizeId(id);
39
+ if (!extractAssetsRE.test(id)) {
40
+ return;
41
+ }
42
+ if (isFixEnabled) {
43
+ // I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
44
+ assertV1Design(vikeConfig._pageConfigs, true);
45
+ assert(false);
46
+ }
47
+ const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
48
+ assert(includeAssetsImportedByServer);
49
+ assert(!isViteServerSide_extraSafe(config, this.environment, options));
50
+ const importStatements = await getImportStatements(src);
51
+ const moduleNames = getImportedModules(importStatements);
52
+ const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
53
+ debugTransformResult(id, code, importStatements);
54
+ return rollupSourceMapRemove(code);
55
+ },
54
56
  },
55
57
  },
56
58
  // This plugin appends `?extractAssets` to module IDs
@@ -61,89 +63,97 @@ function pluginExtractAssets() {
61
63
  // - rollup's `alias` plugin; https://github.com/rollup/plugins/blob/5363f55aa1933b6c650832b08d6a54cb9ea64539/packages/alias/src/index.ts
62
64
  // - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
63
65
  enforce: 'pre',
64
- async resolveId(source, importer, options) {
65
- if (isViteServerSide_extraSafe(config, this.environment, options)) {
66
- // When building for the server, there should never be a `?extractAssets` query
67
- assert(!extractAssetsRE.test(source));
68
- assert(importer === undefined || !extractAssetsRE.test(importer));
69
- return;
70
- }
71
- // If there is no `importer` then `module` is an entry.
72
- // We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
73
- if (!importer) {
74
- return;
75
- }
76
- // We only append `?extractAssets` if the parent module has `?extractAssets`
77
- if (!extractAssetsRE.test(importer)) {
78
- return;
79
- }
80
- const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
81
- assert(includeAssetsImportedByServer);
82
- let resolution = null;
83
- try {
84
- resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
85
- }
86
- catch { }
87
- // Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
88
- if (!resolution)
89
- return emptyModule(source, importer);
90
- const { id: file, external } = resolution;
91
- // Nothing is externalized when building for the client-side
92
- assert(external === false);
93
- // We include:
94
- // - CSS(/LESS/SCSS/...) files
95
- // - Asset files (`.svg`, `.pdf`, ...)
96
- // - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
97
- if (styleFileRE.test(file) || isAsset(file) || urlRE.test(file)) {
98
- debugOperation('INCLUDED', file, importer);
99
- return resolution;
100
- }
101
- // We erase `source` if its file doesn't contain JavaScript
102
- if (!isScriptFile(file)) {
103
- return emptyModule(file, importer);
104
- }
105
- // If the import path resolves to a file in `node_modules/`, we ignore that file:
106
- // - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
107
- // - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
108
- assertPosixPath(file);
109
- if (file.includes('/node_modules/')) {
110
- return emptyModule(file, importer);
111
- }
112
- // When a library is symlinked, it lives outside `root`.
113
- assertPosixPath(config.root);
114
- if (!file.startsWith(config.root)) {
115
- return emptyModule(file, importer);
116
- }
117
- return appendExtractAssetsQuery(file, importer);
66
+ resolveId: {
67
+ async handler(source, importer, options) {
68
+ if (isViteServerSide_extraSafe(config, this.environment, options)) {
69
+ // When building for the server, there should never be a `?extractAssets` query
70
+ assert(!extractAssetsRE.test(source));
71
+ assert(importer === undefined || !extractAssetsRE.test(importer));
72
+ return;
73
+ }
74
+ // If there is no `importer` then `module` is an entry.
75
+ // We don't need to append `?extractAssets` to entries because they already have `?extractAssets` as Vike appends `?extractAssets` to entries by using `import.meta.glob('/**/*.page.server.js', { as: "extractAssets" })` (see `generateImportGlobs.ts`).
76
+ if (!importer) {
77
+ return;
78
+ }
79
+ // We only append `?extractAssets` if the parent module has `?extractAssets`
80
+ if (!extractAssetsRE.test(importer)) {
81
+ return;
82
+ }
83
+ const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
84
+ assert(includeAssetsImportedByServer);
85
+ let resolution = null;
86
+ try {
87
+ resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
88
+ }
89
+ catch { }
90
+ // Sometimes Rollup fails to resolve. If it fails to resolve, we assume the dependency to be an npm package and we skip it. (I guess Rollup should always be able to resolve local dependencies?)
91
+ if (!resolution)
92
+ return emptyModule(source, importer);
93
+ const { id: file, external } = resolution;
94
+ // Nothing is externalized when building for the client-side
95
+ assert(external === false);
96
+ // We include:
97
+ // - CSS(/LESS/SCSS/...) files
98
+ // - Asset files (`.svg`, `.pdf`, ...)
99
+ // - URL imports (e.g. `import scriptUrl from './script.js?url.js'`)
100
+ if (styleFileRE.test(file) || isAsset(file) || urlRE.test(file)) {
101
+ debugOperation('INCLUDED', file, importer);
102
+ return resolution;
103
+ }
104
+ // We erase `source` if its file doesn't contain JavaScript
105
+ if (!isScriptFile(file)) {
106
+ return emptyModule(file, importer);
107
+ }
108
+ // If the import path resolves to a file in `node_modules/`, we ignore that file:
109
+ // - Direct CSS dependencies are included though, such as `import 'bootstrap/theme/dark.css'`. (Because the above if-branch for CSS files will add the file.)
110
+ // - Loading CSS from a library (living in `node_modules/`) in a non-direct way is unconventional; we can safely not support this case. (I'm not aware of any library that does this.)
111
+ assertPosixPath(file);
112
+ if (file.includes('/node_modules/')) {
113
+ return emptyModule(file, importer);
114
+ }
115
+ // When a library is symlinked, it lives outside `root`.
116
+ assertPosixPath(config.root);
117
+ if (!file.startsWith(config.root)) {
118
+ return emptyModule(file, importer);
119
+ }
120
+ return appendExtractAssetsQuery(file, importer);
121
+ },
118
122
  },
119
123
  },
120
124
  {
121
125
  name: 'vike:pluginExtractAssets-3',
122
126
  apply: 'build',
123
- load(id) {
124
- if (!isVirtualFileId(id))
125
- return undefined;
126
- id = removeVirtualFileIdPrefix(id);
127
- if (id === EMPTY_MODULE_ID) {
128
- return '// Erased by vike:pluginExtractAssets';
129
- }
127
+ load: {
128
+ handler(id) {
129
+ if (!isVirtualFileId(id))
130
+ return undefined;
131
+ id = removeVirtualFileIdPrefix(id);
132
+ if (id === EMPTY_MODULE_ID) {
133
+ return '// Erased by vike:pluginExtractAssets';
134
+ }
135
+ },
130
136
  },
131
- config() {
132
- if (debug.isActivated) {
133
- return { logLevel: 'silent' };
134
- }
137
+ config: {
138
+ handler() {
139
+ if (debug.isActivated) {
140
+ return { logLevel: 'silent' };
141
+ }
142
+ },
135
143
  },
136
144
  },
137
145
  {
138
146
  name: 'vike:pluginExtractAssets-4',
139
- async configResolved(config_) {
140
- config = config_;
141
- vikeConfig = await getVikeConfigInternal();
142
- isFixEnabled = handleAssetsManifest_isFixEnabled();
143
- if (!isFixEnabled) {
144
- // https://github.com/vikejs/vike/issues/1060
145
- assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
146
- }
147
+ configResolved: {
148
+ async handler(config_) {
149
+ config = config_;
150
+ vikeConfig = await getVikeConfigInternal();
151
+ isFixEnabled = handleAssetsManifest_isFixEnabled();
152
+ if (!isFixEnabled) {
153
+ // https://github.com/vikejs/vike/issues/1060
154
+ assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
155
+ }
156
+ },
147
157
  },
148
158
  },
149
159
  ];
@@ -14,25 +14,33 @@ function pluginExtractExportNames() {
14
14
  return {
15
15
  name: 'vike:pluginExtractExportNames',
16
16
  enforce: 'post',
17
- async transform(src, id, options) {
18
- id = normalizeId(id);
19
- const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
20
- if (extractExportNamesRE.test(id)) {
21
- const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
22
- debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
23
- return code;
24
- }
17
+ transform: {
18
+ async handler(src, id, options) {
19
+ id = normalizeId(id);
20
+ const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
21
+ if (extractExportNamesRE.test(id)) {
22
+ const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
23
+ debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
24
+ return code;
25
+ }
26
+ },
25
27
  },
26
- configureServer() {
27
- isDev = true;
28
+ configureServer: {
29
+ handler() {
30
+ isDev = true;
31
+ },
28
32
  },
29
- configResolved(config_) {
30
- config = config_;
33
+ configResolved: {
34
+ handler(config_) {
35
+ config = config_;
36
+ },
31
37
  },
32
- config() {
33
- if (debug.isActivated) {
34
- return { logLevel: 'silent' };
35
- }
38
+ config: {
39
+ handler() {
40
+ if (debug.isActivated) {
41
+ return { logLevel: 'silent' };
42
+ }
43
+ },
36
44
  },
37
45
  };
38
46
  }
@@ -13,68 +13,78 @@ function pluginFileEnv() {
13
13
  let viteDevServer;
14
14
  return {
15
15
  name: 'vike:pluginFileEnv',
16
- load(id, options) {
17
- // In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
18
- if (!viteDevServer)
19
- return;
20
- if (!isV1Design())
21
- return;
22
- if (skip(id))
23
- return;
24
- // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
25
- if (id.endsWith('?direct'))
26
- id = id.slice(0, -1 * '?direct'.length);
27
- const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
28
- assert(moduleInfo);
29
- const importers = Array.from(moduleInfo.importers)
30
- .map((m) => m.id)
31
- .filter((id) => id !== null);
32
- assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
33
- // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
34
- true);
16
+ load: {
17
+ handler(id, options) {
18
+ // In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
19
+ if (!viteDevServer)
20
+ return;
21
+ if (!isV1Design())
22
+ return;
23
+ if (skip(id))
24
+ return;
25
+ // For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
26
+ if (id.endsWith('?direct'))
27
+ id = id.slice(0, -1 * '?direct'.length);
28
+ const moduleInfo = viteDevServer.moduleGraph.getModuleById(id);
29
+ assert(moduleInfo);
30
+ const importers = Array.from(moduleInfo.importers)
31
+ .map((m) => m.id)
32
+ .filter((id) => id !== null);
33
+ assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
34
+ // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
35
+ true);
36
+ },
35
37
  },
36
38
  // In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
37
- async transform(code, id, options) {
38
- id = normalizeId(id);
39
- // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
40
- if (viteDevServer)
41
- return;
42
- if (skip(id))
43
- return;
44
- const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
45
- if (!isWrongEnv(id, isServerSide))
46
- return;
47
- const { importers } = this.getModuleInfo(id);
48
- // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
49
- const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
50
- // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
51
- const { exportNames } = await getExportNames(code);
52
- return rollupSourceMapRemove([
53
- `throw new Error(${JSON.stringify(errMsg)});`,
54
- ...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
55
- ].join('\n'));
56
- },
57
- generateBundle() {
58
- Array.from(this.getModuleIds())
59
- .filter((id) => !skip(id))
60
- .forEach((moduleId) => {
61
- const mod = this.getModuleInfo(moduleId);
62
- const { importers } = mod;
63
- if (importers.length === 0) {
64
- // Dynamic imports can only be verified at runtime
65
- /* This assertion can fail: https://github.com/vikejs/vike/issues/2227
66
- assert(dynamicImporters.length > 0)
67
- */
39
+ transform: {
40
+ async handler(code, id, options) {
41
+ id = normalizeId(id);
42
+ // In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
43
+ if (viteDevServer)
68
44
  return;
69
- }
70
- assertFileEnv(moduleId, isViteServerSide(config, this.environment), importers, false);
71
- });
45
+ if (skip(id))
46
+ return;
47
+ const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
48
+ if (!isWrongEnv(id, isServerSide))
49
+ return;
50
+ const { importers } = this.getModuleInfo(id);
51
+ // Throwing a verbose error doesn't waste client-side KBs as dynamic imports are code split.
52
+ const errMsg = getErrorMessage(id, isServerSide, importers, false, true);
53
+ // We have to inject empty exports to avoid Rollup complaining about missing exports, see https://gist.github.com/brillout/5ea45776e65bd65100a52ecd7bfda3ff
54
+ const { exportNames } = await getExportNames(code);
55
+ return rollupSourceMapRemove([
56
+ `throw new Error(${JSON.stringify(errMsg)});`,
57
+ ...exportNames.map((name) => name === 'default' ? 'export default undefined;' : `export const ${name} = undefined;`),
58
+ ].join('\n'));
59
+ },
60
+ },
61
+ generateBundle: {
62
+ handler() {
63
+ Array.from(this.getModuleIds())
64
+ .filter((id) => !skip(id))
65
+ .forEach((moduleId) => {
66
+ const mod = this.getModuleInfo(moduleId);
67
+ const { importers } = mod;
68
+ if (importers.length === 0) {
69
+ // Dynamic imports can only be verified at runtime
70
+ /* This assertion can fail: https://github.com/vikejs/vike/issues/2227
71
+ assert(dynamicImporters.length > 0)
72
+ */
73
+ return;
74
+ }
75
+ assertFileEnv(moduleId, isViteServerSide(config, this.environment), importers, false);
76
+ });
77
+ },
72
78
  },
73
- configResolved(config_) {
74
- config = config_;
79
+ configResolved: {
80
+ handler(config_) {
81
+ config = config_;
82
+ },
75
83
  },
76
- configureServer(viteDevServer_) {
77
- viteDevServer = viteDevServer_;
84
+ configureServer: {
85
+ handler(viteDevServer_) {
86
+ viteDevServer = viteDevServer_;
87
+ },
78
88
  },
79
89
  };
80
90
  function assertFileEnv(moduleId, isServerSide, importers, onlyWarn) {
@@ -23,27 +23,34 @@ function pluginNonRunnableDev() {
23
23
  let config;
24
24
  return {
25
25
  name: 'vike:pluginNonRunnableDev',
26
- configureServer(viteDevServer) {
27
- createViteRPC(viteDevServer, getViteRpcFunctions);
26
+ configureServer: {
27
+ handler(viteDevServer) {
28
+ createViteRPC(viteDevServer, getViteRpcFunctions);
29
+ },
28
30
  },
29
- configResolved(config_) {
30
- config = config_;
31
+ configResolved: {
32
+ handler(config_) {
33
+ config = config_;
34
+ },
31
35
  },
32
- transform(code, id) {
33
- if (!config._isDev)
34
- return;
35
- if (id !== distFileIsNonRunnableDev && id !== distFileGlobalContext)
36
- return;
37
- if (isRunnableDevEnvironment(this.environment))
38
- return;
39
- const { magicString, getMagicStringResult } = getMagicString(code, id);
40
- if (id === distFileIsNonRunnableDev) {
41
- magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
42
- }
43
- if (id === distFileGlobalContext) {
44
- magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
45
- }
46
- return getMagicStringResult();
36
+ transform: {
37
+ handler(code, id) {
38
+ if (!config._isDev)
39
+ return;
40
+ const idWithoutQuery = id.split('?')[0];
41
+ if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
42
+ return;
43
+ if (isRunnableDevEnvironment(this.environment))
44
+ return;
45
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
46
+ if (idWithoutQuery === distFileIsNonRunnableDev) {
47
+ magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(true));
48
+ }
49
+ if (idWithoutQuery === distFileGlobalContext) {
50
+ magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
51
+ }
52
+ return getMagicStringResult();
53
+ },
47
54
  },
48
55
  };
49
56
  }
@@ -14,32 +14,38 @@ function pluginPreview() {
14
14
  return {
15
15
  name: 'vike:pluginPreview',
16
16
  apply: applyPreview,
17
- config() {
18
- return {
19
- appType: 'custom',
20
- };
17
+ config: {
18
+ handler() {
19
+ return {
20
+ appType: 'custom',
21
+ };
22
+ },
21
23
  },
22
- async configResolved(config_) {
23
- config = config_;
24
- vikeConfig = await getVikeConfigInternal();
25
- logDockerHint(config.preview.host);
26
- // vikeConfig = await getVikeConfig(config)
24
+ configResolved: {
25
+ async handler(config_) {
26
+ config = config_;
27
+ vikeConfig = await getVikeConfigInternal();
28
+ logDockerHint(config.preview.host);
29
+ // vikeConfig = await getVikeConfig(config)
30
+ },
27
31
  },
28
- configurePreviewServer(server) {
29
- /* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
30
- - This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
31
- config.appType = 'mpa'
32
- */
33
- return () => {
34
- const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = vikeConfig.prerenderContext;
35
- assertDist(isPrerenderingEnabledForAllPages);
36
- // We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
37
- addStaticAssetsMiddleware(server.middlewares);
38
- if (!isPrerenderingEnabledForAllPages) {
39
- addSsrMiddleware(server.middlewares, config, true, isPrerenderingEnabled);
40
- }
41
- addStatic404Middleware(server.middlewares);
42
- };
32
+ configurePreviewServer: {
33
+ handler(server) {
34
+ /* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
35
+ - This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
36
+ config.appType = 'mpa'
37
+ */
38
+ return () => {
39
+ const { isPrerenderingEnabledForAllPages, isPrerenderingEnabled } = vikeConfig.prerenderContext;
40
+ assertDist(isPrerenderingEnabledForAllPages);
41
+ // We cannot re-use Vite's static middleware: https://github.com/vitejs/vite/pull/14836#issuecomment-1788540300
42
+ addStaticAssetsMiddleware(server.middlewares);
43
+ if (!isPrerenderingEnabledForAllPages) {
44
+ addSsrMiddleware(server.middlewares, config, true, isPrerenderingEnabled);
45
+ }
46
+ addStatic404Middleware(server.middlewares);
47
+ };
48
+ },
43
49
  },
44
50
  };
45
51
  function assertDist(isPrerenderingEnabledForAllPages) {
@@ -9,41 +9,49 @@ function pluginReplaceConstants() {
9
9
  name: 'vike:pluginReplaceConstants',
10
10
  enforce: 'post',
11
11
  apply: 'build',
12
- configResolved(config_) {
13
- config = config_;
12
+ configResolved: {
13
+ handler(config_) {
14
+ config = config_;
15
+ },
14
16
  },
15
- transform(code, id, options) {
16
- id = normalizeId(id);
17
- assertPosixPath(id);
18
- if (id.includes('/node_modules/'))
19
- return;
20
- assertPosixPath(config.root);
21
- if (!id.startsWith(config.root))
22
- return;
23
- if (!code.includes('import.meta.env.'))
24
- return;
25
- const isBuild = config.command === 'build';
26
- assert(isBuild);
27
- // Used by vike.dev
28
- // https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
29
- // @ts-expect-error
30
- if (config._skipVikeReplaceConstants?.(id))
31
- return;
32
- const { magicString, getMagicStringResult } = getMagicString(code, id);
33
- const constantsMap = [];
34
- constantsMap.push({
35
- constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
36
- replacement: !isViteServerSide_extraSafe(config, this.environment, options),
37
- });
38
- constantsMap.forEach(({ constants, replacement }) => {
39
- if (!constants.some((c) => code.includes(c)))
17
+ transform: {
18
+ handler(code, id, options) {
19
+ id = normalizeId(id);
20
+ assertPosixPath(id);
21
+ if (id.includes('/node_modules/'))
40
22
  return;
41
- const regExp = getConstantRegExp(constants);
42
- magicString.replaceAll(regExp, JSON.stringify(replacement));
43
- });
44
- if (!magicString.hasChanged())
45
- return null;
46
- return getMagicStringResult();
23
+ assertPosixPath(config.root);
24
+ if (!id.startsWith(config.root))
25
+ return;
26
+ if (!code.includes('import.meta.env.'))
27
+ return;
28
+ const isBuild = config.command === 'build';
29
+ assert(isBuild);
30
+ // Used by vike.dev
31
+ // https://github.com/vikejs/vike/blob/08a1ff55c80ddca64ca6d4417fefd45fefeb4ffb/docs/vite.config.ts#L12
32
+ // @ts-expect-error
33
+ if (config._skipVikeReplaceConstants?.(id))
34
+ return;
35
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
36
+ const constantsMap = [];
37
+ constantsMap.push({
38
+ constants: [
39
+ 'pageContext.isClientSide',
40
+ 'globalContext.isClientSide',
41
+ 'pageContext.globalContext.isClientSide',
42
+ ],
43
+ replacement: !isViteServerSide_extraSafe(config, this.environment, options),
44
+ });
45
+ constantsMap.forEach(({ constants, replacement }) => {
46
+ if (!constants.some((c) => code.includes(c)))
47
+ return;
48
+ const regExp = getConstantRegExp(constants);
49
+ magicString.replaceAll(regExp, JSON.stringify(replacement));
50
+ });
51
+ if (!magicString.hasChanged())
52
+ return null;
53
+ return getMagicStringResult();
54
+ },
47
55
  },
48
56
  };
49
57
  }
@@ -20,8 +20,10 @@ function pluginSetGlobalContext() {
20
20
  markSetup_viteDevServer();
21
21
  },
22
22
  },
23
- configurePreviewServer() {
24
- markSetup_vitePreviewServer();
23
+ configurePreviewServer: {
24
+ handler() {
25
+ markSetup_vitePreviewServer();
26
+ },
25
27
  },
26
28
  config: {
27
29
  order: 'pre',