vike 0.4.215 → 0.4.217

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 (143) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/node/api/build.js +10 -3
  3. package/dist/cjs/node/api/context.js +8 -6
  4. package/dist/cjs/node/api/dev.js +7 -2
  5. package/dist/cjs/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
  6. package/dist/cjs/node/api/prerender.js +7 -2
  7. package/dist/cjs/node/api/preview.js +7 -2
  8. package/dist/cjs/node/api/utils.js +1 -0
  9. package/dist/cjs/node/plugin/index.js +7 -10
  10. package/dist/cjs/node/plugin/onLoad.js +2 -2
  11. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
  12. package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
  13. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
  14. package/dist/cjs/node/plugin/plugins/buildConfig.js +10 -10
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +35 -4
  16. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  17. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -4
  18. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
  19. package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
  20. package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
  21. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
  22. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
  24. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
  25. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +40 -26
  26. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
  27. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  28. package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -4
  29. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +35 -17
  30. package/dist/cjs/node/prerender/runPrerender.js +5 -7
  31. package/dist/cjs/node/prerender/utils.js +1 -1
  32. package/dist/cjs/node/runtime/globalContext.js +21 -13
  33. package/dist/cjs/node/runtime/index-common.js +3 -1
  34. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
  35. package/dist/cjs/node/runtime/renderPage.js +4 -2
  36. package/dist/cjs/node/runtime/utils.js +1 -2
  37. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
  38. package/dist/cjs/node/runtime-dev/index.js +32 -0
  39. package/dist/cjs/node/shared/resolveBase.js +41 -0
  40. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
  42. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  43. package/dist/cjs/utils/assertSetup.js +135 -0
  44. package/dist/cjs/utils/isDocker.js +2 -2
  45. package/dist/cjs/utils/requireResolve.js +2 -2
  46. package/dist/esm/__internal/index.js +2 -2
  47. package/dist/esm/node/api/build.d.ts +5 -0
  48. package/dist/esm/node/api/build.js +10 -3
  49. package/dist/esm/node/api/context.js +9 -7
  50. package/dist/esm/node/api/dev.d.ts +5 -0
  51. package/dist/esm/node/api/dev.js +7 -2
  52. package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
  53. package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
  54. package/dist/esm/node/api/prerender.d.ts +5 -0
  55. package/dist/esm/node/api/prerender.js +7 -2
  56. package/dist/esm/node/api/preview.d.ts +5 -0
  57. package/dist/esm/node/api/preview.js +7 -2
  58. package/dist/esm/node/api/utils.d.ts +1 -0
  59. package/dist/esm/node/api/utils.js +1 -0
  60. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  61. package/dist/esm/node/plugin/index.d.ts +3 -3
  62. package/dist/esm/node/plugin/index.js +6 -9
  63. package/dist/esm/node/plugin/onLoad.js +1 -1
  64. package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
  65. package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
  66. package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
  67. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
  68. package/dist/esm/node/plugin/plugins/buildConfig.js +11 -11
  69. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
  70. package/dist/esm/node/plugin/plugins/commonConfig.js +36 -5
  71. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
  72. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  73. package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -5
  74. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
  75. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
  76. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
  77. package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
  78. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  79. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
  80. package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +8 -4
  83. package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
  84. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
  85. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +41 -27
  87. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  89. package/dist/esm/node/plugin/plugins/previewConfig.js +5 -5
  90. package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
  91. package/dist/esm/node/plugin/plugins/setGlobalContext.js +37 -19
  92. package/dist/esm/node/prerender/runPrerender.js +6 -8
  93. package/dist/esm/node/prerender/utils.d.ts +1 -1
  94. package/dist/esm/node/prerender/utils.js +1 -1
  95. package/dist/esm/node/runtime/globalContext.d.ts +8 -4
  96. package/dist/esm/node/runtime/globalContext.js +22 -14
  97. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  98. package/dist/esm/node/runtime/index-common.js +1 -0
  99. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
  100. package/dist/esm/node/runtime/renderPage.js +5 -3
  101. package/dist/esm/node/runtime/utils.d.ts +1 -2
  102. package/dist/esm/node/runtime/utils.js +1 -2
  103. package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
  104. package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
  105. package/dist/esm/node/runtime-dev/index.d.ts +3 -0
  106. package/dist/esm/node/runtime-dev/index.js +6 -0
  107. package/dist/esm/node/shared/resolveBase.d.ts +11 -0
  108. package/dist/esm/node/shared/resolveBase.js +36 -0
  109. package/dist/esm/shared/page-configs/Config.d.ts +2 -2
  110. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
  111. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  112. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  113. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  114. package/dist/esm/utils/assertSetup.d.ts +20 -0
  115. package/dist/esm/utils/assertSetup.js +130 -0
  116. package/dist/esm/utils/isDocker.js +1 -1
  117. package/dist/esm/utils/projectInfo.d.ts +1 -1
  118. package/dist/esm/utils/requireResolve.js +1 -1
  119. package/package.json +1 -1
  120. package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
  121. package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
  122. package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
  123. package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
  124. package/dist/cjs/node/shared/getConfigVike.js +0 -10
  125. package/dist/cjs/shared/ConfigVike.js +0 -2
  126. package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
  127. package/dist/cjs/utils/assertNodeEnv.js +0 -106
  128. package/dist/esm/node/api/prepareApiCall.d.ts +0 -7
  129. package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
  130. package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
  131. package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
  132. package/dist/esm/node/plugin/plugins/config/index.js +0 -76
  133. package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
  134. package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
  135. package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
  136. package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
  137. package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
  138. package/dist/esm/node/shared/getConfigVike.js +0 -8
  139. package/dist/esm/shared/ConfigVike.js +0 -1
  140. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
  141. package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
  142. package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
  143. package/dist/esm/utils/assertNodeEnv.js +0 -103
