vike 0.4.225-commit-37a36a5 → 0.4.225-commit-b8fc36e

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 (75) hide show
  1. package/dist/cjs/client/shared/getPageContextProxyForUser.js +3 -66
  2. package/dist/cjs/node/api/build.js +7 -7
  3. package/dist/cjs/node/api/dev.js +2 -2
  4. package/dist/cjs/node/api/prepareViteApiCall.js +52 -29
  5. package/dist/cjs/node/api/prerender.js +2 -2
  6. package/dist/cjs/node/api/preview.js +2 -2
  7. package/dist/cjs/node/api/utils.js +1 -0
  8. package/dist/cjs/node/cli/parseCli.js +10 -4
  9. package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
  10. package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -6
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -0
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +20 -7
  13. package/dist/cjs/node/plugin/shared/getEnvVarObject.js +7 -0
  14. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -3
  15. package/dist/cjs/node/prerender/runPrerender.js +8 -12
  16. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +67 -14
  17. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  18. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  19. package/dist/cjs/node/runtime/renderPage.js +13 -28
  20. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +2 -2
  21. package/dist/cjs/shared/NOT_SERIALIZABLE.js +5 -0
  22. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  23. package/dist/cjs/utils/assert.js +1 -1
  24. package/dist/cjs/utils/objectAssign.js +7 -2
  25. package/dist/cjs/utils/pick.js +12 -0
  26. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -0
  27. package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -1
  28. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  29. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +6 -3
  30. package/dist/esm/client/server-routing-runtime/getPageContext.js +6 -3
  31. package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +1 -11
  32. package/dist/esm/client/shared/getPageContextProxyForUser.js +4 -67
  33. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  34. package/dist/esm/node/api/build.js +7 -7
  35. package/dist/esm/node/api/dev.js +2 -2
  36. package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -1
  37. package/dist/esm/node/api/prepareViteApiCall.js +54 -31
  38. package/dist/esm/node/api/prerender.js +2 -2
  39. package/dist/esm/node/api/preview.js +2 -2
  40. package/dist/esm/node/api/utils.d.ts +1 -0
  41. package/dist/esm/node/api/utils.js +1 -0
  42. package/dist/esm/node/cli/parseCli.js +10 -4
  43. package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
  44. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
  45. package/dist/esm/node/plugin/plugins/commonConfig.js +0 -6
  46. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -0
  47. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -0
  48. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +20 -7
  49. package/dist/esm/node/plugin/shared/getEnvVarObject.js +7 -0
  50. package/dist/esm/node/prerender/resolvePrerenderConfig.js +3 -3
  51. package/dist/esm/node/prerender/runPrerender.js +8 -12
  52. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -0
  53. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +69 -15
  54. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  55. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -1
  56. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  57. package/dist/esm/node/runtime/renderPage.js +14 -29
  58. package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
  59. package/dist/esm/shared/NOT_SERIALIZABLE.d.ts +1 -0
  60. package/dist/esm/shared/NOT_SERIALIZABLE.js +2 -0
  61. package/dist/esm/shared/page-configs/Config.d.ts +11 -3
  62. package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -1
  63. package/dist/esm/shared/route/abort.d.ts +2 -2
  64. package/dist/esm/shared/types.d.ts +34 -2
  65. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  66. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  67. package/dist/esm/utils/assert.js +1 -1
  68. package/dist/esm/utils/objectAssign.d.ts +1 -1
  69. package/dist/esm/utils/objectAssign.js +7 -2
  70. package/dist/esm/utils/pick.d.ts +1 -0
  71. package/dist/esm/utils/pick.js +9 -0
  72. package/package.json +1 -1
  73. package/dist/cjs/shared/notSerializable.js +0 -5
  74. package/dist/esm/shared/notSerializable.d.ts +0 -1
  75. package/dist/esm/shared/notSerializable.js +0 -2
@@ -2,78 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPageContextProxyForUser = getPageContextProxyForUser;
4
4
  const utils_js_1 = require("../server-routing-runtime/utils.js");
