vike 0.4.236-commit-08fbc10 → 0.4.236-commit-79f1ef0

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 (76) hide show
  1. package/dist/cjs/client/shared/createGetGlobalContextClient.js +20 -10
  2. package/dist/cjs/client/shared/utils.js +1 -0
  3. package/dist/cjs/node/runtime/globalContext.js +104 -20
  4. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
  5. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +3 -1
  6. package/dist/cjs/node/runtime/utils.js +3 -0
  7. package/dist/cjs/node/vite/index.js +2 -0
  8. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
  9. package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
  10. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -3
  11. package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
  12. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +10 -8
  13. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
  14. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
  15. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +51 -0
  16. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
  17. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
  18. package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
  19. package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
  20. package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
  21. package/dist/cjs/shared/createGlobalContextShared.js +5 -1
  22. package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
  23. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  24. package/dist/cjs/utils/assertSetup.js +2 -0
  25. package/dist/cjs/utils/debug.js +1 -0
  26. package/dist/cjs/utils/getViteRPC.js +79 -0
  27. package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
  28. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
  29. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
  30. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
  31. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
  32. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
  33. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
  34. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
  35. package/dist/esm/client/shared/createGetGlobalContextClient.js +20 -10
  36. package/dist/esm/client/shared/utils.d.ts +1 -0
  37. package/dist/esm/client/shared/utils.js +1 -0
  38. package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
  39. package/dist/esm/node/runtime/globalContext.d.ts +32 -52
  40. package/dist/esm/node/runtime/globalContext.js +105 -21
  41. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
  42. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -33
  43. package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -2
  44. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +20 -66
  45. package/dist/esm/node/runtime/renderPage.d.ts +10 -33
  46. package/dist/esm/node/runtime/utils.d.ts +3 -0
  47. package/dist/esm/node/runtime/utils.js +3 -0
  48. package/dist/esm/node/vite/index.js +2 -0
  49. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
  50. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
  51. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
  52. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
  53. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -2
  54. package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
  55. package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
  56. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +10 -8
  57. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
  58. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +49 -0
  59. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
  60. package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
  61. package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
  62. package/dist/esm/node/vite/shared/getMagicString.js +13 -0
  63. package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
  64. package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
  65. package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
  66. package/dist/esm/shared/createGlobalContextShared.js +5 -1
  67. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  68. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  69. package/dist/esm/utils/assertSetup.js +2 -0
  70. package/dist/esm/utils/debug.d.ts +1 -1
  71. package/dist/esm/utils/debug.js +1 -0
  72. package/dist/esm/utils/getViteRPC.d.ts +6 -0
  73. package/dist/esm/utils/getViteRPC.js +77 -0
  74. package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
  75. package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
  76. package/package.json +11 -2