@@ -1,8 +1,13 @@
1
1
  export { dev };
2
- import { prepareApiCall } from './prepareApiCall.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { createServer } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike dev`
6
+ *
7
+ * https://vike.dev/api#dev
8
+ */
4
9
  async function dev(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'dev');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'dev');
6
11
  const server = await createServer(viteConfigEnhanced);
7
12
  return {
8
13
  viteServer: server,
@@ -0,0 +1,7 @@
1
+ export { prepareViteApiCall };
2
+ import type { InlineConfig } from 'vite';
3
+ import type { Operation } from './types.js';
4
+ declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
5
+ viteConfigEnhanced: InlineConfig;
6
+ vikeConfigGlobal: import("../plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js").VikeConfigGlobal;
7
+ }>;
@@ -1,9 +1,9 @@
1
- export { prepareApiCall };
1
+ export { prepareViteApiCall };
2
2
  import { resolveConfig } from 'vite';
3
- import { getConfigVike } from '../shared/getConfigVike.js';
4
3
  import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
5
4
  import { setOperation } from './context.js';
6
- async function prepareApiCall(viteConfig = {}, operation) {
5
+ import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
6
+ async function prepareViteApiCall(viteConfig = {}, operation) {
7
7
  setOperation(operation);
8
8
  return enhanceViteConfig(viteConfig, operation);
9
9
  }
@@ -20,13 +20,23 @@ async function enhanceViteConfig(viteConfig = {}, operation) {
20
20
  };
21
21
  viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
22
22
  }
23
- const configVike = await getConfigVike(viteConfigResolved);
23
+ // TODO: use loadConfigFromFile() instead of viteConfigResolved
24
+ const { vikeConfigGlobal } = await getVikeConfig2(viteConfigResolved.root, operation === 'dev', viteConfigResolved._vikeVitePluginOptions);
24
25
  // TODO: enable Vike extensions to add Vite plugins
25
26
  return {
26
27
  viteConfigEnhanced,
27
- configVike
28
+ vikeConfigGlobal
28
29
  };
29
30
  }