5
- const notSerializable_js_1 = require("../../shared/notSerializable.js");
6
- const globalObject = (0, utils_js_1.getGlobalObject)('shared/getPageContextProxyForUser.ts', {});
7
- /**
8
- * Throw error when pageContext value isn't:
9
- * - serializable, or
10
- * - defined.
11
- */
5
+ const NOT_SERIALIZABLE_js_1 = require("../../shared/NOT_SERIALIZABLE.js");
6
+ // Throw error when pageContext value isn't serializable
12
7
  function getPageContextProxyForUser(pageContext) {
13
- (0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromServer));
14
- (0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromClient));
15
8
  return new Proxy(pageContext, {
16
9
  get(_, prop) {
17
10
  const val = pageContext[prop];
18
11
  const propName = (0, utils_js_1.getPropAccessNotation)(prop);
19
- (0, utils_js_1.assertUsage)(val !== notSerializable_js_1.notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
20
- passToClientHint(pageContext, prop, propName);
12
+ (0, utils_js_1.assertUsage)(val !== NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
21
13
  return val;
22
14
  }
23
15
  });
24
16
  }
25
- function passToClientHint(pageContext, prop, propName) {
26
- if (handleVueReactivity(prop))
27
- return;
28
- // `prop in pageContext` is the trick we use to know the passToClient value on the client-side, as we set a value to all passToClient props, even `undefined` ones:
29
- // ```html
30
- // <script id="vike_pageContext" type="application/json">{"pageProps":"!undefined"}</script>
31
- // ```
32
- if (prop in pageContext)
33
- return;
34
- if (isWhitelisted(prop))
35
- return;
36
- // The trick described above (`prop in pageContext`) doesn't work if Vike doesn't fetch any pageContext from the server.
37
- // - There would still be some value to show a warning, but it isn't worth it because of the confusion that the first recommendation (adding `prop` to `passToClient`) wouldn't actually remove the warning, and only the second recommendation (using `prop in pageContext` instead of `pageContext[prop]`) would work.
38
- if (!pageContext._hasPageContextFromServer)
39
- return;
40
- const errMsg = `pageContext${propName} isn't defined on the client-side, see https://vike.dev/passToClient#error`;
41
- if (
42
- // TODO/next-major-release always make it an error.
43
- // - Remove pageContext._hasPageContextFromClient logic (IIRC this is its only use case).
44
- pageContext._hasPageContextFromClient) {
45
- (0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: false, showStackTrace: true });
46
- }
47
- else {
48
- (0, utils_js_1.assertUsage)(false, errMsg);
49
- }
50
- }
51
- const WHITELIST = [
52
- 'then',
53
- // Vue calls toJSON()
54
- 'toJSON'
55
- ];
56
- function isWhitelisted(prop) {
57
- if (WHITELIST.includes(prop))
58
- return true;
59
- if (typeof prop === 'symbol')
60
- return true; // Vue tries to access some symbols
61
- if (typeof prop !== 'string')
62
- return true;
63
- if (prop.startsWith('__v_'))
64
- return true; // Vue internals upon `reactive(pageContext)`
65
- return false;
66
- }
67
- // Handle Vue's reactivity.
68
- // When changing a reactive object:
69
- // - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextReactive.routeParams = pageContextNew.routeParams` and `pageContextReactive` has no `routeParams`.
70
- // - Vue seems to read __v_raw before reading the property.
71
- function handleVueReactivity(prop) {
72
- if (globalObject.prev === prop || globalObject.prev === '__v_raw')
73
- return true;
74
- globalObject.prev = prop;
75
- window.setTimeout(() => {
76
- globalObject.prev = undefined;
77
- }, 0);
78
- return false;
79
- }
@@ -16,13 +16,13 @@ const utils_js_1 = require("./utils.js");
16
16
  * https://vike.dev/api#build
17
17
  */
18
18
  async function build(options = {}) {
19
- const { viteConfigEnhanced, vikeConfig } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'build');
19
+ const { viteConfigFromUserEnhanced, vikeConfig } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'build');
20
20
  // Pass it to pluginAutoFullBuild()
