vike 0.4.259-commit-a909f04 → 0.4.259-commit-286bd57
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.
- package/dist/node/api/build.js +6 -6
- package/dist/node/api/dev.js +2 -2
- package/dist/node/api/prepareViteApiCall.d.ts +1 -1
- package/dist/node/api/prepareViteApiCall.js +2 -2
- package/dist/node/api/prerender.js +2 -2
- package/dist/node/api/preview.js +2 -2
- package/dist/node/api/{resolveViteConfigFromUser.d.ts → resolveViteConfigUser.d.ts} +5 -5
- package/dist/node/api/{resolveViteConfigFromUser.js → resolveViteConfigUser.js} +75 -78
- package/dist/node/cli/parseCli.js +3 -3
- package/dist/node/createDevMiddleware.js +2 -2
- package/dist/node/prerender/runPrerenderEntry.js +2 -2
- package/dist/node/vite/index.js +2 -2
- package/dist/node/vite/plugins/build/pluginBuildApp.js +2 -2
- package/dist/node/vite/plugins/pluginCommon.d.ts +1 -1
- package/dist/node/vite/plugins/pluginCommon.js +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +4 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +2 -0
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +26 -0
- package/dist/types/Config.d.ts +0 -4
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/pick.d.ts +1 -1
- package/package.json +1 -1
package/dist/node/api/build.js
CHANGED
|
@@ -8,16 +8,16 @@ import './assertEnvApiDev.js';
|
|
|
8
8
|
* https://vike.dev/api#build
|
|
9
9
|
*/
|
|
10
10
|
async function build(options = {}) {
|
|
11
|
-
const {
|
|
11
|
+
const { viteConfigUser } = await prepareViteApiCall(options, 'build');
|
|
12
12
|
// Pass it to vike:build:pluginBuildApp
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
const builder = await createBuilder(
|
|
13
|
+
if (viteConfigUser)
|
|
14
|
+
viteConfigUser._viteConfigUser = viteConfigUser;
|
|
15
|
+
const builder = await createBuilder(viteConfigUser);
|
|
16
16
|
// buildApp() is implemented by vike:build:pluginBuildApp
|
|
17
17
|
await builder.buildApp();
|
|
18
18
|
return {
|
|
19
|
-
/* We don't return `viteConfig` because `
|
|
20
|
-
viteConfig:
|
|
19
|
+
/* We don't return `viteConfig` because `viteConfigUser` is `InlineConfig` not `ResolvedConfig`
|
|
20
|
+
viteConfig: viteConfigUser,
|
|
21
21
|
*/
|
|
22
22
|
};
|
|
23
23
|
}
|
package/dist/node/api/dev.js
CHANGED
|
@@ -15,8 +15,8 @@ assertIsNotProductionRuntime();
|
|
|
15
15
|
* https://vike.dev/api#dev
|
|
16
16
|
*/
|
|
17
17
|
async function dev(options = {}) {
|
|
18
|
-
const {
|
|
19
|
-
const server = await createServer(
|
|
18
|
+
const { viteConfigUser } = await prepareViteApiCall(options, 'dev');
|
|
19
|
+
const server = await createServer(viteConfigUser);
|
|
20
20
|
const viteServer = server;
|
|
21
21
|
const viteConfig = server.config;
|
|
22
22
|
const viteVersion = viteConfig._viteVersionResolved;
|
|
@@ -3,5 +3,5 @@ import type { ApiOptions, ApiOperation } from './types.js';
|
|
|
3
3
|
import './assertEnvApiDevAndProd.js';
|
|
4
4
|
declare function prepareViteApiCall(options: ApiOptions, operation: ApiOperation): Promise<{
|
|
5
5
|
viteConfigResolved: import("vite").ResolvedConfig;
|
|
6
|
-
|
|
6
|
+
viteConfigUser: import("vite").UserConfig;
|
|
7
7
|
}>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { prepareViteApiCall };
|
|
2
2
|
import { clearContextVikeApiOperation, setContextVikeApiOperation } from '../../shared-server-node/api-context.js';
|
|
3
3
|
import { clearGlobalContext } from '../../server/runtime/globalContext.js';
|
|
4
|
-
import {
|
|
4
|
+
import { resolveViteConfigUser } from './resolveViteConfigUser.js';
|
|
5
5
|
import './assertEnvApiDevAndProd.js';
|
|
6
6
|
async function prepareViteApiCall(options, operation) {
|
|
7
7
|
clear();
|
|
8
8
|
setContextVikeApiOperation(operation, options);
|
|
9
|
-
return
|
|
9
|
+
return resolveViteConfigUser();
|
|
10
10
|
}
|
|
11
11
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
12
12
|
function clear() {
|
|
@@ -8,8 +8,8 @@ import './assertEnvApiDevAndProd.js';
|
|
|
8
8
|
* https://vike.dev/api#prerender
|
|
9
9
|
*/
|
|
10
10
|
async function prerender(options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
options.viteConfig =
|
|
11
|
+
const { viteConfigUser } = await prepareViteApiCall(options, 'prerender');
|
|
12
|
+
options.viteConfig = viteConfigUser;
|
|
13
13
|
const { viteConfig } = await runPrerenderFromAPI(options);
|
|
14
14
|
return {
|
|
15
15
|
viteConfig,
|
package/dist/node/api/preview.js
CHANGED
|
@@ -19,7 +19,7 @@ import { getStartupLogFirstLine } from './getStartupLogFirstLine.js';
|
|
|
19
19
|
*/
|
|
20
20
|
async function preview(options = {}) {
|
|
21
21
|
onSetupPreview();
|
|
22
|
-
const {
|
|
22
|
+
const { viteConfigUser, viteConfigResolved } = await prepareViteApiCall(options, 'preview');
|
|
23
23
|
const vikeConfig = await getVikeConfigInternal();
|
|
24
24
|
const cliPreviewConfig = await resolveCliPreviewConfig(vikeConfig);
|
|
25
25
|
assertUsage(cliPreviewConfig !== false, `${pc.cyan('$ vike preview')} isn't supported`);
|
|
@@ -53,7 +53,7 @@ async function preview(options = {}) {
|
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
// Use Vite's preview server
|
|
56
|
-
const server = await previewVite(
|
|
56
|
+
const server = await previewVite(viteConfigUser);
|
|
57
57
|
logHint(vikeConfig.prerenderContext.isPrerenderingEnabledForAllPages
|
|
58
58
|
? ' — your app is fully pre-rendered and can be statically deployed.'
|
|
59
59
|
: '', isStartupLogCompact);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { resolveViteConfigUser };
|
|
2
|
+
export { isResolvingViteConfigUser };
|
|
3
3
|
export { getVikeConfigInternalEarly };
|
|
4
4
|
export { getViteRoot };
|
|
5
5
|
export { assertViteRoot };
|
|
6
6
|
export { normalizeViteRoot };
|
|
7
7
|
import type { ResolvedConfig, UserConfig } from 'vite';
|
|
8
8
|
import './assertEnvApiDevAndProd.js';
|
|
9
|
-
declare function
|
|
9
|
+
declare function resolveViteConfigUser(): Promise<{
|
|
10
10
|
viteConfigResolved: ResolvedConfig;
|
|
11
|
-
|
|
11
|
+
viteConfigUser: UserConfig;
|
|
12
12
|
}>;
|
|
13
13
|
declare function getVikeConfigInternalEarly(): Promise<import("../vite/shared/resolveVikeConfigInternal.js").VikeConfigInternal>;
|
|
14
|
-
declare function
|
|
14
|
+
declare function isResolvingViteConfigUser(): boolean | undefined;
|
|
15
15
|
declare function getViteRoot(viteContext: ViteContext): Promise<string>;
|
|
16
16
|
type ViteContext = 'build' | 'preview' | 'dev';
|
|
17
17
|
declare function normalizeViteRoot(root: string): string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { resolveViteConfigUser };
|
|
2
|
+
export { isResolvingViteConfigUser };
|
|
3
3
|
export { getVikeConfigInternalEarly };
|
|
4
4
|
export { getViteRoot };
|
|
5
5
|
export { assertViteRoot };
|
|
6
6
|
export { normalizeViteRoot };
|
|
7
7
|
import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
|
|
8
|
-
import { getVikeConfigInternal, getVikeConfigFromCliOrEnv, setVikeConfigContext, isVikeConfigContextSet, } from '../vite/shared/resolveVikeConfigInternal.js';
|
|
8
|
+
import { getVikeConfigInternal, getVikeConfigFromCliOrEnv, setVikeConfigContext, isVikeConfigContextSet, EARLY_SETTINGS, } from '../vite/shared/resolveVikeConfigInternal.js';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import { assert, assertUsage, assertWarning } from '../../utils/assert.js';
|
|
11
11
|
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
@@ -16,92 +16,95 @@ import { getEnvVarObject } from '../vite/shared/getEnvVarObject.js';
|
|
|
16
16
|
import { getVikeApiOperation, isVikeCliOrApi } from '../../shared-server-node/api-context.js';
|
|
17
17
|
import { getViteCliCommand, getViteCliArgs } from '../vite/shared/isViteCli.js';
|
|
18
18
|
import './assertEnvApiDevAndProd.js';
|
|
19
|
-
const globalObject = getGlobalObject('
|
|
20
|
-
async function
|
|
19
|
+
const globalObject = getGlobalObject('resolveViteConfigUser.ts', {});
|
|
20
|
+
async function resolveViteConfigUser() {
|
|
21
21
|
const { viteContext } = getVikeApiContext();
|
|
22
22
|
assert(viteContext);
|
|
23
|
-
const
|
|
24
|
-
const {
|
|
25
|
-
const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteConfigFromUserResolved, viteContext);
|
|
23
|
+
const { viteConfigUser, root } = await resolve(viteContext);
|
|
24
|
+
const { viteConfigResolved } = await assertViteRoot2(root, viteConfigUser, viteContext);
|
|
26
25
|
return {
|
|
27
26
|
viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
|
|
28
|
-
|
|
27
|
+
viteConfigUser,
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
30
|
async function getVikeConfigInternalEarly() {
|
|
32
|
-
assert(!globalObject.
|
|
31
|
+
assert(!globalObject.isResolvingViteConfigUser); // ensure no infinite loop
|
|
33
32
|
if (!isVikeConfigContextSet()) {
|
|
34
33
|
const viteContext = getViteContext();
|
|
35
|
-
const
|
|
36
|
-
setVikeConfigContext_(
|
|
34
|
+
const resolved = await resolve(viteContext);
|
|
35
|
+
setVikeConfigContext_(resolved, viteContext);
|
|
37
36
|
}
|
|
38
37
|
return await getVikeConfigInternal();
|
|
39
38
|
}
|
|
40
|
-
function setVikeConfigContext_(
|
|
39
|
+
function setVikeConfigContext_(resolved, viteContext) {
|
|
41
40
|
setVikeConfigContext({
|
|
42
|
-
userRootDir:
|
|
41
|
+
userRootDir: resolved.root,
|
|
43
42
|
isDev: viteContext === 'dev',
|
|
44
|
-
vikeVitePluginOptions:
|
|
43
|
+
vikeVitePluginOptions: resolved.vikeVitePluginOptions,
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
function
|
|
48
|
-
return globalObject.
|
|
46
|
+
function isResolvingViteConfigUser() {
|
|
47
|
+
return globalObject.isResolvingViteConfigUser;
|
|
49
48
|
}
|
|
50
49
|
async function getViteRoot(viteContext) {
|
|
51
50
|
if (!globalObject.root)
|
|
52
|
-
await
|
|
51
|
+
await resolve(viteContext);
|
|
53
52
|
assert(globalObject.root);
|
|
54
53
|
return globalObject.root;
|
|
55
54
|
}
|
|
56
|
-
async function
|
|
57
|
-
const { viteConfigFromUserVikeApiOptions } = getVikeApiContext();
|
|
58
|
-
let viteConfigFromUserResolved = clone(viteConfigFromUserVikeApiOptions ?? {});
|
|
55
|
+
async function resolve(viteContext) {
|
|
59
56
|
// Precedence:
|
|
60
|
-
// 1. (highest precedence) |
|
|
61
|
-
// 2. |
|
|
62
|
-
// 3. |
|
|
63
|
-
// 4. |
|
|
64
|
-
// 5. (lowest precedence) |
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
// 1. (highest precedence) | viteConfigFromViteEnv | VITE_CONFIG
|
|
58
|
+
// 2. | viteConfigFromVikeCliOrEnv | VIKE_CONFIG & Vike CLI options — `+mode` & `+root`
|
|
59
|
+
// 3. | viteConfigFromViteCli | Vite CLI args — `[root]` & `-c/--config`
|
|
60
|
+
// 4. | viteConfigFromVikeApi | Vike API options — `viteConfig`, and `+mode` & `+root` from `vikeConfig`
|
|
61
|
+
// 5. (lowest precedence) | viteConfigFromViteFile | vite.config.js
|
|
62
|
+
let viteConfigUser = {};
|
|
63
|
+
const addConfig = (c) => {
|
|
64
|
+
// Merge `c` overriding viteConfigUser (`c` wins — higher precedence)
|
|
65
|
+
viteConfigUser = mergeConfig(viteConfigUser, c ?? {});
|
|
66
|
+
};
|
|
67
|
+
const underride = (c) => {
|
|
68
|
+
// Merge `c` underiding viteConfigUser (`c` loses — lower precedence)
|
|
69
|
+
return mergeConfig(c ?? {}, viteConfigUser);
|
|
70
|
+
};
|
|
71
|
+
// Vike API args
|
|
72
|
+
{
|
|
73
|
+
const { viteConfigFromVikeApi, vikeConfigFromApi } = getVikeApiContext();
|
|
74
|
+
addConfig(viteConfigFromVikeApi); // `viteConfig`
|
|
75
|
+
addConfig(pick(vikeConfigFromApi ?? {}, EARLY_SETTINGS)); // `+mode` & `+root`
|
|
71
76
|
}
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// +config.js files (so it can't be defined inside +config.js itself), and +mode affects which
|
|
75
|
-
// vite.config.js environment is loaded. That's why — unlike +host/+port/+force which are applied
|
|
76
|
-
// later from the resolved Vike config — they're read here from Vike's CLI options & VIKE_CONFIG only.
|
|
77
|
+
// Vite CLI args (when invoked via Vite's CLI rather than Vike's API).
|
|
78
|
+
// - Without this, Vike loads vite.config.js blind to `vite [root]` / `-c <file>` and ends up with the wrong root when those Vite CLI args are used.
|
|
77
79
|
{
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
'root',
|
|
81
|
-
]);
|
|
82
|
-
if (Object.keys(viteConfigFromUserVikeSettings).length > 0) {
|
|
83
|
-
viteConfigFromUserResolved = merge(viteConfigFromUserResolved ?? {}, viteConfigFromUserVikeSettings);
|
|
84
|
-
}
|
|
80
|
+
const viteConfigFromViteCli = getViteCliArgs();
|
|
81
|
+
addConfig(viteConfigFromViteCli);
|
|
85
82
|
}
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
// Vike's CLI and VIKE_CONFIG — `+mode` & `+root`
|
|
84
|
+
{
|
|
85
|
+
const viteConfigFromVikeCliOrEnv = pick(getVikeConfigFromCliOrEnv().vikeConfigFromCliOrEnv, EARLY_SETTINGS);
|
|
86
|
+
addConfig(viteConfigFromVikeCliOrEnv);
|
|
90
87
|
}
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
// VITE_CONFIG
|
|
89
|
+
{
|
|
90
|
+
const viteConfigFromViteEnv = getEnvVarObject('VITE_CONFIG');
|
|
91
|
+
addConfig(viteConfigFromViteEnv);
|
|
92
|
+
}
|
|
93
|
+
// vite.config.js — lowest precedence. Merged into a *separate* result (used only to compute `root` and to
|
|
94
|
+
// find the Vike plugin): it must not flow back into `viteConfigUser`, which is handed to Vite —
|
|
95
|
+
// Vite loads vite.config.js itself, so merging it here would add the Vike plugin twice.
|
|
96
|
+
// Replicates Vite: https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1001
|
|
97
|
+
globalObject.isResolvingViteConfigUser = true;
|
|
98
|
+
const viteConfigFromViteFile = await loadViteConfigFile(viteConfigUser, viteContext);
|
|
99
|
+
globalObject.isResolvingViteConfigUser = false;
|
|
100
|
+
const viteConfigAll = underride(viteConfigFromViteFile ?? {});
|
|
101
|
+
const root = normalizeViteRoot(viteConfigAll.root ?? process.cwd());
|
|
99
102
|
globalObject.root = root;
|
|
100
103
|
// - Find options `vike(options)` set in vite.config.js
|
|
101
104
|
// - TO-DO/next-major-release: remove
|
|
102
105
|
// - Add Vike's Vite plugin if missing
|
|
103
106
|
let vikeVitePluginOptions;
|
|
104
|
-
const found = findVikeVitePlugin(
|
|
107
|
+
const found = findVikeVitePlugin(viteConfigAll);
|
|
105
108
|
if (found) {
|
|
106
109
|
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
107
110
|
}
|
|
@@ -109,28 +112,21 @@ async function getViteInfo(viteContext) {
|
|
|
109
112
|
// Show a warning because Vike supports Vite's CLI (as well as third-party CLIs).
|
|
110
113
|
// - Encourage users to define a vite.config.js file that also works with Vite's CLI (and potentially other third-party CLIs).
|
|
111
114
|
// - Vike-based frameworks, such as DocPress, allow their users to omit defining a vite.config.js file.
|
|
112
|
-
assertWarning(!
|
|
115
|
+
assertWarning(!viteConfigFromViteFile, // Only show the warning if the user defined a vite.config.js file
|
|
113
116
|
"Omitting Vike's Vite plugin (inside your vite.config.js) is deprecated — make sure to always add Vike's Vite plugin https://vike.dev/vite-plugin", { onlyOnce: true });
|
|
114
117
|
// Add Vike to plugins if not present.
|
|
115
118
|
// 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.
|
|
116
119
|
const { plugin: vikePlugin } = await import('../vite/index.js');
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
plugins: [...(
|
|
120
|
+
viteConfigUser = {
|
|
121
|
+
...viteConfigUser,
|
|
122
|
+
plugins: [...(viteConfigUser?.plugins ?? []), vikePlugin()],
|
|
120
123
|
};
|
|
121
|
-
const res = findVikeVitePlugin(
|
|
124
|
+
const res = findVikeVitePlugin(viteConfigUser);
|
|
122
125
|
assert(res);
|
|
123
126
|
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
124
127
|
}
|
|
125
128
|
assert(vikeVitePluginOptions);
|
|
126
|
-
return { root, vikeVitePluginOptions
|
|
127
|
-
}
|
|
128
|
-
/** `c2` overrides `c1` */
|
|
129
|
-
function merge(c1, c2) {
|
|
130
|
-
return mergeConfig(c1, c2);
|
|
131
|
-
}
|
|
132
|
-
function clone(c) {
|
|
133
|
-
return mergeConfig({}, c);
|
|
129
|
+
return { viteConfigUser, root, vikeVitePluginOptions };
|
|
134
130
|
}
|
|
135
131
|
function findVikeVitePlugin(viteConfig) {
|
|
136
132
|
let vikeVitePluginOptions;
|
|
@@ -148,8 +144,8 @@ function findVikeVitePlugin(viteConfig) {
|
|
|
148
144
|
return { vikeVitePluginOptions };
|
|
149
145
|
}
|
|
150
146
|
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
151
|
-
async function loadViteConfigFile(
|
|
152
|
-
const viteContextResolved = resolveViteContext(
|
|
147
|
+
async function loadViteConfigFile(viteConfigUser, viteContext) {
|
|
148
|
+
const viteContextResolved = resolveViteContext(viteConfigUser, viteContext);
|
|
153
149
|
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = viteContextResolved;
|
|
154
150
|
let config = inlineConfig;
|
|
155
151
|
let mode = inlineConfig.mode || defaultMode;
|
|
@@ -205,11 +201,12 @@ function getViteContextWithOperation(operation) {
|
|
|
205
201
|
function getVikeApiContext() {
|
|
206
202
|
const vikeApiOperation = getVikeApiOperation();
|
|
207
203
|
if (!vikeApiOperation)
|
|
208
|
-
return {
|
|
204
|
+
return { viteConfigFromVikeApi: null, vikeConfigFromApi: null, viteContext: null };
|
|
209
205
|
const { options, operation } = vikeApiOperation;
|
|
210
|
-
const
|
|
206
|
+
const viteConfigFromVikeApi = options.viteConfig;
|
|
207
|
+
const vikeConfigFromApi = options.vikeConfig;
|
|
211
208
|
const viteContext = getViteContextWithOperation(operation);
|
|
212
|
-
return {
|
|
209
|
+
return { viteConfigFromVikeApi, vikeConfigFromApi, viteContext };
|
|
213
210
|
}
|
|
214
211
|
function resolveViteContext(inlineConfig = {}, viteContext) {
|
|
215
212
|
const isBuild = viteContext === 'build';
|
|
@@ -222,15 +219,15 @@ function resolveViteContext(inlineConfig = {}, viteContext) {
|
|
|
222
219
|
return viteContextResolved;
|
|
223
220
|
}
|
|
224
221
|
function normalizeViteRoot(root) {
|
|
225
|
-
// `path.resolve(
|
|
222
|
+
// `path.resolve(viteConfigUserViteFile.configFile, root)` could be more intuitive than `path.resolve(process.cwd(), root)` but we replicate Vite's behavior (`vite.config.js` should follow Vite's API), see:
|
|
226
223
|
// https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1063
|
|
227
224
|
return toPosixPath(
|
|
228
225
|
// Equivalent to `path.resolve(process.cwd(), root)`
|
|
229
226
|
path.resolve(root));
|
|
230
227
|
}
|
|
231
228
|
const errMsg = `A Vite plugin is modifying the Vite setting ${pc.cyan('root')} which is forbidden`;
|
|
232
|
-
async function assertViteRoot2(root,
|
|
233
|
-
const viteContextResolved = resolveViteContext(
|
|
229
|
+
async function assertViteRoot2(root, viteConfigUser, viteContext) {
|
|
230
|
+
const viteContextResolved = resolveViteContext(viteConfigUser, viteContext);
|
|
234
231
|
// We can eventually remove 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 and preview which is required). But let's keep it for now, just to see whether calling resolveConfig() can be problematic.
|
|
235
232
|
const viteConfigResolved = await resolveConfig(...viteContextResolved);
|
|
236
233
|
assertUsage(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
|
|
@@ -78,10 +78,10 @@ function showHelp() {
|
|
|
78
78
|
'Common CLI options:',
|
|
79
79
|
[
|
|
80
80
|
`vike dev ${pc.cyan('--host')} ${TAB}${pc.dim('# Make server available over LAN and public addresses')}`,
|
|
81
|
-
`vike dev ${pc.cyan('--port')} 80 ${TAB}${pc.dim('#
|
|
82
|
-
`vike build ${pc.cyan('--mode')} staging${TAB}${pc.dim('# Set
|
|
81
|
+
`vike dev ${pc.cyan('--port')} 80 ${TAB}${pc.dim('# Set server port')}`,
|
|
82
|
+
`vike build ${pc.cyan('--mode')} staging${TAB}${pc.dim('# Set mode (e.g. development, production, staging)')}`,
|
|
83
83
|
`vike dev ${pc.cyan('--force')} ${TAB}${pc.dim("# Disable Vite's cache")}`,
|
|
84
|
-
`vike dev ${pc.cyan('--root')} src ${TAB}${pc.dim('# Set
|
|
84
|
+
`vike dev ${pc.cyan('--root')} src ${TAB}${pc.dim('# Set project root directory')}`,
|
|
85
85
|
]
|
|
86
86
|
.map((o) => ` ${pc.dim('$')} ${o}`)
|
|
87
87
|
.join('\n'),
|
|
@@ -18,8 +18,8 @@ async function createDevMiddleware(options = {}) {
|
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
|
-
const {
|
|
22
|
-
const server = await createServer(
|
|
21
|
+
const { viteConfigUser } = await prepareViteApiCall(optionsMod, 'dev');
|
|
22
|
+
const server = await createServer(viteConfigUser);
|
|
23
23
|
const devMiddleware = server.middlewares;
|
|
24
24
|
return { devMiddleware, viteServer: server, viteConfig: server.config };
|
|
25
25
|
}
|
|
@@ -19,8 +19,8 @@ async function runPrerenderFromAPI(options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
async function runPrerenderFromCLIPrerenderCommand() {
|
|
21
21
|
try {
|
|
22
|
-
const {
|
|
23
|
-
await runPrerender({ viteConfig:
|
|
22
|
+
const { viteConfigUser } = await prepareViteApiCall({}, 'prerender');
|
|
23
|
+
await runPrerender({ viteConfig: viteConfigUser }, '$ vike prerender');
|
|
24
24
|
}
|
|
25
25
|
catch (err) {
|
|
26
26
|
// Error may come from user-land
|
package/dist/node/vite/index.js
CHANGED
|
@@ -37,7 +37,7 @@ import { pluginReplaceConstantsNonRunnableDev } from './plugins/non-runnable-dev
|
|
|
37
37
|
import { isVikeCliOrApi } from '../../shared-server-node/api-context.js';
|
|
38
38
|
import { pluginViteConfigVikeExtensions } from './plugins/pluginViteConfigVikeExtensions.js';
|
|
39
39
|
import { pluginStripPointerImportAttribute } from './plugins/pluginStripPointerImportAttribute.js';
|
|
40
|
-
import { getVikeConfigInternalEarly,
|
|
40
|
+
import { getVikeConfigInternalEarly, isResolvingViteConfigUser } from '../api/resolveViteConfigUser.js';
|
|
41
41
|
import './assertEnvVite.js';
|
|
42
42
|
import { isStorybook } from '../../utils/isStorybook.js';
|
|
43
43
|
import { pluginUniversalDeploy } from './plugins/pluginUniversalDeploy.js';
|
|
@@ -96,7 +96,7 @@ function pluginNonRunnabeDev() {
|
|
|
96
96
|
}
|
|
97
97
|
function removeVitePlugin() {
|
|
98
98
|
// Early resolving of user Vite configs
|
|
99
|
-
if (
|
|
99
|
+
if (isResolvingViteConfigUser()) {
|
|
100
100
|
return true;
|
|
101
101
|
}
|
|
102
102
|
// *****************/
|
|
@@ -166,8 +166,8 @@ function isPrerenderForceExit() {
|
|
|
166
166
|
}
|
|
167
167
|
function getFullBuildInlineConfig(config) {
|
|
168
168
|
const configFromCli = !isViteCli() ? null : getViteBuildCliArgs();
|
|
169
|
-
if (config.
|
|
170
|
-
return config.
|
|
169
|
+
if (config._viteConfigUser) {
|
|
170
|
+
return config._viteConfigUser;
|
|
171
171
|
}
|
|
172
172
|
else {
|
|
173
173
|
return {
|
|
@@ -9,7 +9,7 @@ import { assertRollupInput } from './build/pluginBuildConfig.js';
|
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
|
|
11
11
|
import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
|
|
12
|
-
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/
|
|
12
|
+
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigUser.js';
|
|
13
13
|
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
14
14
|
import { version as viteVersionVike } from 'vite';
|
|
15
15
|
import '../assertEnvVite.js';
|
|
@@ -198,7 +198,9 @@ const metaBuiltIn = {
|
|
|
198
198
|
mode: {
|
|
199
199
|
env: { config: true },
|
|
200
200
|
global: true,
|
|
201
|
+
/* +mode can't be set in +config.js => a +config.js change never affects it — no Vite restart needed
|
|
201
202
|
vite: true,
|
|
203
|
+
*/
|
|
202
204
|
},
|
|
203
205
|
force: {
|
|
204
206
|
env: { config: true },
|
|
@@ -208,7 +210,9 @@ const metaBuiltIn = {
|
|
|
208
210
|
root: {
|
|
209
211
|
env: { config: true },
|
|
210
212
|
global: true,
|
|
213
|
+
/* +root can't be set in +config.js => a +config.js change never affects it — no Vite restart needed
|
|
211
214
|
vite: true,
|
|
215
|
+
*/
|
|
212
216
|
},
|
|
213
217
|
csp: {
|
|
214
218
|
env: { server: true },
|
|
@@ -9,6 +9,7 @@ export { isV1Design };
|
|
|
9
9
|
export { getConfVal };
|
|
10
10
|
export { getConfigDefinitionOptional };
|
|
11
11
|
export { getVikeConfigFromCliOrEnv };
|
|
12
|
+
export { EARLY_SETTINGS };
|
|
12
13
|
export type { VikeConfigInternal };
|
|
13
14
|
export type { PageConfigBuildTimeBeforeComputed };
|
|
14
15
|
import type { PageConfigGlobalBuildTime, ConfigEnv, PageConfigBuildTime, DefinedAtFilePath } from '../../../types/PageConfig.js';
|
|
@@ -62,6 +63,7 @@ declare function getVikeConfigFromCliOrEnv(): {
|
|
|
62
63
|
configFromCliOptions: import("../../cli/parseCli.js").CliOptions | null;
|
|
63
64
|
configFromEnvVar: Record<string, unknown> | null;
|
|
64
65
|
};
|
|
66
|
+
declare const EARLY_SETTINGS: readonly ["root", "mode"];
|
|
65
67
|
type PageConfigBuildTimeBeforeComputed = Omit<PageConfigBuildTime, 'configValuesComputed'>;
|
|
66
68
|
declare function getConfigDefinitionOptional(configDefinitions: ConfigDefinitionsInternal, configName: string): {
|
|
67
69
|
env: ConfigEnv;
|
|
@@ -10,6 +10,7 @@ export { isV1Design };
|
|
|
10
10
|
export { getConfVal };
|
|
11
11
|
export { getConfigDefinitionOptional };
|
|
12
12
|
export { getVikeConfigFromCliOrEnv };
|
|
13
|
+
export { EARLY_SETTINGS };
|
|
13
14
|
import { deepEqual } from '../../../utils/deepEqual.js';
|
|
14
15
|
import { assertKeys } from '../../../utils/assertKeys.js';
|
|
15
16
|
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
@@ -220,6 +221,7 @@ async function resolveVikeConfigInternal(userRootDir, vikeVitePluginOptions, esb
|
|
|
220
221
|
// Backwards compatibility for vike(options) in vite.config.js
|
|
221
222
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
222
223
|
setCliAndApiOptions(pageConfigGlobal, pageConfigs, configDefinitionsResolved);
|
|
224
|
+
warnEarlySettingsInConfigFile(pageConfigGlobal);
|
|
223
225
|
const globalConfigPublic = resolveGlobalConfig(pageConfigGlobal, pageConfigs);
|
|
224
226
|
const prerenderContext = await resolvePrerenderContext({
|
|
225
227
|
config: globalConfigPublic.config,
|
|
@@ -536,6 +538,30 @@ function getSourceNonConfigFile(configName, value, definedAt, configDefinitionsG
|
|
|
536
538
|
};
|
|
537
539
|
return source;
|
|
538
540
|
}
|
|
541
|
+
// Settings that must be resolved early before Vike crawls +config.js files:
|
|
542
|
+
// - They can't be defined inside +config.js files.
|
|
543
|
+
// - They must be set early (via Vike's CLI/API options or VIKE_CONFIG), and read early before Vike's main config resolution.
|
|
544
|
+
const EARLY_SETTINGS = [
|
|
545
|
+
// +root determines where Vike looks for +config.js files (so it can't be defined inside +config.js itself)
|
|
546
|
+
'root',
|
|
547
|
+
// +mode affects which vite.config.js environment is loaded
|
|
548
|
+
'mode',
|
|
549
|
+
];
|
|
550
|
+
function warnEarlySettingsInConfigFile(pageConfigGlobal) {
|
|
551
|
+
for (const configName of EARLY_SETTINGS) {
|
|
552
|
+
const sources = pageConfigGlobal.configValueSources[configName];
|
|
553
|
+
if (!sources)
|
|
554
|
+
continue;
|
|
555
|
+
for (const source of sources) {
|
|
556
|
+
if (!source.plusFile) {
|
|
557
|
+
// `plusFile === null` => source comes from Vike CLI argument, Vike API option, or VIKE_CONFIG
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
const configDefinedAt = getConfigDefinedAt('Config', configName, source.definedAt);
|
|
561
|
+
assertWarning(false, `${configDefinedAt} has no effect: it can't be set from a ${pc.cyan('+')} file — see ${pc.underline(`https://vike.dev/${configName}`)}`, { onlyOnce: true });
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
539
565
|
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
540
566
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
541
567
|
sources
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -492,10 +492,6 @@ type ConfigBuiltIn = {
|
|
|
492
492
|
/**
|
|
493
493
|
* The root directory of your project.
|
|
494
494
|
*
|
|
495
|
-
* Can be an absolute path, or a path relative to the current working directory.
|
|
496
|
-
*
|
|
497
|
-
* @default process.cwd()
|
|
498
|
-
*
|
|
499
495
|
* https://vike.dev/root
|
|
500
496
|
*/
|
|
501
497
|
root?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.259-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.259-commit-286bd57";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.259-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.259-commit-286bd57';
|
package/dist/utils/pick.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function pick<Obj extends object, Keys extends keyof Obj>(obj: Obj, keys: Keys[]): Pick<Obj, Keys>;
|
|
1
|
+
export declare function pick<Obj extends object, Keys extends keyof Obj>(obj: Obj, keys: readonly Keys[]): Pick<Obj, Keys>;
|