30
31
  async function resolveViteConfig(viteConfig, operation) {
31
- return await resolveConfig(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
32
+ const args = getResolveConfigArgs(viteConfig, operation);
33
+ return await resolveConfig(...args);
34
+ }
35
+ function getResolveConfigArgs(viteConfig, operation) {
36
+ const inlineConfig = viteConfig;
37
+ const command = operation === 'build' || operation === 'prerender' ? 'build' : 'serve';
38
+ const defaultMode = operation === 'dev' ? 'development' : 'production';
39
+ const defaultNodeEnv = defaultMode;
40
+ const isPreview = operation === 'preview';
41
+ return [inlineConfig, command, defaultMode, defaultNodeEnv, isPreview];
32
42
  }
@@ -1,6 +1,11 @@
1
1
  export { prerender };
2
2
  import { type PrerenderOptions } from '../prerender/runPrerender.js';
3
3
  import type { ResolvedConfig } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
4
9
  declare function prerender(options?: PrerenderOptions): Promise<{
5
10
  viteConfig: ResolvedConfig;
6
11
  }>;
@@ -1,8 +1,13 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
- import { prepareApiCall } from './prepareApiCall.js';
3
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
4
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
4
9
  async function prerender(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'prerender');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
6
11
  options.viteConfig = viteConfigEnhanced;
7
12
  const { viteConfig } = await runPrerenderFromAPI(options);
8
13
  return {
@@ -1,6 +1,11 @@
1
1
  export { preview };
2
2
  import { type ResolvedConfig, type PreviewServer } from 'vite';
3
3
  import type { APIOptions } from './types.js';
4
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
4
9
  declare function preview(options?: APIOptions): Promise<{
5
10
  viteServer: PreviewServer;
6
11
  viteConfig: ResolvedConfig;
@@ -1,8 +1,13 @@
1
1
  export { preview };
2
- import { prepareApiCall } from './prepareApiCall.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
4
9
  async function preview(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'preview');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
6
11
  const server = await previewVite(viteConfigEnhanced);
7
12
  return {
8
13
  viteServer: server,
@@ -1 +1,2 @@
1
1
  export * from '../../utils/assert.js';
2
+ export * from '../../utils/getGlobalObject.js';
@@ -3,3 +3,4 @@
3
3
  import { onLoad } from './onLoad.js';
4
4
  onLoad();
5
5
  export * from '../../utils/assert.js';
6
+ export * from '../../utils/getGlobalObject.js';
@@ -1,4 +1,4 @@
1
1
  export { parseCli };
2
2
  declare function parseCli(): {
3
- command: "build" | "dev" | "preview" | "prerender";
3
+ command: "dev" | "build" | "preview" | "prerender";
4
4
  };
@@ -1,7 +1,7 @@
1
1
  export default plugin;
2
2
  export { plugin };
3
3
  export { plugin as ssr };
4
- export type { ConfigVikeUserProvided as UserConfig };
4
+ export type { VikeVitePluginOptions as UserConfig };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
- import type { ConfigVikeUserProvided } from '../../shared/ConfigVike.js';
7
- declare function plugin(vikeConfig?: ConfigVikeUserProvided): any;
6
+ import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
7
+ declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
@@ -4,7 +4,7 @@ export { plugin };
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
6
  import { version } from 'vite';
7
- import { assertNodeEnv_onVikePluginLoad, assertUsage, assertVersion, markEnvAsVikePluginLoaded } from './utils.js';
7
+ import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
8
8
  import { buildConfig } from './plugins/buildConfig.js';
9
9
  import { previewConfig } from './plugins/previewConfig.js';
10
10
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -12,7 +12,6 @@ import { devConfig } from './plugins/devConfig/index.js';
12
12
  import { packageJsonFile } from './plugins/packageJsonFile.js';
13
13
  import { removeRequireHookPlugin } from './plugins/removeRequireHookPlugin.js';
14
14
  import { importUserCode } from './plugins/importUserCode/index.js';
15
- import { resolveVikeConfig } from './plugins/config/index.js';
16
15
  import { distFileNames } from './plugins/distFileNames.js';
17
16
  import { extractAssetsPlugin } from './plugins/extractAssetsPlugin.js';
18
17
  import { extractExportNamesPlugin } from './plugins/extractExportNamesPlugin.js';
@@ -28,15 +27,13 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
28
27
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
29
28
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
30
29
  import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
31
- assertNodeEnv_onVikePluginLoad();
32
- markEnvAsVikePluginLoaded();
30
+ markSetup_vikeVitePlugin();
33
31
  assertViteVersion();
34
32
  setResolveClientEntriesDev(resolveClientEntriesDev);
35
33
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
36
- function plugin(vikeConfig) {
34
+ function plugin(vikeVitePluginOptions) {
37
35
  const plugins = [
38
- resolveVikeConfig(vikeConfig), // The configResolved() hook of resolveVikeConfig() should be the first called
39
- ...commonConfig(),
36
+ ...commonConfig(vikeVitePluginOptions),
40
37
  importUserCode(),
41
38
  ...devConfig(),
42
39
  ...buildConfig(),
@@ -48,9 +45,9 @@ function plugin(vikeConfig) {
48
45
  ...extractAssetsPlugin(),
49
46
  extractExportNamesPlugin(),
50
47
  suppressRollupWarning(),
51
- setGlobalContext(),
48
+ ...setGlobalContext(),
52
49
  ...importBuild(),
53
- baseUrls(vikeConfig),
50
+ baseUrls(vikeVitePluginOptions),
54
51
  envVarsPlugin(),
55
52
  fileEnv(),
56
53
  workaroundCssModuleHmr(),
@@ -1,6 +1,6 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
3
+ import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
4
4
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
5
5
  function onLoad() {
6
6
  assertIsNotBrowser();
@@ -3,24 +3,25 @@ export { autoFullBuild };
3
3
  import { build } from 'vite';
4
4
  import { assertWarning } from '../utils.js';
5
5
  import { runPrerenderFromAutoRun, runPrerender_forceExit } from '../../prerender/runPrerender.js';
6
- import { getConfigVike } from '../../shared/getConfigVike.js';
7
6
  import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
8
7
  import pc from '@brillout/picocolors';
9
8
  import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
10
9
  import { manifestTempFile } from './buildConfig.js';
10
+ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
11
11
  let forceExit = false;
12
12
  function autoFullBuild() {
13
13
  let config;
14
- let configVike;
14
+ let vikeConfigGlobal;
15
15
  return [
16
16
  {
17
17
  name: 'vike:autoFullBuild',
18
18
  apply: 'build',
19
19
  enforce: 'pre',
20
20
  async configResolved(config_) {
21
- configVike = await getConfigVike(config_);
21
+ const vikeConfig = await getVikeConfig(config_);
22
+ vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
22
23
  config = config_;
23
- abortViteBuildSsr(configVike);
24
+ abortViteBuildSsr(vikeConfigGlobal);
24
25
  },
25
26
  writeBundle: {
26
27
  /* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
@@ -29,7 +30,7 @@ function autoFullBuild() {
29
30
  */
30
31
  async handler(_options, bundle) {
31
32
  try {
32
- await triggerFullBuild(config, configVike, bundle);
33
+ await triggerFullBuild(config, vikeConfigGlobal, bundle);
33
34
  }
34
35
  catch (err) {
35
36
  // Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
@@ -55,10 +56,10 @@ function autoFullBuild() {
55
56
  }
56
57
  ];
57
58
  }
58
- async function triggerFullBuild(config, configVike, bundle) {
59
+ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
59
60
  if (config.build.ssr)
60
61
  return; // already triggered
61
- if (isDisabled(configVike))
62
+ if (isDisabled(vikeConfigGlobal))
62
63
  return;
63
64
  // Workaround for @vitejs/plugin-legacy
64
65
  // - The legacy plugin triggers its own Rollup build for the client-side.
@@ -89,19 +90,21 @@ async function triggerFullBuild(config, configVike, bundle) {
89
90
  logErrorHint(err);
90
91
  process.exit(1);
91
92
  }
92
- if (configVike.prerender && !configVike.prerender.disableAutoRun && configVike.disableAutoFullBuild !== 'prerender') {
93
+ if (vikeConfigGlobal.prerender &&
94
+ !vikeConfigGlobal.prerender.disableAutoRun &&
95
+ vikeConfigGlobal.disableAutoFullBuild !== 'prerender') {
93
96
  await runPrerenderFromAutoRun(configInline, false);
94
97
  forceExit = true;
95
98
  }
96
99
  }
97
- function abortViteBuildSsr(configVike) {
98
- if (configVike.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
100
+ function abortViteBuildSsr(vikeConfigGlobal) {
101
+ if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
99
102
  assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
100
103
  process.exit(0);
101
104
  }
102
105
  }
103
- function isDisabled(configVike) {
104
- const { disableAutoFullBuild } = configVike;
106
+ function isDisabled(vikeConfigGlobal) {
107
+ const { disableAutoFullBuild } = vikeConfigGlobal;
105
108
  if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
106
109
  return !isViteCliCall();
107
110
  }
@@ -1,4 +1,4 @@
1
1
  export { baseUrls };
2
2
  import type { Plugin } from 'vite';
3
- import type { ConfigVikeUserProvided } from '../../../shared/ConfigVike.js';
4
- declare function baseUrls(configVike?: ConfigVikeUserProvided): Plugin;
3
+ import type { VikeVitePluginOptions } from './importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
4
+ declare function baseUrls(vikeVitePluginOptions?: VikeVitePluginOptions): Plugin;
@@ -1,17 +1,16 @@
1
1
  export { baseUrls };
2
- import { resolveBaseFromUserConfig } from '../plugins/config/resolveBase.js';
2
+ import { resolveBase, resolveBaseFromResolvedConfig } from '../../shared/resolveBase.js';
3
3
  import { assert } from '../utils.js';
4
- import { getConfigVike } from '../../shared/getConfigVike.js';
5
- function baseUrls(configVike) {
6
- let baseServer;
7
- let baseAssets;
4
+ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
5
+ function baseUrls(vikeVitePluginOptions) {
6
+ let bases;
8
7
  return {
9
8
  name: 'vike:baseUrls',
10
9
  enforce: 'post',
11
10
  async config(config) {
12
- const bases = resolveBaseFromUserConfig(config, configVike);
13
- baseServer = bases.baseServer;
14
- baseAssets = bases.baseAssets;
11
+ // TODO: fix bug: use getVikeConfig2() and udpate check below
12
+ bases = resolveBaseFromUserConfig(config, vikeVitePluginOptions);
13
+ const { baseServer, baseAssets } = bases;
15
14
  // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
16
15
  process.env.BASE_SERVER = baseServer;
17
16
  process.env.BASE_ASSETS = baseAssets;
@@ -22,14 +21,16 @@ function baseUrls(configVike) {
22
21
  'BASE_ASSETS'
23
22
  ],
24
23
  base: baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
25
- _baseOriginal: config.base ?? '/__UNSET__' // Vite resolves `_baseOriginal: null` to `undefined`
24
+ _baseViteOriginal: config.base ?? '/__UNSET__' // Vite resolves `_baseViteOriginal: null` to `undefined`
26
25
  };
27
26
  },
28
27
  async configResolved(config) {
29
- const configVike = await getConfigVike(config);
28
+ const vikeConfig = await getVikeConfig(config);
29
+ const { baseServer, baseAssets } = vikeConfig.vikeConfigGlobal;
30
+ const basesResolved = resolveBaseFromResolvedConfig(baseServer, baseAssets, config);
30
31
  // Ensure that the premature base URL resolving we did in config() isn't erroneous
31
- assert(configVike.baseServer === baseServer);
32
- assert(configVike.baseAssets === baseAssets);
32
+ assert(basesResolved.baseServer === bases.baseServer);
33
+ assert(basesResolved.baseAssets === bases.baseAssets);
33
34
  /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
34
35
  * - In dev, Vite removes the URL origin. (I.e. it resolves the user config `vite.config.js#base: 'http://localhost:8080/cdn/'` to resolved config `config.base === '/cdn/'`.)
35
36
  * - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
@@ -38,3 +39,7 @@ function baseUrls(configVike) {
38
39
  }
39
40
  };
40
41
  }
42
+ function resolveBaseFromUserConfig(config, vikeVitePluginOptions) {
43
+ const baseViteOriginal = config.base ?? null;
44
+ return resolveBase(baseViteOriginal, vikeVitePluginOptions?.baseServer ?? null, vikeVitePluginOptions?.baseAssets ?? null);
45
+ }
@@ -202,7 +202,7 @@ function fixServerAssets_assertCssTarget_populate(config) {
202
202
  async function fixServerAssets_assertCssTarget(config) {
203
203
  if (!fixServerAssets_isEnabled())
204
204
  return;
205
- if (!(await isV1Design(config, false)))
205
+ if (!(await isV1Design(config)))
206
206
  return;
207
207
  const targetsServer = targets.filter((t) => t.isServerSide);
208
208
  const targetsClient = targets.filter((t) => !t.isServerSide);
@@ -2,10 +2,9 @@ export { buildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
4
  export { manifestTempFile };
5
- import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, assertNodeEnv_build, assertIsNpmPackageImport } from '../utils.js';
5
+ import { assert, resolveOutDir, viteIsSSR, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, getOutDirs, onSetupBuild, assertIsNpmPackageImport } from '../utils.js';
6
6
  import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
7
7
  import { findPageFiles } from '../shared/findPageFiles.js';
8
- import { getConfigVike } from '../../shared/getConfigVike.js';
9
8
  import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
10
9
  import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
11
10
  import { createRequire } from 'module';
@@ -27,14 +26,14 @@ function buildConfig() {
27
26
  let config;
28
27
  return [
29
28
  {
30
- name: 'vike:buildConfig:configResolved',
29
+ name: 'vike:buildConfig:post',
31
30
  apply: 'build',
32
31
  enforce: 'post',
33
32
  configResolved: {
34
33
  order: 'post',
35
34
  async handler(config_) {
36
35
  config = config_;
37
- assertNodeEnv_build();
36
+ onSetupBuild();
38
37
  assertRollupInput(config);
39
38
  const entries = await getEntries(config);
40
39
  assert(Object.keys(entries).length > 0);
@@ -42,7 +41,7 @@ function buildConfig() {
42
41
  addLogHook();
43
42
  outDirs = getOutDirs(config);
44
43
  {
45
- isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
44
+ isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config));
46
45
  if (isServerAssetsFixEnabled) {
47
46
  // https://github.com/vikejs/vike/issues/1339
48
47
  config.build.ssrEmitAssets = true;
@@ -57,7 +56,7 @@ function buildConfig() {
57
56
  config: {
58
57
  order: 'post',
59
58
  handler(config) {
60
- assertNodeEnv_build();
59
+ onSetupBuild();
61
60
  isSsrBuild = viteIsSSR(config);
62
61
  return {
63
62
  build: {
@@ -69,14 +68,15 @@ function buildConfig() {
69
68
  }
70
69
  },
71
70
  buildStart() {
72
- assertNodeEnv_build();
71
+ onSetupBuild();
73
72
  },
74
73
  async closeBundle() {
74
+ onSetupBuild();
75
75
  await fixServerAssets_assertCssTarget(config);
76
76
  }
77
77
  },
78
78
  {
79
- name: 'vike:buildConfig:writeBundle',
79
+ name: 'vike:buildConfig:pre',
80
80
  apply: 'build',
81
81
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
82
82
  // - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
@@ -110,9 +110,9 @@ function buildConfig() {
110
110
  ];
111
111
  }
112
112
  async function getEntries(config) {
113
- const configVike = await getConfigVike(config);
114
- const pageFileEntries = await getPageFileEntries(config, configVike.includeAssetsImportedByServer); // TODO/v1-release: remove
115
- const { pageConfigs } = await getVikeConfig(config, false);
113
+ const vikeConfig = await getVikeConfig(config);
114
+ const { pageConfigs } = vikeConfig;
115
+ const pageFileEntries = await getPageFileEntries(config, vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer); // TODO/v1-release: remove
116
116
  assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
117
117
  if (viteIsSSR(config)) {
118
118
  const pageEntries = getPageEntries(pageConfigs);
@@ -1,3 +1,3 @@
1
1
  export { commonConfig };
2
2
  import { type Plugin } from 'vite';
3
- declare function commonConfig(): Plugin[];
3
+ declare function commonConfig(vikeVitePluginOptions?: unknown): Plugin[];
@@ -1,6 +1,6 @@
1
1
  export { commonConfig };
2
2
  import { mergeConfig } from 'vite';
3
- import { assert, assertUsage, assertWarning, findPackageJson, isDocker } from '../utils.js';
3
+ import { assert, assertUsage, assertWarning, findPackageJson, isDevCheck, isDocker } from '../utils.js';
4
4
  import { assertRollupInput } from './buildConfig.js';
5
5
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
6
6
  import pc from '@brillout/picocolors';
@@ -9,11 +9,22 @@ import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
9
9
  import { pluginName } from './commonConfig/pluginName.js';
10
10
  import { getEnvVarObject } from '../shared/getEnvVarObject.js';
11
11
  import { isViteCliCall } from '../shared/isViteCliCall.js';
12
- assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
13
- onlyOnce: true
14
- });
15
- function commonConfig() {
12
+ import { isVikeCliOrApi } from '../../api/context.js';
13
+ function commonConfig(vikeVitePluginOptions = {}) {
16
14
  return [
15
+ {
16
+ name: `${pluginName}:pre`,
17
+ enforce: 'pre',
18
+ config: {
19
+ order: 'pre',
20
+ handler(_config, env) {
21
+ return {
22
+ _isDev: isDevCheck(env),
23
+ _vikeVitePluginOptions: vikeVitePluginOptions
24
+ };
25
+ }
26
+ }
27
+ },
17
28
  {
18
29
  name: pluginName,
19
30
  configResolved(config) {
@@ -34,6 +45,7 @@ function commonConfig() {
34
45
  assertRollupInput(config);
35
46
  assertResolveAlias(config);
36
47
  assertEsm(config.root);
48
+ assertVikeCliOrApi(config);
37
49
  }
38
50
  },
39
51
  config: {
@@ -97,3 +109,22 @@ function assertSingleInstance(config) {
97
109
  const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
98
110
  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.`);
99
111
  }
112
+ function assertVikeCliOrApi(config) {
113
+ if (isVikeCliOrApi())
114
+ return;
115
+ if (isViteCliCall()) {
116
+ assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
117
+ onlyOnce: true
118
+ });
119
+ return;
120
+ }
121
+ if (config.server.middlewareMode) {
122
+ assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
123
+ onlyOnce: true
124
+ });
125
+ return;
126
+ }
127
+ assertWarning(false, `Vite's JavaScript API is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
128
+ onlyOnce: true
129
+ });
130
+ }
@@ -1,3 +1,3 @@
1
1
  export { determineOptimizeDeps };
2
2
  import type { ResolvedConfig } from 'vite';
3
- declare function determineOptimizeDeps(config: ResolvedConfig, isDev: true): Promise<void>;
3
+ declare function determineOptimizeDeps(config: ResolvedConfig): Promise<void>;
@@ -6,9 +6,9 @@ import { analyzeClientEntries } from '../buildConfig.js';
6
6
  import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
7
7
  import { getFilePathResolved } from '../../shared/getFilePath.js';
8
8
  const debug = createDebugger('vike:optimizeDeps');
9
- async function determineOptimizeDeps(config, isDev) {
10
- const { pageConfigs } = await getVikeConfig(config, isDev);
11
- const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
9
+ async function determineOptimizeDeps(config) {
10
+ const { pageConfigs } = await getVikeConfig(config);
11
+ const { entries, include } = await getPageDeps(config, pageConfigs);
12
12
  {
13
13
  // This actually doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
14
14
  // - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
@@ -28,7 +28,7 @@ async function determineOptimizeDeps(config, isDev) {
28
28
  'config.optimizeDeps.include': config.optimizeDeps.include
29
29
  });
30
30
  }
31
- async function getPageDeps(config, pageConfigs, isDev) {
31
+ async function getPageDeps(config, pageConfigs) {
32
32
  let entries = [];
33
33
  let include = [];
34
34
  const addEntry = (e) => {
@@ -67,7 +67,7 @@ async function getPageDeps(config, pageConfigs, isDev) {
67
67
  }
68
68
  // V0.4 design
69
69
  {
70
- const pageFiles = await findPageFiles(config, ['.page', '.page.client'], isDev);
70
+ const pageFiles = await findPageFiles(config, ['.page', '.page.client'], true);
71
71
  const userRootDir = config.root;
72
72
  pageFiles.forEach((filePathAbsoluteUserRootDir) => {
73
73
  const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
@@ -3,7 +3,7 @@ export { logDockerHint };
3
3
  import { determineOptimizeDeps } from './determineOptimizeDeps.js';
4
4
  import { determineFsAllowList } from './determineFsAllowList.js';
5
5
  import { addSsrMiddleware } from '../../shared/addSsrMiddleware.js';
6
- import { applyDev, assertWarning, isDocker, markEnvAsViteDev } from '../../utils.js';
6
+ import { applyDev, assertWarning, isDocker } from '../../utils.js';
7
7
  import { improveViteLogs } from '../../shared/loggerVite.js';
8
8
  import { isErrorDebug } from '../../../shared/isErrorDebug.js';
9
9
  import { installHttpRequestAsyncStore } from '../../shared/getHttpRequestAsyncStore.js';
@@ -58,16 +58,13 @@ function devConfig() {
58
58
  },
59
59
  async configResolved(config_) {
60
60
  config = config_;
61
- await determineOptimizeDeps(config, true);
61
+ await determineOptimizeDeps(config);
62
62
  await determineFsAllowList(config);
63
63
  if (!isErrorDebug()) {
64
64
  await installHttpRequestAsyncStore();
65
65
  improveViteLogs(config);
66
66
  }
67
67
  logDockerHint(config.server.host);
68
- },
69
- configureServer() {
70
- markEnvAsViteDev();
71
68
  }
72
69
  },
73
70
  {
@@ -9,7 +9,6 @@ export { extractAssetsRE };
9
9
  import { viteIsSSR_options, assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage } from '../utils.js';
10
10
  import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtual-files.js';
11
11
  import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
12
- import { getConfigVike } from '../../shared/getConfigVike.js';
13
12
  import { isAsset } from '../shared/isAsset.js';
14
13
  import { getImportStatements } from '../shared/parseEsModule.js';
15
14
  import { sourceMapRemove } from '../shared/rollupSourceMap.js';
@@ -25,7 +24,6 @@ const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
25
24
  const debug = createDebugger('vike:extractAssets');
26
25
  function extractAssetsPlugin() {
27
26
  let config;
28
- let configVike;
29
27
  let vikeConfig;
30
28
  let isServerAssetsFixEnabled;
31
29
  return [
@@ -45,7 +43,7 @@ function extractAssetsPlugin() {
45
43
  assertV1Design(vikeConfig.pageConfigs, true);
46
44
  assert(false);
47
45
  }
48
- assert(configVike.includeAssetsImportedByServer);
46
+ assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
49
47
  assert(!viteIsSSR_options(options));
50
48
  const importStatements = await getImportStatements(src);
51
49
  const moduleNames = getImportedModules(importStatements);
@@ -78,7 +76,7 @@ function extractAssetsPlugin() {
78
76
  if (!extractAssetsRE.test(importer)) {
79
77
  return;
80
78
  }
81
- assert(configVike.includeAssetsImportedByServer);
79
+ assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
82
80
  let resolution = null;
83
81
  try {
84
82
  resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
@@ -137,10 +135,9 @@ function extractAssetsPlugin() {
137
135
  {
138
136
  name: 'vike:extractAssets-4',
139
137
  async configResolved(config_) {
140
- configVike = await getConfigVike(config_);
141
138
  config = config_;
142
- vikeConfig = await getVikeConfig(config, false);
143
- isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
139
+ vikeConfig = await getVikeConfig(config);
140
+ isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config));
144
141
  if (!isServerAssetsFixEnabled) {
145
142
  // https://github.com/vikejs/vike/issues/1060
146
143
  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');
@@ -1,4 +1,5 @@
1
1
  export { getVikeManifest };
2
2
  import { type PluginManifest } from '../../../shared/assertPluginManifest.js';
3
- import type { ConfigVikeResolved } from '../../../../shared/ConfigVike.js';
4
- declare function getVikeManifest(configVike: ConfigVikeResolved): PluginManifest;
3
+ import type { VikeConfigGlobal } from '../importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
4
+ import type { ResolvedConfig } from 'vite';
5
+ declare function getVikeManifest(vikeConfigGlobal: VikeConfigGlobal, viteConfig: ResolvedConfig): PluginManifest;