21
- if (viteConfigEnhanced)
22
- viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
21
+ if (viteConfigFromUserEnhanced)
22
+ viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
23
23
  if (vikeConfig.global.config.vite6BuilderApp) {
24
24
  (0, utils_js_1.assertVersion)('Vite', vite_1.version, '6.0.0');
25
- const builder = await (0, vite_1.createBuilder)(viteConfigEnhanced);
25
+ const builder = await (0, vite_1.createBuilder)(viteConfigFromUserEnhanced);
26
26
  // See Vite plugin vike:build:pluginBuildApp
27
27
  await builder.buildApp();
28
28
  }
@@ -35,14 +35,14 @@ async function build(options = {}) {
35
35
  // > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
36
36
  // > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
37
37
  // > Rationale: https://github.com/vikejs/vike/issues/2123
38
- await (0, vite_1.build)(viteConfigEnhanced);
38
+ await (0, vite_1.build)(viteConfigFromUserEnhanced);
39
39
  // After pre-rendering, when using the Vike CLI, the process is forcefully exited at the end of the buildVite() call above.
40
40
  if ((0, context_js_1.isVikeCli)() && (0, context_js_2.isPrerendering)())
41
41
  (0, assert_1.default)(false);
42
42
  }
43
43
  return {
44
- /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
45
- viteConfig: viteConfigEnhanced,
44
+ /* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
45
+ viteConfig: viteConfigFromUserEnhanced,
46
46
  */
47
47
  };
48
48
  }
@@ -9,8 +9,8 @@ const vite_1 = require("vite");
9
9
  * https://vike.dev/api#dev
10
10
  */