@@ -46,24 +46,12 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
46
46
  pages: {
47
47
  [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
48
48
  };
49
- } & ({
49
+ } & (({
50
50
  _isProduction: false;
51
51
  _isPrerendering: false;
52
52
  assetsManifest: null;
53
- _viteDevServer: import("vite").ViteDevServer;
54
- viteConfig: import("vite").ResolvedConfig;
55
- viteConfigRuntime: {
56
- root: string;
57
- build: {
58
- outDir: string;
59
- };
60
- _baseViteOriginal: string;
61
- vitePluginServerEntry: {
62
- inject: boolean | undefined;
63
- };
64
- };
65
- baseServer: string;
66
- baseAssets: string;
53
+ _viteDevServer: import("vite").ViteDevServer | undefined;
54
+ viteConfig: import("vite").ResolvedConfig | undefined;
67
55
  isClientSide: false;
68
56
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
69
57
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
@@ -73,19 +61,7 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
73
61
  _isProduction: true;
74
62
  assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
75
63
  _viteDevServer: null;
76
- viteConfigRuntime: {
77
- root: string;
78
- build: {
79
- outDir: string;
80
- };
81
- _baseViteOriginal: string;
82
- vitePluginServerEntry: {
83
- inject: boolean | undefined;
84
- };
85
- };
86
64
  _usesClientRouter: boolean;
87
- baseServer: string;
88
- baseAssets: string;
89
65
  isClientSide: false;
90
66
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
91
67
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
@@ -95,6 +71,13 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
95
71
  _isProduction: true;
96
72
  assetsManifest: import("../../types/ViteManifest.js").ViteManifest;
97
73
  _viteDevServer: null;
74
+ _usesClientRouter: boolean;
75
+ isClientSide: false;
76
+ _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
77
+ _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
78
+ }) & {
79
+ baseServer: string;
80
+ baseAssets: string;
98
81
  viteConfigRuntime: {
99
82
  root: string;
100
83
  build: {
@@ -105,12 +88,6 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
105
88
  inject: boolean | undefined;
106
89
  };
107
90
  };
108
- _usesClientRouter: boolean;
109
- baseServer: string;
110
- baseAssets: string;
111
- isClientSide: false;
112
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
113
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
114
91
  });
115
92
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
116
93
  _baseServer: string;
@@ -57,3 +57,6 @@ export * from '../../utils/PROJECT_VERSION.js';
57
57
  export * from '../../utils/genPromise.js';
58
58
  export * from '../../utils/augmentType.js';
59
59
  export * from '../../utils/changeEnumerable.js';
60
+ export * from '../../utils/getViteRPC.js';
61
+ export * from '../../utils/isRunnableDevEnvironment.js';
62
+ export * from '../../utils/assertIsNotBrowser.js';
@@ -61,3 +61,6 @@ export * from '../../utils/PROJECT_VERSION.js';
61
61
  export * from '../../utils/genPromise.js';
62
62
  export * from '../../utils/augmentType.js';
63
63
  export * from '../../utils/changeEnumerable.js';
64
+ export * from '../../utils/getViteRPC.js';
65
+ export * from '../../utils/isRunnableDevEnvironment.js';
66
+ export * from '../../utils/assertIsNotBrowser.js';
@@ -22,6 +22,7 @@ import { resolveClientEntriesDev } from './shared/resolveClientEntriesDev.js';
22
22
  import { pluginWorkaroundCssModuleHmr } from './plugins/pluginWorkaroundCssModuleHmr.js';
23
23
  import { pluginWorkaroundVite6HmrRegression } from './plugins/pluginWorkaroundVite6HmrRegression.js';
24
24
  import { pluginReplaceConstants } from './plugins/pluginReplaceConstants.js';
25
+ import { pluginNonRunnableDev } from './plugins/pluginNonRunnableDev.js';
25
26
  // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
26
27
  setResolveClientEntriesDev(resolveClientEntriesDev);
27
28
  // Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
@@ -41,6 +42,7 @@ function plugin(vikeVitePluginOptions = {}) {
41
42
  pluginWorkaroundCssModuleHmr(),
42
43
  pluginWorkaroundVite6HmrRegression(),
43
44
  pluginReplaceConstants(),
45
+ pluginNonRunnableDev(),
44
46
  ];
45
47
  Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
46
48
  return plugins;
@@ -11,7 +11,7 @@ declare function handleAssetsManifest_assertUsageCssTarget(config: ResolvedConfi
11
11
  declare function handleAssetsManifest_getBuildConfig(config: UserConfig): Promise<{
12
12
  readonly ssrEmitAssets: true | undefined;
13
13
  readonly cssMinify: "esbuild" | undefined;
14
- readonly manifest: "_temp_manifest.json";
14
+ readonly manifest: true;
15
15
  readonly copyPublicDir: boolean | undefined;
16
16
  }>;
17
17
  declare function handleAssetsManifest(config: ResolvedConfig, viteEnv: Environment | undefined, options: {
@@ -9,13 +9,13 @@ import path from 'node:path';
9
9
  import { existsSync } from 'node:fs';
10
10
  import { assert, assertIsSingleModuleInstance, assertWarning, isEqualStringList, isObject, pLimit, unique, } from '../../utils.js';
11
11
  import { isVirtualFileIdPageConfigLazy } from '../../../shared/virtualFiles/virtualFilePageConfigLazy.js';
12
- import { manifestTempFile } from './pluginBuildConfig.js';
13
12
  import { getAssetsDir } from '../../shared/getAssetsDir.js';
14
13
  import pc from '@brillout/picocolors';
15
14
  import { getVikeConfigInternal, isV1Design } from '../../shared/resolveVikeConfigInternal.js';
16
15
  import { getOutDirs } from '../../shared/getOutDirs.js';
17
16
  import { isViteServerBuild_onlySsrEnv, isViteServerBuild } from '../../shared/isViteServerBuild.js';
18
17
  import { set_macro_ASSETS_MANIFEST } from './pluginBuildEntry.js';
18
+ import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
19
19
  assertIsSingleModuleInstance('build/handleAssetsManifest.ts');
20
20
  let assetsJsonFilePath;
21
21
  // true => use workaround config.build.ssrEmitAssets
@@ -26,9 +26,8 @@ function handleAssetsManifest_isFixEnabled(config) {
26
26
  }
27
27
  /** https://github.com/vikejs/vike/issues/1339 */
28
28
  async function fixServerAssets(config) {
29
- const outDirs = getOutDirs(config);
30
- const clientManifest = await readManifestFile(outDirs.outDirClient);
31
- const serverManifest = await readManifestFile(outDirs.outDirServer);
29
+ const clientManifest = await readManifestFile(config, true);
30
+ const serverManifest = await readManifestFile(config, false);
32
31
  const { clientManifestMod, serverManifestMod, filesToMove, filesToRemove } = addServerAssets(clientManifest, serverManifest);
33
32
  await copyAssets(filesToMove, filesToRemove, config);
34
33
  return { clientManifestMod, serverManifestMod };
@@ -265,8 +264,8 @@ function removeEmptyDirectories(dirPath) {
265
264
  fs_sync.rmdirSync(dirPath);
266
265
  }
267
266
  }
268
- async function readManifestFile(outDir) {
269
- const manifestFilePath = path.posix.join(outDir, manifestTempFile);
267
+ async function readManifestFile(config, client) {
268
+ const manifestFilePath = getManifestFilePath(config, client);
270
269
  const manifestFileContent = await fs.readFile(manifestFilePath, 'utf-8');
271
270
  assert(manifestFileContent);
272
271
  const manifest = JSON.parse(manifestFileContent);
@@ -287,7 +286,7 @@ async function handleAssetsManifest_getBuildConfig(config) {
287
286
  ssrEmitAssets: isFixEnabled ? true : undefined,
288
287
  // Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
289
288
  cssMinify: isFixEnabled ? 'esbuild' : undefined,
290
- manifest: manifestTempFile,
289
+ manifest: true,
291
290
  copyPublicDir: vikeConfig.config.vite6BuilderApp
292
291
  ? // Already set by vike:build:pluginBuildApp
293
292
  undefined
@@ -300,7 +299,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
300
299
  assert(!assetsJsonFilePath);
301
300
  const outDirs = getOutDirs(config, viteEnv);
302
301
  assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
303
- await writeAssetsManifestFile(outDirs, assetsJsonFilePath, config);
302
+ await writeAssetsManifestFile(assetsJsonFilePath, config);
304
303
  }
305
304
  if (isViteServerBuild(config, viteEnv)) {
306
305
  const outDir = options.dir;
@@ -314,10 +313,10 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
314
313
  assert(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
315
314
  }
316
315
  }
317
- async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
316
+ async function writeAssetsManifestFile(assetsJsonFilePath, config) {
318
317
  const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
319
- const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
320
- const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
318
+ const clientManifestFilePath = getManifestFilePath(config, true);
319
+ const serverManifestFilePath = getManifestFilePath(config, false);
321
320
  if (!isFixEnabled) {
322
321
  await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
323
322
  }
@@ -328,3 +327,12 @@ async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
328
327
  await fs.rm(clientManifestFilePath);
329
328
  await fs.rm(serverManifestFilePath);
330
329
  }
330
+ function getManifestFilePath(config, client) {
331
+ const outDirs = getOutDirs(config);
332
+ const outDir = client ? outDirs.outDirClient : outDirs.outDirServer;
333
+ const env = client ? config.environments.client : config.environments.ssr;
334
+ assert(env);
335
+ const manifestFilePathRelative = getManifestFilePathRelative(env.build.manifest);
336
+ const manifestFilePath = path.posix.join(outDir, manifestFilePathRelative);
337
+ return manifestFilePath;
338
+ }
@@ -6,12 +6,12 @@ import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/c
6
6
  import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
9
- import { manifestTempFile } from './pluginBuildConfig.js';
10
9
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
11
10
  import { isVikeCliOrApi } from '../../../api/context.js';
12
11
  import { handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget } from './handleAssetsManifest.js';
13
12
  import { isViteClientBuild, isViteServerBuild_onlySsrEnv } from '../../shared/isViteServerBuild.js';
14
13
  import { runPrerender_forceExit, runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
14
+ import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
15
15
  assertIsSingleModuleInstance('build/pluginAutoFullBuild.ts');
16
16
  let forceExit = false;
17
17
  function pluginAutoFullBuild() {
@@ -82,7 +82,7 @@ async function triggerFullBuild(config, viteEnv, bundle) {
82
82
  // - The legacy plugin triggers its own Rollup build for the client-side.
83
83
  // - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
84
84
  // - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
85
- if (!bundle[manifestTempFile])
85
+ if (!bundle[getManifestFilePathRelative(config.build.manifest)])
86
86
  return;
87
87
  const configInline = getFullBuildInlineConfig(config);
88
88
  if (!isBuilderApp) {
@@ -1,10 +1,8 @@
1
1
  export { pluginBuildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
- export { manifestTempFile };
5
4
  import type { ResolvedConfig, Plugin } from 'vite';
6
5
  import type { PageConfigBuildTime } from '../../../../types/PageConfig.js';
7
- declare const manifestTempFile = "_temp_manifest.json";
8
6
  declare function pluginBuildConfig(): Plugin[];
9
7
  declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config: ResolvedConfig): {
10
8
  hasClientRouting: boolean;
@@ -1,7 +1,6 @@
1
1
  export { pluginBuildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
- export { manifestTempFile };
5
4
  import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveVikeDistFile, } from '../../utils.js';
6
5
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
7
6
  import { findPageFiles } from '../../shared/findPageFiles.js';
@@ -14,7 +13,6 @@ import { isViteServerBuild } from '../../shared/isViteServerBuild.js';
14
13
  import { resolveOutDir } from '../../shared/getOutDirs.js';
15
14
  import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
16
15
  import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets.js';
17
- const manifestTempFile = '_temp_manifest.json';
18
16
  function pluginBuildConfig() {
19
17
  let config;
20
18
  return [
@@ -10,4 +10,7 @@ declare module 'vite' {
10
10
  _viteConfigFromUserEnhanced?: InlineConfig;
11
11
  }
12
12
  }
13
+ declare global {
14
+ var __VIKE__IS_PROCESS_SHARED_WITH_VITE: undefined | true;
15
+ }
13
16
  declare function pluginCommon(vikeVitePluginOptions: unknown): Plugin[];
@@ -11,6 +11,7 @@ import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVi
11
11
  import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
12
12
  import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
13
13
  const pluginName = 'vike:pluginCommon';
14
+ globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
14
15
  function pluginCommon(vikeVitePluginOptions) {
15
16
  return [
16
17
  {
@@ -12,21 +12,23 @@ async function determineOptimizeDeps(config) {
12
12
  const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
13
13
  config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
14
14
  config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
15
- // TO-DO/eventually: use a check that is agnostic to @cloudflare/vite-plugin
16
- const isNotRunnable = config.environments?.ssr?.resolve.conditions.includes('workerd');
17
- if (isNotRunnable) {
18
- config.ssr.optimizeDeps.include = add(config.ssr.optimizeDeps.include, includeServer);
19
- // @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
20
- config.ssr.optimizeDeps.entries = add(config.ssr.optimizeDeps.entries, entriesServer);
15
+ // Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
16
+ // - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
17
+ includeServer.push('react/jsx-dev-runtime');
18
+ for (const envName in config.environments) {
19
+ const env = config.environments[envName];
20
+ if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
21
+ env.optimizeDeps.include = add(env.optimizeDeps.include, includeServer);
22
+ env.optimizeDeps.entries = add(env.optimizeDeps.entries, entriesServer);
23
+ }
21
24
  }
22
25
  if (debug.isActivated)
23
26
  debug('optimizeDeps', {
24
27
  'config.optimizeDeps.entries': config.optimizeDeps.entries,
25
28
  'config.optimizeDeps.include': config.optimizeDeps.include,
26
29
  'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
27
- /* Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
30
+ // @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
28
31
  'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
29
- //*/
30
32
  'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
31
33
  'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
32
34
  });
@@ -0,0 +1,26 @@
1
+ export { pluginNonRunnableDev };
2
+ import type { Plugin, ViteDevServer } from 'vite';
3
+ import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
4
+ export type ViteRPC = ReturnType<typeof getViteRpcFunctions>;
5
+ declare function getViteRpcFunctions(viteDevServer: ViteDevServer): {
6
+ transformIndexHtmlRPC(html: string): Promise<string>;
7
+ retrievePageAssetsDevRPC(clientDependencies: ClientDependency[], clientEntries: string[]): Promise<{
8
+ clientEntriesSrc: string[];
9
+ assetUrls: string[];
10
+ }>;
11
+ getViteConfigRuntimeRPC(): Promise<{
12
+ root: string;
13
+ build: {
14
+ outDir: string;
15
+ };
16
+ _baseViteOriginal: string;
17
+ vitePluginServerEntry: {
18
+ inject: boolean | undefined;
19
+ };
20
+ }>;
21
+ };
22
+ declare global {
23
+ var __VIKE__DYNAMIC_IMPORT: (module: string) => Promise<Record<string, unknown>>;
24
+ var __VIKE__IS_NON_RUNNABLE_DEV: undefined | boolean;
25
+ }
26
+ declare function pluginNonRunnableDev(): Plugin;
@@ -0,0 +1,49 @@
1
+ export { pluginNonRunnableDev };
2
+ import { createViteRPC, assertIsNotProductionRuntime, requireResolveVikeDistFile, isRunnableDevEnvironment, } from '../utils.js';
3
+ import { resolveClientEntriesDev } from '../shared/resolveClientEntriesDev.js';
4
+ import { retrieveAssetsDev } from '../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js';
5
+ import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
6
+ import { getMagicString } from '../shared/getMagicString.js';
7
+ assertIsNotProductionRuntime();
8
+ function getViteRpcFunctions(viteDevServer) {
9
+ return {
10
+ async transformIndexHtmlRPC(html) {
11
+ return await viteDevServer.transformIndexHtml('/', html);
12
+ },
13
+ // TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
14
+ async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
15
+ const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer));
16
+ const assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
17
+ return { clientEntriesSrc, assetUrls };
18
+ },
19
+ async getViteConfigRuntimeRPC() {
20
+ return getViteConfigRuntime(viteDevServer.config);
21
+ },
22
+ };
23
+ }
24
+ function pluginNonRunnableDev() {
25
+ const runtimeGlobalContextFilePath = requireResolveVikeDistFile('dist/esm/node/runtime/globalContext.js');
26
+ let config;
27
+ return {
28
+ name: 'vike:pluginNonRunnableDev',
29
+ configureServer(viteDevServer) {
30
+ createViteRPC(viteDevServer, getViteRpcFunctions);
31
+ },
32
+ configResolved(config_) {
33
+ config = config_;
34
+ },
35
+ transform(code, id) {
36
+ if (!config._isDev)
37
+ return;
38
+ if (id !== runtimeGlobalContextFilePath)
39
+ return;
40
+ const isNonRunnableDev = !isRunnableDevEnvironment(this.environment);
41
+ const { magicString, getMagicStringResult } = getMagicString(code, id);
42
+ if (isNonRunnableDev) {
43
+ magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
44
+ }
45
+ magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
46
+ return getMagicStringResult();
47
+ },
48
+ };
49
+ }
@@ -19,6 +19,10 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
19
19
  lines.push('export const pageConfigGlobalSerialized = {');
20
20
  lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
21
21
  lines.push('};');
22
+ if (!isForClientSide && isDev) {
23
+ // https://vite.dev/guide/api-environment-frameworks.html
24
+ lines.push('if (import.meta.hot) import.meta.hot.accept();');
25
+ }
22
26
  const code = [...importStatements, ...lines].join('\n');
23
27
  debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
24
28
  return code;
@@ -1,4 +1,5 @@
1
1
  export { applyRegExpWithMagicString };
2
+ // TODO/now: replace with .replaceAll() ?
2
3
  function applyRegExpWithMagicString(magicString, regExp, replacement) {
3
4
  const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
4
5
  let match;
@@ -0,0 +1,9 @@
1
+ export { getMagicString };
2
+ import MagicString from 'magic-string';
3
+ declare function getMagicString(code: string, id: string): {
4
+ magicString: MagicString;
5
+ getMagicStringResult: () => {
6
+ code: string;
7
+ map: import("magic-string").SourceMap;
8
+ };
9
+ };
@@ -0,0 +1,13 @@
1
+ export { getMagicString };
2
+ import MagicString from 'magic-string';
3
+ // TODO/now use everywhere
4
+ function getMagicString(code, id) {
5
+ const magicString = new MagicString(code);
6
+ const getMagicStringResult = () => {
7
+ return {
8
+ code: magicString.toString(),
9
+ map: magicString.generateMap({ hires: true, source: id }),
10
+ };
11
+ };
12
+ return { magicString, getMagicStringResult };
13
+ }
@@ -0,0 +1,2 @@
1
+ export { getManifestFilePathRelative };
2
+ declare function getManifestFilePathRelative(manifestConfig: string | boolean): string;
@@ -0,0 +1,8 @@
1
+ export { getManifestFilePathRelative };
2
+ import { assert } from '../utils.js';
3
+ function getManifestFilePathRelative(manifestConfig) {
4
+ assert(['string', 'boolean'].includes(typeof manifestConfig));
5
+ assert(manifestConfig !== false);
6
+ const manifestFileRelative = typeof manifestConfig === 'string' ? manifestConfig : '.vite/manifest.json';
7
+ return manifestFileRelative;
8
+ }
@@ -9,10 +9,10 @@ import type { GlobalContextServerInternal } from '../node/runtime/globalContext.
9
9
  import type { GlobalContextClientInternal } from '../client/runtime-client-routing/globalContext.js';
10
10
  import { type Hook } from './hooks/getHook.js';
11
11
  declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
12
- declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
12
+ declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>, GlobalContextAddedAsync extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
13
13
  globalContext?: Record<string, unknown>;
14
14
  onCreateGlobalContextHooks?: Hook[];
15
- }, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>): Promise<{
15
+ }, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>, addGlobalContextAsync?: (globalContext: GlobalContextBase) => Promise<GlobalContextAddedAsync>): Promise<{
16
16
  /**
17
17
  * Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
18
18
  *
@@ -35,7 +35,7 @@ declare function createGlobalContextShared<GlobalContextAdded extends Record<str
35
35
  pages: {
36
36
  [k: string]: import("./page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
37
37
  };
38
- } & GlobalContextAdded>;
38
+ } & GlobalContextAdded & GlobalContextAddedAsync>;
39
39
  type GlobalContextBasePublic = Pick<GlobalContextBase, 'config' | 'pages' | 'isGlobalContext'>;
40
40
  type GlobalContextBase = ReturnType<typeof createGlobalContextBase>;
41
41
  declare function createGlobalContextBase(virtualFileExports: unknown): {
@@ -9,7 +9,7 @@ import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
9
9
  const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
10
10
  async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
11
11
  // TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
12
- addGlobalContextTmp) {
12
+ addGlobalContextTmp, addGlobalContextAsync) {
13
13
  const globalContext = createGlobalContextBase(virtualFileExports);
14
14
  let isNewGlobalContext;
15
15
  if (!globalObject.globalContext) {
@@ -31,6 +31,10 @@ addGlobalContextTmp) {
31
31
  const globalContextAdded = await addGlobalContextTmp?.(globalContext);
32
32
  objectAssign(globalContext, globalContextAdded);
33
33
  }
34
+ {
35
+ const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
36
+ objectAssign(globalContext, globalContextAddedAsync);
37
+ }
34
38
  const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
35
39
  let hooksCalled = false;
36
40
  if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.236-commit-08fbc10";
1
+ export declare const PROJECT_VERSION: "0.4.236-commit-79f1ef0";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.236-commit-08fbc10';
2
+ export const PROJECT_VERSION = '0.4.236-commit-79f1ef0';
@@ -24,6 +24,8 @@ function assertIsNotProductionRuntime() {
24
24
  setup.shouldNotBeProduction = true;
25
25
  }
26
26
  function onSetupRuntime() {
27
+ if (true)
28
+ return; // TODO/now refactor this
27
29
  if (debug.isActivated)
28
30
  debug('assertSetup()', new Error().stack);
29
31
  if (isTest())
@@ -1,7 +1,7 @@
1
1
  export { createDebugger };
2
2
  export { isDebugActivated };
3
3
  export type { Debug };
4
- declare const flags: readonly ["vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles"];
4
+ declare const flags: readonly ["vike:crawl", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:resolve", "vike:routing", "vike:setup", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
5
5
  type Flag = (typeof flags)[number];
6
6
  type Debug = ReturnType<typeof createDebugger>;
7
7
  type Options = {
@@ -30,6 +30,7 @@ const flags = [
30
30
  'vike:setup',
31
31
  'vike:stream',
32
32
  'vike:virtualFiles',
33
+ 'vike:vite-rpc',
33
34
  ];
34
35
  const flagsSkipWildcard = ['vike:log'];
35
36
  const flagRegex = /\bvike:[a-zA-Z-]+/g;
@@ -0,0 +1,6 @@
1
+ export { getViteRPC };
2
+ export { createViteRPC };
3
+ import type { ViteDevServer } from 'vite';
4
+ declare function getViteRPC<RpcFunctions>(): RpcFunctions;
5
+ type AsyncFunction = (...args: any[]) => Promise<unknown>;
6
+ declare function createViteRPC(viteDevServer: ViteDevServer, getRpcFunctions: (viteDevServer: ViteDevServer) => Record<string, AsyncFunction>): void;
@@ -0,0 +1,77 @@
1
+ export { getViteRPC }; // consumer (aka RPC client)
2
+ export { createViteRPC }; // provider (aka RPC server)
3
+ import { assert } from './assert.js';
4
+ import { genPromise } from './genPromise.js';
5
+ import { getRandomId } from './getRandomId.js';
6
+ import { getGlobalObject } from './getGlobalObject.js';
7
+ import { createDebugger } from './debug.js';
8
+ import { assertIsNotBrowser } from './assertIsNotBrowser.js';
9
+ assertIsNotBrowser();
10
+ const globalObject = getGlobalObject('utils/getViteRPC.ts', {
11
+ rpc: null,
12
+ });
13
+ const debug = createDebugger('vike:vite-rpc');
14
+ function getViteRPC() {
15
+ globalObject.rpc ?? (globalObject.rpc = createRpcClient());
16
+ return globalObject.rpc;
17
+ }
18
+ function createRpcClient() {
19
+ // @ts-ignore CJS build doesn't support import.meta — TO-DO/eventually: let's remove this ts-ignore after we removed the CJS build
20
+ const hot = import.meta.hot;
21
+ assert(hot);
22
+ const listeners = [];
23
+ hot.on(`vike:rpc:response`, (dataResponse) => {
24
+ if (debug.isActivated)
25
+ debug('Response received', dataResponse);
26
+ const { callId, functionReturn } = dataResponse;
27
+ listeners.forEach((l) => {
28
+ if (callId !== l.callId)
29
+ return;
30
+ l.cb(functionReturn);
31
+ listeners.splice(listeners.indexOf(l), 1);
32
+ });
33
+ });
34
+ const rpc = new Proxy({}, {
35
+ get(_, functionName) {
36
+ return async (...functionArgs) => {
37
+ // @ts-ignore CJS build doesn't support import.meta — TO-DO/eventually: let's remove this ts-ignore after we removed the CJS build
38
+ const hot = import.meta.hot;
39
+ assert(hot);
40
+ const callId = getRandomId();
41
+ const { promise, resolve } = genPromise({ timeout: 3 * 1000 });
42
+ listeners.push({
43
+ callId,
44
+ cb: (functionReturn) => {
45
+ resolve(functionReturn);
46
+ },
47
+ });
48
+ const dataRequest = { callId, functionName, functionArgs };
49
+ if (debug.isActivated)
50
+ debug('Request sent', dataRequest);
51
+ // Vite's type is wrong: import.meta.hot.send() does seem to return a promise
52
+ await hot.send('vike:rpc:request', dataRequest);
53
+ const functionReturn = await promise;
54
+ return functionReturn;
55
+ };
56
+ },
57
+ });
58
+ return rpc;
59
+ }
60
+ function createViteRPC(viteDevServer, getRpcFunctions) {
61
+ const rpcFunctions = getRpcFunctions(viteDevServer);
62
+ const { environments } = viteDevServer;
63
+ for (const envName in environments) {
64
+ debug('Listening to environment', envName);
65
+ const env = environments[envName];
66
+ env.hot.on('vike:rpc:request', async (dataRequest) => {
67
+ if (debug.isActivated)
68
+ debug('Request received', dataRequest);
69
+ const { callId, functionName, functionArgs } = dataRequest;
70
+ const functionReturn = await rpcFunctions[functionName](...functionArgs);
71
+ const dataResponse = { callId, functionReturn };
72
+ if (debug.isActivated)
73
+ debug('Response sent', dataResponse);
74
+ env.hot.send('vike:rpc:response', dataResponse);
75
+ });
76
+ }
77
+ }
@@ -0,0 +1,3 @@
1
+ export { isRunnableDevEnvironment };
2
+ import type { Environment, RunnableDevEnvironment } from 'vite';
3
+ declare function isRunnableDevEnvironment(environment: Environment | undefined): environment is RunnableDevEnvironment;
@@ -0,0 +1,7 @@
1
+ export { isRunnableDevEnvironment };
2
+ // We use this instead of `import { isRunnableDevEnvironment } from 'vite'` because:
3
+ // - Vite's isRunnableDevEnvironment() isn't reliable in monorepos where multiple Vite instances can be used simultaneously (it uses `instanceof RunnableDevEnvironment` which fails)
4
+ // - We can use this in Vike's server production runtime without having to load the 'vite' package
5
+ function isRunnableDevEnvironment(environment) {
6
+ return !!environment && 'runner' in environment && !!environment.runner;
7
+ }