vike 0.4.259-commit-dcc116b → 0.4.259-commit-9fc8a01
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} +82 -73
- 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 +15 -7
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/debug.d.ts +1 -1
- package/dist/utils/debug.js +1 -0
- 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,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { resolveViteConfigUser };
|
|
2
|
+
export { isResolvingViteConfigUser };
|
|
3
3
|
export { getVikeConfigInternalEarly };
|
|
4
4
|
export { getViteRoot };
|
|
5
5
|
export { assertViteRoot };
|
|
@@ -8,6 +8,7 @@ import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
|
|
|
8
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
|
+
import { createDebug } from '../../utils/debug.js';
|
|
11
12
|
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
12
13
|
import { pick } from '../../utils/pick.js';
|
|
13
14
|
import { toPosixPath } from '../../utils/path.js';
|
|
@@ -16,96 +17,106 @@ import { getEnvVarObject } from '../vite/shared/getEnvVarObject.js';
|
|
|
16
17
|
import { getVikeApiOperation, isVikeCliOrApi } from '../../shared-server-node/api-context.js';
|
|
17
18
|
import { getViteCliCommand, getViteCliArgs } from '../vite/shared/isViteCli.js';
|
|
18
19
|
import './assertEnvApiDevAndProd.js';
|
|
19
|
-
const globalObject = getGlobalObject('
|
|
20
|
-
|
|
20
|
+
const globalObject = getGlobalObject('resolveViteConfigUser.ts', {});
|
|
21
|
+
const debug = createDebug('vike:vite-config-user');
|
|
22
|
+
async function resolveViteConfigUser() {
|
|
21
23
|
const { viteContext } = getVikeApiContext();
|
|
22
24
|
assert(viteContext);
|
|
23
|
-
const
|
|
24
|
-
const {
|
|
25
|
-
const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteConfigFromUserResolved, viteContext);
|
|
25
|
+
const { viteConfigUser, root } = await resolve(viteContext);
|
|
26
|
+
const { viteConfigResolved } = await assertViteRoot2(root, viteConfigUser, viteContext);
|
|
26
27
|
return {
|
|
27
28
|
viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
|
|
28
|
-
|
|
29
|
+
viteConfigUser,
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
async function getVikeConfigInternalEarly() {
|
|
32
|
-
assert(!globalObject.
|
|
33
|
+
assert(!globalObject.isResolvingViteConfigUser); // ensure no infinite loop
|
|
33
34
|
if (!isVikeConfigContextSet()) {
|
|
34
35
|
const viteContext = getViteContext();
|
|
35
|
-
const
|
|
36
|
-
setVikeConfigContext_(
|
|
36
|
+
const resolved = await resolve(viteContext);
|
|
37
|
+
setVikeConfigContext_(resolved, viteContext);
|
|
37
38
|
}
|
|
38
39
|
return await getVikeConfigInternal();
|
|
39
40
|
}
|
|
40
|
-
function setVikeConfigContext_(
|
|
41
|
+
function setVikeConfigContext_(resolved, viteContext) {
|
|
41
42
|
setVikeConfigContext({
|
|
42
|
-
userRootDir:
|
|
43
|
+
userRootDir: resolved.root,
|
|
43
44
|
isDev: viteContext === 'dev',
|
|
44
|
-
vikeVitePluginOptions:
|
|
45
|
+
vikeVitePluginOptions: resolved.vikeVitePluginOptions,
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
|
-
function
|
|
48
|
-
return globalObject.
|
|
48
|
+
function isResolvingViteConfigUser() {
|
|
49
|
+
return globalObject.isResolvingViteConfigUser;
|
|
49
50
|
}
|
|
50
51
|
async function getViteRoot(viteContext) {
|
|
51
52
|
if (!globalObject.root)
|
|
52
|
-
await
|
|
53
|
+
await resolve(viteContext);
|
|
53
54
|
assert(globalObject.root);
|
|
54
55
|
return globalObject.root;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
// TODO rename_all viteConfigFromUser viteConfigFrom
|
|
58
|
-
// TODO rename_all vikeConfigFromUser vikeConfigFrom
|
|
59
|
-
async function getViteInfo(viteContext) {
|
|
57
|
+
async function resolve(viteContext) {
|
|
60
58
|
// Precedence:
|
|
61
|
-
// 1. (highest precedence) |
|
|
62
|
-
// 2. | viteConfigFromVikeCliOrEnv
|
|
63
|
-
// 3. |
|
|
64
|
-
// 4. |
|
|
65
|
-
// 5. (lowest precedence) |
|
|
66
|
-
let
|
|
59
|
+
// 1. (highest precedence) | viteConfigFromViteEnv | VITE_CONFIG
|
|
60
|
+
// 2. | viteConfigFromVikeCliOrEnv | VIKE_CONFIG & Vike CLI options — `+mode` & `+root`
|
|
61
|
+
// 3. | viteConfigFromViteCli | Vite CLI args — `[root]` & `-c/--config`
|
|
62
|
+
// 4. | viteConfigFromVikeApi | Vike API options — `viteConfig`, and `+mode` & `+root` from `vikeConfig`
|
|
63
|
+
// 5. (lowest precedence) | viteConfigFromViteFile | vite.config.js
|
|
64
|
+
let viteConfigUser = {};
|
|
65
|
+
const addConfig = (c) => {
|
|
66
|
+
// Merge `c` overriding viteConfigUser (`c` wins — higher precedence)
|
|
67
|
+
viteConfigUser = mergeConfig(viteConfigUser, c ?? {});
|
|
68
|
+
};
|
|
69
|
+
const underride = (c) => {
|
|
70
|
+
// Merge `c` underiding viteConfigUser (`c` loses — lower precedence)
|
|
71
|
+
return mergeConfig(c ?? {}, viteConfigUser);
|
|
72
|
+
};
|
|
67
73
|
// Vike API args
|
|
68
|
-
const { viteConfigFromUserVikeApiOptions, vikeConfigFromUserVikeApiOptions } = getVikeApiContext();
|
|
69
|
-
// - Resolve `viteConfig` set over Vike's API
|
|
70
|
-
viteConfigFromUserResolved = merge(viteConfigFromUserResolved, viteConfigFromUserVikeApiOptions ?? {});
|
|
71
|
-
// - Resolve +mode/+root set over Vike's API
|
|
72
74
|
{
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
+
const { viteConfigFromVikeApi, vikeConfigFromApi } = getVikeApiContext();
|
|
76
|
+
addConfig(viteConfigFromVikeApi); // `viteConfig`
|
|
77
|
+
addConfig(pick(vikeConfigFromApi ?? {}, EARLY_SETTINGS)); // `+mode` & `+root`
|
|
78
|
+
if (debug.isActivated)
|
|
79
|
+
debug('viteConfigFromVikeApi', viteConfigFromVikeApi);
|
|
80
|
+
if (debug.isActivated)
|
|
81
|
+
debug('vikeConfigFromApi', vikeConfigFromApi);
|
|
75
82
|
}
|
|
76
83
|
// Vite CLI args (when invoked via Vite's CLI rather than Vike's API).
|
|
77
84
|
// - 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.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
{
|
|
86
|
+
const viteConfigFromViteCli = getViteCliArgs();
|
|
87
|
+
addConfig(viteConfigFromViteCli);
|
|
88
|
+
if (debug.isActivated)
|
|
89
|
+
debug('viteConfigFromViteCli', viteConfigFromViteCli);
|
|
81
90
|
}
|
|
82
|
-
// Vike's CLI and VIKE_CONFIG
|
|
83
|
-
// - Resolve +mode/+root set over Vike's CLI or VIKE_CONFIG
|
|
91
|
+
// Vike's CLI and VIKE_CONFIG — `+mode` & `+root`
|
|
84
92
|
{
|
|
85
93
|
const viteConfigFromVikeCliOrEnv = pick(getVikeConfigFromCliOrEnv().vikeConfigFromCliOrEnv, EARLY_SETTINGS);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
addConfig(viteConfigFromVikeCliOrEnv);
|
|
95
|
+
if (debug.isActivated)
|
|
96
|
+
debug('viteConfigFromVikeCliOrEnv', viteConfigFromVikeCliOrEnv);
|
|
89
97
|
}
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
98
|
+
// VITE_CONFIG
|
|
99
|
+
{
|
|
100
|
+
const viteConfigFromViteEnv = getEnvVarObject('VITE_CONFIG');
|
|
101
|
+
addConfig(viteConfigFromViteEnv);
|
|
102
|
+
if (debug.isActivated)
|
|
103
|
+
debug('viteConfigFromViteEnv', viteConfigFromViteEnv);
|
|
94
104
|
}
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
105
|
+
// vite.config.js — lowest precedence. Merged into a *separate* result (used only to compute `root` and to
|
|
106
|
+
// find the Vike plugin): it must not flow back into `viteConfigUser`, which is handed to Vite —
|
|
107
|
+
// Vite loads vite.config.js itself, so merging it here would add the Vike plugin twice.
|
|
108
|
+
// Replicates Vite: https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1001
|
|
109
|
+
globalObject.isResolvingViteConfigUser = true;
|
|
110
|
+
const viteConfigFromViteFile = await loadViteConfigFile(viteConfigUser, viteContext);
|
|
111
|
+
globalObject.isResolvingViteConfigUser = false;
|
|
112
|
+
const viteConfigAll = underride(viteConfigFromViteFile ?? {});
|
|
113
|
+
const root = normalizeViteRoot(viteConfigAll.root ?? process.cwd());
|
|
103
114
|
globalObject.root = root;
|
|
104
115
|
// - Find options `vike(options)` set in vite.config.js
|
|
105
116
|
// - TO-DO/next-major-release: remove
|
|
106
117
|
// - Add Vike's Vite plugin if missing
|
|
107
118
|
let vikeVitePluginOptions;
|
|
108
|
-
const found = findVikeVitePlugin(
|
|
119
|
+
const found = findVikeVitePlugin(viteConfigAll);
|
|
109
120
|
if (found) {
|
|
110
121
|
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
111
122
|
}
|
|
@@ -113,25 +124,23 @@ async function getViteInfo(viteContext) {
|
|
|
113
124
|
// Show a warning because Vike supports Vite's CLI (as well as third-party CLIs).
|
|
114
125
|
// - Encourage users to define a vite.config.js file that also works with Vite's CLI (and potentially other third-party CLIs).
|
|
115
126
|
// - Vike-based frameworks, such as DocPress, allow their users to omit defining a vite.config.js file.
|
|
116
|
-
assertWarning(!
|
|
127
|
+
assertWarning(!viteConfigFromViteFile, // Only show the warning if the user defined a vite.config.js file
|
|
117
128
|
"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 });
|
|
118
129
|
// Add Vike to plugins if not present.
|
|
119
130
|
// 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.
|
|
120
131
|
const { plugin: vikePlugin } = await import('../vite/index.js');
|
|
121
|
-
|
|
122
|
-
...
|
|
123
|
-
plugins: [...(
|
|
132
|
+
viteConfigUser = {
|
|
133
|
+
...viteConfigUser,
|
|
134
|
+
plugins: [...(viteConfigUser?.plugins ?? []), vikePlugin()],
|
|
124
135
|
};
|
|
125
|
-
const res = findVikeVitePlugin(
|
|
136
|
+
const res = findVikeVitePlugin(viteConfigUser);
|
|
126
137
|
assert(res);
|
|
127
138
|
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
128
139
|
}
|
|
129
140
|
assert(vikeVitePluginOptions);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
function merge(c1, c2) {
|
|
134
|
-
return mergeConfig(c1, c2);
|
|
141
|
+
if (debug.isActivated)
|
|
142
|
+
debug('viteConfigUser', viteConfigUser);
|
|
143
|
+
return { viteConfigUser, root, vikeVitePluginOptions };
|
|
135
144
|
}
|
|
136
145
|
function findVikeVitePlugin(viteConfig) {
|
|
137
146
|
let vikeVitePluginOptions;
|
|
@@ -149,8 +158,8 @@ function findVikeVitePlugin(viteConfig) {
|
|
|
149
158
|
return { vikeVitePluginOptions };
|
|
150
159
|
}
|
|
151
160
|
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
152
|
-
async function loadViteConfigFile(
|
|
153
|
-
const viteContextResolved = resolveViteContext(
|
|
161
|
+
async function loadViteConfigFile(viteConfigUser, viteContext) {
|
|
162
|
+
const viteContextResolved = resolveViteContext(viteConfigUser, viteContext);
|
|
154
163
|
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = viteContextResolved;
|
|
155
164
|
let config = inlineConfig;
|
|
156
165
|
let mode = inlineConfig.mode || defaultMode;
|
|
@@ -206,12 +215,12 @@ function getViteContextWithOperation(operation) {
|
|
|
206
215
|
function getVikeApiContext() {
|
|
207
216
|
const vikeApiOperation = getVikeApiOperation();
|
|
208
217
|
if (!vikeApiOperation)
|
|
209
|
-
return {
|
|
218
|
+
return { viteConfigFromVikeApi: null, vikeConfigFromApi: null, viteContext: null };
|
|
210
219
|
const { options, operation } = vikeApiOperation;
|
|
211
|
-
const
|
|
212
|
-
const
|
|
220
|
+
const viteConfigFromVikeApi = options.viteConfig;
|
|
221
|
+
const vikeConfigFromApi = options.vikeConfig;
|
|
213
222
|
const viteContext = getViteContextWithOperation(operation);
|
|
214
|
-
return {
|
|
223
|
+
return { viteConfigFromVikeApi, vikeConfigFromApi, viteContext };
|
|
215
224
|
}
|
|
216
225
|
function resolveViteContext(inlineConfig = {}, viteContext) {
|
|
217
226
|
const isBuild = viteContext === 'build';
|
|
@@ -224,15 +233,15 @@ function resolveViteContext(inlineConfig = {}, viteContext) {
|
|
|
224
233
|
return viteContextResolved;
|
|
225
234
|
}
|
|
226
235
|
function normalizeViteRoot(root) {
|
|
227
|
-
// `path.resolve(
|
|
236
|
+
// `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:
|
|
228
237
|
// https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1063
|
|
229
238
|
return toPosixPath(
|
|
230
239
|
// Equivalent to `path.resolve(process.cwd(), root)`
|
|
231
240
|
path.resolve(root));
|
|
232
241
|
}
|
|
233
242
|
const errMsg = `A Vite plugin is modifying the Vite setting ${pc.cyan('root')} which is forbidden`;
|
|
234
|
-
async function assertViteRoot2(root,
|
|
235
|
-
const viteContextResolved = resolveViteContext(
|
|
243
|
+
async function assertViteRoot2(root, viteConfigUser, viteContext) {
|
|
244
|
+
const viteContextResolved = resolveViteContext(viteConfigUser, viteContext);
|
|
236
245
|
// 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.
|
|
237
246
|
const viteConfigResolved = await resolveConfig(...viteContextResolved);
|
|
238
247
|
assertUsage(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
|
|
@@ -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';
|
|
@@ -79,26 +79,29 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
79
79
|
config: {
|
|
80
80
|
order: 'post',
|
|
81
81
|
async handler(configFromUser) {
|
|
82
|
-
|
|
82
|
+
const configFromVike = { server: {}, preview: {} };
|
|
83
83
|
const vikeConfig = await getVikeConfigInternal();
|
|
84
|
+
// A value the user set through Vike (+config.js, CLI option, or VIKE_CONFIG) overrides vite.config.js:
|
|
85
|
+
// Vike's config has higher precedence than vite.config.js (see precedence list at resolveViteConfigUser.ts).
|
|
86
|
+
// Vike's own fallbacks (default port, Docker `--host`) use setDefault() so they don't override vite.config.js.
|
|
84
87
|
if (vikeConfig.config.port !== undefined) {
|
|
85
88
|
// https://vike.dev/port
|
|
86
|
-
|
|
89
|
+
setOverride('port', vikeConfig.config.port, configFromVike);
|
|
87
90
|
}
|
|
88
91
|
else {
|
|
89
92
|
// Change Vite's default port
|
|
90
93
|
setDefault('port', 3000, configFromUser, configFromVike);
|
|
91
94
|
}
|
|
92
|
-
if (vikeConfig.config.host) {
|
|
95
|
+
if (vikeConfig.config.host !== undefined) {
|
|
93
96
|
// https://vike.dev/host
|
|
94
|
-
|
|
97
|
+
setOverride('host', vikeConfig.config.host, configFromVike);
|
|
95
98
|
}
|
|
96
99
|
else if (isDocker()) {
|
|
97
100
|
// Set `--host` for Docker/Podman
|
|
98
101
|
setDefault('host', true, configFromUser, configFromVike);
|
|
99
102
|
}
|
|
100
103
|
// https://vike.dev/force
|
|
101
|
-
if (vikeConfig.config.force !== undefined
|
|
104
|
+
if (vikeConfig.config.force !== undefined) {
|
|
102
105
|
configFromVike.optimizeDeps ?? (configFromVike.optimizeDeps = {});
|
|
103
106
|
configFromVike.optimizeDeps.force = vikeConfig.config.force;
|
|
104
107
|
}
|
|
@@ -108,7 +111,12 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
108
111
|
},
|
|
109
112
|
];
|
|
110
113
|
}
|
|
111
|
-
//
|
|
114
|
+
// Apply a Vike-provided value, overriding vite.config.js (Vike's config has higher precedence than vite.config.js)
|
|
115
|
+
function setOverride(setting, value, configFromVike) {
|
|
116
|
+
configFromVike.server[setting] = value;
|
|
117
|
+
configFromVike.preview[setting] = value;
|
|
118
|
+
}
|
|
119
|
+
// Apply a Vike fallback without overriding the user's vite.config.js
|
|
112
120
|
function setDefault(setting, value, configFromUser, configFromVike) {
|
|
113
121
|
if (configFromUser.server?.[setting] === undefined)
|
|
114
122
|
configFromVike.server[setting] = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.259-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.259-commit-9fc8a01";
|
|
@@ -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-9fc8a01';
|
package/dist/utils/debug.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { createDebug };
|
|
|
2
2
|
export { isDebug };
|
|
3
3
|
export { isDebugError };
|
|
4
4
|
export { debug };
|
|
5
|
-
declare const flags: ["vike", "vike:config", "vike:crawl", "vike:file-change", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:staticReplace", "vike:stream", "vike:virtualFiles", "vike:vite-rpc"];
|
|
5
|
+
declare const flags: ["vike", "vike:config", "vike:crawl", "vike:file-change", "vike:error", "vike:esbuild-resolve", "vike:pluginExtractAssets", "vike:pluginExtractExportNames", "vike:glob", "vike:globalContext", "vike:log", "vike:optimizeDeps", "vike:outDir", "vike:pageFiles", "vike:pointer-imports", "vike:requireResolve", "vike:routing", "vike:setup", "vike:staticReplace", "vike:stream", "vike:virtualFiles", "vike:vite-config-user", "vike:vite-rpc"];
|
|
6
6
|
type Flag = (typeof flags)[number];
|
|
7
7
|
type Options = {
|
|
8
8
|
serialization?: {
|
package/dist/utils/debug.js
CHANGED