11
11
  async function dev(options = {}) {
12
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'dev');
13
- const server = await (0, vite_1.createServer)(viteConfigEnhanced);
12
+ const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'dev');
13
+ const server = await (0, vite_1.createServer)(viteConfigFromUserEnhanced);
14
14
  return {
15
15
  viteServer: server,
16
16
  viteConfig: server.config
@@ -47,56 +47,79 @@ const path_1 = __importDefault(require("path"));
47
47
  const utils_js_1 = require("./utils.js");
48
48
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
49
49
  const globalContext_js_1 = require("../runtime/globalContext.js");
50
+ const getEnvVarObject_js_1 = require("../plugin/shared/getEnvVarObject.js");
50
51
  const globalObject = (0, utils_js_1.getGlobalObject)('api/prepareViteApiCall.ts', {});
51
52
  async function prepareViteApiCall(options, operation) {
52
53
  clear();
53
54
  (0, context_js_1.setContextApiOperation)(operation, options);
54
- const viteConfigFromOptions = options.viteConfig;
55
- return enhanceViteConfig(viteConfigFromOptions, operation);
55
+ const viteConfigFromUserApiOptions = options.viteConfig;
56
+ return resolveConfigs(viteConfigFromUserApiOptions, operation);
56
57
  }
57
58
  // For subsequent API calls, e.g. calling prerender() after build()
58
59
  function clear() {
59
60
  (0, context_js_1.clearContextApiOperation)();
60
61
  (0, globalContext_js_1.clearGlobalContext)();
61
62
  }
62
- async function enhanceViteConfig(viteConfigFromOptions, operation) {
63
- const viteInfo = await getInfoFromVite(viteConfigFromOptions, operation);
64
- await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
63
+ async function resolveConfigs(viteConfigFromUserApiOptions, operation) {
64
+ const viteInfo = await getViteInfo(viteConfigFromUserApiOptions, operation);
65
+ await assertViteRoot2(viteInfo.root, viteInfo.viteConfigFromUserEnhanced, operation);
65
66
  const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
66
- const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
67
+ const viteConfigFromUserEnhanced = applyVikeViteConfig(viteInfo.viteConfigFromUserEnhanced, vikeConfig);
67
68
  return {
68
69
  vikeConfig,
69
- viteConfigEnhanced
70
+ viteConfigFromUserEnhanced
70
71
  };
71
72
  }
72
- function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
73
+ // Apply +vite
74
+ // - For example, Vike extensions adding Vite plugins
75
+ function applyVikeViteConfig(viteConfigFromUserEnhanced, vikeConfig) {
73
76
  const viteConfigs = vikeConfig.global._from.configsCumulative.vite;
74
77
  if (!viteConfigs)
75
- return viteConfigEnhanced;
78
+ return viteConfigFromUserEnhanced;
76
79
  viteConfigs.values.forEach((v) => {
77
80
  (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(v.value), `${v.definedAt} should be an object`);
78
- viteConfigEnhanced = (0, vite_1.mergeConfig)(viteConfigEnhanced ?? {}, v.value);
81
+ viteConfigFromUserEnhanced = (0, vite_1.mergeConfig)(viteConfigFromUserEnhanced ?? {}, v.value);
79
82
  (0, utils_js_1.assertUsage)(!findVikeVitePlugin(v.value), "Using the +vite setting to add Vike's Vite plugin is forbidden");
80
83
  });
81
- return viteConfigEnhanced;
84
+ return viteConfigFromUserEnhanced;
82
85
  }
83
86
  async function getViteRoot(operation) {
84
87
  if (!globalObject.root)
85
- await getInfoFromVite(undefined, operation);
88
+ await getViteInfo(undefined, operation);
86
89
  (0, utils_js_1.assert)(globalObject.root);
87
90
  return globalObject.root;
88
91
  }
89
- async function getInfoFromVite(viteConfigFromOptions, operation) {
90
- const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigFromOptions, operation);
91
- const root = normalizeViteRoot(
92
- // `viteConfigFromOptions.root` before `viteConfigFromUserViteFile.root` replicates Vite's precedence:
92
+ async function getViteInfo(viteConfigFromUserApiOptions, operation) {
93
+ let viteConfigFromUserEnhanced = viteConfigFromUserApiOptions;
94
+ // Precedence:
95
+ // 1) viteConfigFromUserEnvVar (highest precendence)
96
+ // 2) viteConfigFromUserVikeConfig
97
+ // 2) viteConfigFromUserApiOptions
98
+ // 3) viteConfigFromUserViteFile (lowest precendence)
99
+ // Resolve Vike's +mode setting
100
+ {
101
+ const viteConfigFromUserVikeConfig = (0, utils_js_1.pick)((0, getVikeConfig_js_1.getVikeConfigFromCliOrEnv)().vikeConfigFromCliOrEnv, ['mode']);
102
+ if (Object.keys(viteConfigFromUserVikeConfig).length > 0) {
103
+ viteConfigFromUserEnhanced = (0, vite_1.mergeConfig)(viteConfigFromUserEnhanced ?? {}, viteConfigFromUserVikeConfig);
104
+ }
105
+ }
106
+ // Resolve VITE_CONFIG
107
+ const viteConfigFromUserEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VITE_CONFIG');
108
+ if (viteConfigFromUserEnvVar) {
109
+ viteConfigFromUserEnhanced = (0, vite_1.mergeConfig)(viteConfigFromUserEnhanced ?? {}, viteConfigFromUserEnvVar);
110
+ }
111
+ // Resolve vite.config.js
112
+ const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigFromUserEnhanced, operation);
113
+ // Correct precedence, replicates Vite:
93
114
  // https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1001
94
- viteConfigFromOptions?.root ?? viteConfigFromUserViteFile?.root ?? process.cwd());
115
+ const viteConfigResolved = (0, vite_1.mergeConfig)(viteConfigFromUserViteFile ?? {}, viteConfigFromUserEnhanced ?? {});
116
+ const root = normalizeViteRoot(viteConfigResolved.root ?? process.cwd());
95
117
  globalObject.root = root;
118
+ // - Find options `vike(options)` set in vite.config.js
119
+ // - TODO/next-major: remove
120
+ // - Add Vike's Vite plugin if missing
96
121
  let vikeVitePluginOptions;
97
- let viteConfigEnhanced = viteConfigFromOptions;
98
- // If Vike's Vite plugin is found in both viteConfigFromOptions and viteConfigFromUserViteFile then Vike will later throw an error
99
- const found = findVikeVitePlugin(viteConfigFromOptions) || findVikeVitePlugin(viteConfigFromUserViteFile);
122
+ const found = findVikeVitePlugin(viteConfigResolved);
100
123
  if (found) {
101
124
  vikeVitePluginOptions = found.vikeVitePluginOptions;
102
125
  }
@@ -104,16 +127,16 @@ async function getInfoFromVite(viteConfigFromOptions, operation) {
104
127
  // Add Vike to plugins if not present.
105
128
  // Using a dynamic import because the script calling the Vike API may not live in the same place as vite.config.js, thus vike/plugin may resolved to two different node_modules/vike directories.
106
129
  const { plugin: vikePlugin } = await Promise.resolve().then(() => __importStar(require('../plugin/index.js')));
107
- viteConfigEnhanced = {
108
- ...viteConfigFromOptions,
109
- plugins: [...(viteConfigFromOptions?.plugins ?? []), vikePlugin()]
130
+ viteConfigFromUserEnhanced = {
131
+ ...viteConfigFromUserEnhanced,
132
+ plugins: [...(viteConfigFromUserEnhanced?.plugins ?? []), vikePlugin()]
110
133
  };
111
- const res = findVikeVitePlugin(viteConfigEnhanced);
134
+ const res = findVikeVitePlugin(viteConfigFromUserEnhanced);
112
135
  (0, utils_js_1.assert)(res);
113
136
  vikeVitePluginOptions = res.vikeVitePluginOptions;
114
137
  }
115
138
  (0, utils_js_1.assert)(vikeVitePluginOptions);
116
- return { root, vikeVitePluginOptions, viteConfigEnhanced };
139
+ return { root, vikeVitePluginOptions, viteConfigFromUserEnhanced };
117
140
  }
118
141
  function findVikeVitePlugin(viteConfig) {
119
142
  let vikeVitePluginOptions;
@@ -131,8 +154,8 @@ function findVikeVitePlugin(viteConfig) {
131
154
  return { vikeVitePluginOptions };
132
155
  }
133
156
  // Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
134
- async function loadViteConfigFile(viteConfigFromOptions, operation) {
135
- const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfigFromOptions, operation);
157
+ async function loadViteConfigFile(viteConfigFromUserApiOptions, operation) {
158
+ const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfigFromUserApiOptions, operation);
136
159
  let config = inlineConfig;
137
160
  let mode = inlineConfig.mode || defaultMode;
138
161
  const configEnv = {
@@ -164,8 +187,8 @@ function normalizeViteRoot(root) {
164
187
  path_1.default.resolve(root));
165
188
  }
166
189
  const errMsg = `A Vite plugin is modifying Vite's setting ${picocolors_1.default.cyan('root')} which is forbidden`;
167
- async function assertViteRoot2(root, viteConfigEnhanced, operation) {
168
- const args = getResolveConfigArgs(viteConfigEnhanced, operation);
190
+ async function assertViteRoot2(root, viteConfigFromUserEnhanced, operation) {
191
+ const args = getResolveConfigArgs(viteConfigFromUserEnhanced, operation);
169
192
  // We can eventually this resolveConfig() call (along with removing the whole assertViteRoot2() function which is redundant with the assertViteRoot() function) so that Vike doesn't make any resolveConfig() (except for pre-rendering which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
170
193
  const viteConfigResolved = await (0, vite_1.resolveConfig)(...args);
171
194
  (0, utils_js_1.assertUsage)(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
@@ -10,8 +10,8 @@ const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
10
10
  * https://vike.dev/api#prerender
11
11
  */
12
12
  async function prerender(options = {}) {
13
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'prerender');
14
- options.viteConfig = viteConfigEnhanced;
13
+ const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'prerender');
14
+ options.viteConfig = viteConfigFromUserEnhanced;
15
15
  const { viteConfig } = await (0, runPrerender_js_1.runPrerenderFromAPI)(options);
16
16
  return {
17
17
  viteConfig
@@ -9,8 +9,8 @@ const vite_1 = require("vite");
9
9
  * https://vike.dev/api#preview
10
10
  */
11
11
  async function preview(options = {}) {
12
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'preview');
13
- const server = await (0, vite_1.preview)(viteConfigEnhanced);
12
+ const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'preview');
13
+ const server = await (0, vite_1.preview)(viteConfigFromUserEnhanced);
14
14
  return {
15
15
  viteServer: server,
16
16
  viteConfig: server.config
@@ -23,3 +23,4 @@ __exportStar(require("../../utils/getGlobalObject.js"), exports);
23
23
  __exportStar(require("../../utils/path.js"), exports);
24
24
  __exportStar(require("../../utils/isObject.js"), exports);
25
25
  __exportStar(require("../../utils/assertVersion.js"), exports);
26
+ __exportStar(require("../../utils/pick.js"), exports);
@@ -11,7 +11,7 @@ const commands = [
11
11
  { name: 'dev', desc: 'Start development server' },
12
12
  { name: 'build', desc: 'Build for production' },
13
13
  { name: 'preview', desc: 'Start preview server using production build (only works for SSG apps)' },
14
- { name: 'prerender', desc: 'Pre-render pages (only needed when partial.disableAutoRun is true)' }
14
+ { name: 'prerender', desc: 'Pre-render pages (only needed when prerender.disableAutoRun is true)' }
15
15
  ];
16
16
  function parseCli() {
17
17
  const command = getCommand();
@@ -62,10 +62,16 @@ function showHelp() {
62
62
  `vike@${utils_js_1.PROJECT_VERSION}`,
63
63
  '',
64
64
  'Usage:',
65
- ...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${picocolors_1.default.dim('$')} ${picocolors_1.default.bold(`vike ${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${picocolors_1.default.dim(`# ${c.desc}`)}`),
65
+ ...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${picocolors_1.default.dim('$')} vike ${c.name.startsWith('-') ? picocolors_1.default.cyan(`${c.name}`) : picocolors_1.default.bold(`${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${picocolors_1.default.dim(`# ${c.desc}`)}`),
66
66
  '',
67
- `Vike settings can be passed over the ${picocolors_1.default.cyan('VIKE_CONFIG')} environment variable or as ${picocolors_1.default.cyan('CLI options')} such as --host.`,
68
- `Vite settings can be passed over the ${picocolors_1.default.cyan('VITE_CONFIG')} environment variable.`,
67
+ 'Common CLI options:',
68
+ [`vike dev ${picocolors_1.default.cyan('--host')}`, `vike dev ${picocolors_1.default.cyan('--port')} 80`, `vike build ${picocolors_1.default.cyan('--mode')} staging`]
69
+ .map((o) => ` ${picocolors_1.default.dim('$')} ${o}`)
70
+ .join('\n'),
71
+ '',
72
+ `More Vike settings can be passed over the ${picocolors_1.default.cyan('VIKE_CONFIG')} environment variable or as ${picocolors_1.default.cyan('CLI options')}.`,
73
+ `More Vite settings can be passed over the ${picocolors_1.default.cyan('VITE_CONFIG')} environment variable.`,
74
+ ``,
69
75
  `See ${picocolors_1.default.underline('https://vike.dev/cli')} for more information.`
70
76
  ].join('\n'));
71
77
  process.exit(1);
@@ -129,8 +129,8 @@ function isPrerenderForceExit() {
129
129
  }
130
130
  function getFullBuildInlineConfig(config) {
131
131
  const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
132
- if (config._viteConfigEnhanced) {
133
- return config._viteConfigEnhanced;
132
+ if (config._viteConfigFromUserEnhanced) {
133
+ return config._viteConfigFromUserEnhanced;
134
134
  }
135
135
  else {
136
136
  return {
@@ -5,14 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.commonConfig = commonConfig;
7
7
  exports.getVikeConfigPublic = getVikeConfigPublic;
8
- const vite_1 = require("vite");
9
8
  const utils_js_1 = require("../utils.js");
10
9
  const pluginBuildConfig_js_1 = require("./build/pluginBuildConfig.js");
11
10
  const require_shim_1 = require("@brillout/require-shim");
12
11
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
12
  const path_1 = __importDefault(require("path"));
14
13
  const assertResolveAlias_js_1 = require("./commonConfig/assertResolveAlias.js");
15
- const getEnvVarObject_js_1 = require("../shared/getEnvVarObject.js");
16
14
  const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
17
15
  const context_js_1 = require("../../api/context.js");
18
16
  const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
@@ -96,10 +94,6 @@ function commonConfig(vikeVitePluginOptions) {
96
94
  // Set `--host` for Docker/Podman
97
95
  setDefault('host', true, configFromUser, configFromVike);
98
96
  }
99
- // VITE_CONFIG
100
- const configFromEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VITE_CONFIG');
101
- if (configFromEnvVar)
102
- configFromVike = (0, vite_1.mergeConfig)(configFromVike, configFromEnvVar);
103
97
  return configFromVike;
104
98
  }
105
99
  }
@@ -133,6 +133,10 @@ const configDefinitionsBuiltIn = {
133
133
  env: { config: true },
134
134
  global: true
135
135
  },
136
+ mode: {
137
+ env: { config: true },
138
+ global: true
139
+ },
136
140
  injectScriptsAt: {
137
141
  env: { server: true }
138
142
  },
@@ -10,6 +10,7 @@ exports.reloadVikeConfig = reloadVikeConfig;
10
10
  exports.isV1Design = isV1Design;
11
11
  exports.getConfVal = getConfVal;
12
12
  exports.getConfigDefinitionOptional = getConfigDefinitionOptional;
13
+ exports.getVikeConfigFromCliOrEnv = getVikeConfigFromCliOrEnv;
13
14
  exports.isOverriden = isOverriden;
14
15
  const utils_js_1 = require("../../../utils.js");
15
16
  const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
@@ -310,7 +311,7 @@ function assertGlobalConfigLocation(configName, sources, plusFilesAll, configDef
310
311
  : 'to a value that is global';
311
312
  const what = isConditionallyGlobal ? 'global values' : picocolors_1.default.cyan(configName);
312
313
  const errEnd = configFilePathsGlobal.length > 0
313
- ? `define ${what} at a global config file such as ${(0, utils_js_1.joinEnglish)(configFilePathsGlobal, 'or')} instead`
314
+ ? `define ${what} at a global config file such as ${(0, utils_js_1.joinEnglish)(configFilePathsGlobal.map(picocolors_1.default.bold), 'or')} instead`
314
315
  : `create a global config file (e.g. /pages/+config.js) and define ${what} there instead`;
315
316
  // When updating this error message => also update error message at https://vike.dev/warning/global-config
316
317
  const errMsg = `${errBeg} ${errMid}: ${errEnd} (https://vike.dev/warning/global-config).`;
@@ -395,15 +396,14 @@ function setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved) {
395
396
  if (apiOperation?.options.vikeConfig) {
396
397
  addSources(apiOperation.options.vikeConfig, { definedBy: 'api', operation: apiOperation.operation }, false);
397
398
  }
399
+ const { configFromCliOptions, configFromEnvVar } = getVikeConfigFromCliOrEnv();
398
400
  // Vike CLI options
399
- const cliOptions = (0, context_js_2.getCliOptions)();
400
- if (cliOptions) {
401
- addSources(cliOptions, { definedBy: 'cli' }, true);
401
+ if (configFromCliOptions) {
402
+ addSources(configFromCliOptions, { definedBy: 'cli' }, true);
402
403
  }
403
404
  // VIKE_CONFIG [highest precedence]
404
- const configFromEnv = (0, getEnvVarObject_js_1.getEnvVarObject)('VIKE_CONFIG');
405
- if (configFromEnv) {
406
- addSources(configFromEnv, { definedBy: 'env' }, false);
405
+ if (configFromEnvVar) {
406
+ addSources(configFromEnvVar, { definedBy: 'env' }, false);
407
407
  }
408
408
  return;
409
409
  function addSources(configValues, definedBy, exitOnError) {
@@ -416,6 +416,19 @@ function setCliAndApiOptions(pageConfigGlobal, configDefinitionsResolved) {
416
416
  });
417
417
  }
418
418
  }
419
+ function getVikeConfigFromCliOrEnv() {
420
+ const configFromCliOptions = (0, context_js_2.getCliOptions)();
421
+ const configFromEnvVar = (0, getEnvVarObject_js_1.getEnvVarObject)('VIKE_CONFIG');
422
+ const vikeConfigFromCliOrEnv = {
423
+ ...configFromCliOptions, // Lower precedence
424
+ ...configFromEnvVar // Higher precedence
425
+ };
426
+ return {
427
+ vikeConfigFromCliOrEnv,
428
+ configFromCliOptions,
429
+ configFromEnvVar
430
+ };
431
+ }
419
432
  function getSourceNonConfigFile(configName, value, definedAt) {
420
433
  (0, utils_js_1.assert)((0, utils_js_1.includes)((0, utils_js_1.objectKeys)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn), configName));
421
434
  const configDef = configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn[configName];
@@ -23,8 +23,15 @@ function parseJson5(valueStr, what) {
23
23
  value = json5_1.default.parse(valueStr);
24
24
  }
25
25
  catch (err) {
26
+ if (isNotJavaScriptLike(valueStr)) {
27
+ // Interpret as string
28
+ return valueStr;
29
+ }
26
30
  console.error(err);
27
31
  (0, utils_js_1.assertUsage)(false, `Cannot parse ${picocolors_1.default.cyan(what)} (see error above) because it's set to the following which isn't a valid JSON5 string: ${picocolors_1.default.bold(valueStr)}`);
28
32
  }
29
33
  return value;
30
34
  }
35
+ function isNotJavaScriptLike(valueStr) {
36
+ return ![':', ',', '{', '}', '(', ')'].some((c) => valueStr.includes(c));
37
+ }
@@ -17,8 +17,8 @@ function resolvePrerenderConfigGlobal(vikeConfig) {
17
17
  };
18
18
  let defaultLocalValue = false;
19
19
  {
20
- const valueFirst = prerenderConfigs.filter((p) => !(0, utils_js_1.isObject)(p) || p.value !== null)[0];
21
- if (valueFirst === true || ((0, utils_js_1.isObject)(valueFirst) && (valueFirst.value ?? defaultValueForObject))) {
20
+ const valueFirst = prerenderConfigs.filter((p) => !(0, utils_js_1.isObject)(p) || p.enable !== null)[0];
21
+ if (valueFirst === true || ((0, utils_js_1.isObject)(valueFirst) && (valueFirst.enable ?? defaultValueForObject))) {
22
22
  defaultLocalValue = true;
23
23
  }
24
24
  }
@@ -49,7 +49,7 @@ function resolvePrerenderConfigLocal(pageConfig) {
49
49
  const values = configValue.value;
50
50
  (0, utils_js_1.assert)((0, utils_js_1.isArray)(values));
51
51
  const value = values[0];
52
- // TODO/now I believe this assert() can fail
52
+ // If it's set to an object in a local config then Vike considers it a global config and it's skipped from local inheritance, thus we can assume the value to be a boolean.
53
53
  (0, utils_js_1.assert)(typeof value === 'boolean');
54
54
  (0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
55
55
  const prerenderConfigLocal = { value };
@@ -76,8 +76,8 @@ async function runPrerenderFromAPI(options = {}) {
76
76
  }
77
77
  async function runPrerenderFromCLIPrerenderCommand() {
78
78
  try {
79
- const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)({}, 'prerender');
80
- await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
79
+ const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)({}, 'prerender');
80
+ await runPrerender({ viteConfig: viteConfigFromUserEnhanced }, '$ vike prerender');
81
81
  }
82
82
  catch (err) {
83
83
  console.error(err);
@@ -342,20 +342,16 @@ async function handlePagesWithStaticRoutes(prerenderContext, globalContext, doNo
342
342
  })));
343
343
  }
344
344
  async function createPageContext(urlOriginal, prerenderContext, globalContext) {
345
- const pageContext = {
345
+ const pageContextInit = { urlOriginal };
346
+ (0, utils_js_1.objectAssign)(pageContextInit, prerenderContext.pageContextInit);
347
+ const pageContext = await (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, globalContext, true, {});
348
+ (0, utils_js_1.assert)(pageContext.isPrerendering === true);
349
+ (0, utils_js_1.objectAssign)(pageContext, {
346
350
  _urlHandler: null,
347
351
  _urlRewrite: null,
348
352
  _noExtraDir: prerenderContext.noExtraDir,
349
353
  _prerenderContext: prerenderContext
350
- };
351
- const pageContextInit = {
352
- urlOriginal
353
- };
354
- (0, utils_js_1.objectAssign)(pageContextInit, prerenderContext.pageContextInit);
355
- {
356
- const pageContextInitEnhanced = await (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, globalContext);
357
- (0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
358
- }
354
+ });
359
355
  return pageContext;
360
356
  }
361
357
  async function callOnPrerenderStartHook(prerenderContext, globalContext) {