vike 0.4.217 → 0.4.218-commit-01a099d
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/cjs/__internal/index.js +9 -8
- package/dist/cjs/node/api/build.js +20 -11
- package/dist/cjs/node/api/index.js +17 -7
- package/dist/cjs/node/api/prepareViteApiCall.js +109 -26
- package/dist/cjs/node/api/utils.js +2 -0
- package/dist/cjs/node/cli/entry.js +17 -7
- package/dist/cjs/node/plugin/index.js +6 -5
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -3
- package/dist/cjs/node/plugin/plugins/baseUrls.js +20 -18
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/cjs/node/plugin/plugins/commonConfig.js +6 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +1 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +22 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +188 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/cjs/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +17 -7
- package/dist/cjs/node/prerender/isPrerenderEnabled.js +8 -0
- package/dist/cjs/node/prerender/runPrerender.js +21 -12
- package/dist/cjs/node/runtime/globalContext.js +44 -21
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/index-common.js +0 -15
- package/dist/cjs/node/runtime/onLoad.js +17 -3
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime-dev/index.js +17 -7
- package/dist/cjs/node/shared/resolveBase.js +2 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +2 -3
- package/dist/cjs/shared/getPageFiles.js +3 -9
- package/dist/cjs/shared/hooks/getHook.js +3 -3
- package/dist/cjs/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +113 -81
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +79 -54
- package/dist/cjs/shared/route/loadPageRoutes.js +3 -3
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +4 -3
- package/dist/esm/__internal/index.d.ts +3 -5
- package/dist/esm/__internal/index.js +4 -5
- package/dist/esm/client/client-routing-runtime/createPageContext.js +7 -1
- package/dist/esm/client/client-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/entry.js +0 -1
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/server-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/entry.js +0 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +8 -2
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.js +3 -4
- package/dist/esm/node/api/prepareViteApiCall.d.ts +9 -3
- package/dist/esm/node/api/prepareViteApiCall.js +91 -21
- package/dist/esm/node/api/utils.d.ts +2 -0
- package/dist/esm/node/api/utils.js +2 -0
- package/dist/esm/node/cli/parseCli.d.ts +1 -1
- package/dist/esm/node/plugin/index.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +6 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -3
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +21 -19
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +1 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -112
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +99 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +188 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/esm/node/plugin/plugins/workaroundVite6HmrRegression.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
- package/dist/esm/node/prerender/isPrerenderEnabled.d.ts +3 -0
- package/dist/esm/node/prerender/isPrerenderEnabled.js +6 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +1 -2
- package/dist/esm/node/prerender/runPrerender.js +3 -4
- package/dist/esm/node/runtime/globalContext.d.ts +4 -4
- package/dist/esm/node/runtime/globalContext.js +44 -21
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/index-common.d.ts +0 -1
- package/dist/esm/node/runtime/index-common.js +0 -15
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -0
- package/dist/esm/node/runtime/onLoad.js +16 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/esm/node/shared/resolveBase.js +2 -2
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +2 -3
- package/dist/esm/shared/getPageFiles.d.ts +2 -5
- package/dist/esm/shared/getPageFiles.js +1 -4
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +7 -3
- package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +23 -12
- package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +28 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +79 -54
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +1 -1
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +4 -3
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +2 -21
- package/__internal/loadImportBuild.js +0 -3
- package/__internal/setup.js +0 -3
- package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +0 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -128
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -25
- package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +0 -22
- package/dist/cjs/node/runtime/page-files/setup.js +0 -5
- package/dist/esm/client/client-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/client/server-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/server-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts +0 -104
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -123
- package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +0 -3
- package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +0 -18
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +0 -23
- package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +0 -2
- package/dist/esm/node/runtime/page-files/getPageFilesExports.js +0 -20
- package/dist/esm/node/runtime/page-files/setup.d.ts +0 -1
- package/dist/esm/node/runtime/page-files/setup.js +0 -3
- package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- package/dist/cjs/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +1 -1
- /package/dist/esm/shared/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
|
@@ -1,38 +1,93 @@
|
|
|
1
1
|
export { prepareViteApiCall };
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export { getViteRoot };
|
|
3
|
+
export { assertViteRoot };
|
|
4
|
+
export { normalizeViteRoot };
|
|
5
|
+
// TODO: enable Vike extensions to add Vite plugins
|
|
6
|
+
import { loadConfigFromFile, resolveConfig } from 'vite';
|
|
4
7
|
import { setOperation } from './context.js';
|
|
5
8
|
import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
6
|
-
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { assert, assertUsage, getGlobalObject, toPosixPath } from './utils.js';
|
|
11
|
+
import pc from '@brillout/picocolors';
|
|
12
|
+
const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
|
|
13
|
+
async function prepareViteApiCall(viteConfig, operation) {
|
|
7
14
|
setOperation(operation);
|
|
8
15
|
return enhanceViteConfig(viteConfig, operation);
|
|
9
16
|
}
|
|
10
|
-
async function enhanceViteConfig(viteConfig
|
|
11
|
-
|
|
17
|
+
async function enhanceViteConfig(viteConfig, operation) {
|
|
18
|
+
const { root, vikeVitePluginOptions, viteConfigEnhanced } = await getInfoFromVite(viteConfig, operation);
|
|
19
|
+
await assertViteRoot2(root, viteConfigEnhanced, operation);
|
|
20
|
+
const { vikeConfigGlobal } = await getVikeConfig2(root, operation === 'dev', vikeVitePluginOptions);
|
|
21
|
+
return {
|
|
22
|
+
viteConfigEnhanced,
|
|
23
|
+
vikeConfigGlobal
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async function getViteRoot(operation) {
|
|
27
|
+
if (!globalObject.root)
|
|
28
|
+
await getInfoFromVite(undefined, operation);
|
|
29
|
+
assert(globalObject.root);
|
|
30
|
+
return globalObject.root;
|
|
31
|
+
}
|
|
32
|
+
async function getInfoFromVite(viteConfig, operation) {
|
|
33
|
+
const viteConfigFromFile = await loadViteConfigFile(viteConfig, operation);
|
|
34
|
+
const root = normalizeViteRoot(viteConfigFromFile?.root ?? viteConfig?.root ?? process.cwd());
|
|
35
|
+
globalObject.root = root;
|
|
36
|
+
let vikeVitePluginOptions;
|
|
12
37
|
let viteConfigEnhanced = viteConfig;
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
38
|
+
const found = findVikeVitePlugin([...(viteConfig?.plugins ?? []), ...(viteConfigFromFile?.plugins ?? [])]);
|
|
39
|
+
if (found) {
|
|
40
|
+
vikeVitePluginOptions = found.vikeVitePluginOptions;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Add Vike to plugins if not present.
|
|
44
|
+
// 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.
|
|
16
45
|
const { plugin: vikePlugin } = await import('../plugin/index.js');
|
|
17
46
|
viteConfigEnhanced = {
|
|
18
47
|
...viteConfig,
|
|
19
|
-
plugins: [...(viteConfig
|
|
48
|
+
plugins: [...(viteConfig?.plugins ?? []), vikePlugin()]
|
|
20
49
|
};
|
|
21
|
-
|
|
50
|
+
const res = findVikeVitePlugin(viteConfigEnhanced.plugins);
|
|
51
|
+
assert(res);
|
|
52
|
+
vikeVitePluginOptions = res.vikeVitePluginOptions;
|
|
22
53
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// TODO: enable Vike extensions to add Vite plugins
|
|
26
|
-
return {
|
|
27
|
-
viteConfigEnhanced,
|
|
28
|
-
vikeConfigGlobal
|
|
29
|
-
};
|
|
54
|
+
assert(vikeVitePluginOptions);
|
|
55
|
+
return { root, vikeVitePluginOptions, viteConfigEnhanced };
|
|
30
56
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
function findVikeVitePlugin(plugins) {
|
|
58
|
+
let vikeVitePluginOptions;
|
|
59
|
+
let vikeVitePuginFound = false;
|
|
60
|
+
plugins.forEach((p) => {
|
|
61
|
+
if (p && '__vikeVitePluginOptions' in p) {
|
|
62
|
+
vikeVitePuginFound = true;
|
|
63
|
+
const options = p.__vikeVitePluginOptions;
|
|
64
|
+
vikeVitePluginOptions ?? (vikeVitePluginOptions = {});
|
|
65
|
+
Object.assign(vikeVitePluginOptions, options);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (!vikeVitePuginFound)
|
|
69
|
+
return null;
|
|
70
|
+
return { vikeVitePluginOptions };
|
|
71
|
+
}
|
|
72
|
+
// Copied from https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L961-L1005
|
|
73
|
+
async function loadViteConfigFile(viteConfig, operation) {
|
|
74
|
+
const [inlineConfig, command, defaultMode, _defaultNodeEnv, isPreview] = getResolveConfigArgs(viteConfig, operation);
|
|
75
|
+
let config = inlineConfig;
|
|
76
|
+
let mode = inlineConfig.mode || defaultMode;
|
|
77
|
+
const configEnv = {
|
|
78
|
+
mode,
|
|
79
|
+
command,
|
|
80
|
+
isSsrBuild: command === 'build' && !!config.build?.ssr,
|
|
81
|
+
isPreview
|
|
82
|
+
};
|
|
83
|
+
let { configFile } = config;
|
|
84
|
+
if (configFile !== false) {
|
|
85
|
+
const loadResult = await loadConfigFromFile(configEnv, configFile, config.root, config.logLevel, config.customLogger);
|
|
86
|
+
return loadResult?.config;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
34
89
|
}
|
|
35
|
-
function getResolveConfigArgs(viteConfig, operation) {
|
|
90
|
+
function getResolveConfigArgs(viteConfig = {}, operation) {
|
|
36
91
|
const inlineConfig = viteConfig;
|
|
37
92
|
const command = operation === 'build' || operation === 'prerender' ? 'build' : 'serve';
|
|
38
93
|
const defaultMode = operation === 'dev' ? 'development' : 'production';
|
|
@@ -40,3 +95,18 @@ function getResolveConfigArgs(viteConfig, operation) {
|
|
|
40
95
|
const isPreview = operation === 'preview';
|
|
41
96
|
return [inlineConfig, command, defaultMode, defaultNodeEnv, isPreview];
|
|
42
97
|
}
|
|
98
|
+
function normalizeViteRoot(root) {
|
|
99
|
+
return toPosixPath(path.resolve(root));
|
|
100
|
+
}
|
|
101
|
+
const errMsg = `A Vite plugin is modifying Vite's setting ${pc.cyan('root')} which is forbidden`;
|
|
102
|
+
async function assertViteRoot2(root, viteConfigEnhanced, operation) {
|
|
103
|
+
const args = getResolveConfigArgs(viteConfigEnhanced, operation);
|
|
104
|
+
// 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.
|
|
105
|
+
const viteConfigResolved = await resolveConfig(...args);
|
|
106
|
+
assertUsage(normalizeViteRoot(viteConfigResolved.root) === normalizeViteRoot(root), errMsg);
|
|
107
|
+
}
|
|
108
|
+
function assertViteRoot(root, config) {
|
|
109
|
+
if (globalObject.root)
|
|
110
|
+
assert(normalizeViteRoot(globalObject.root) === normalizeViteRoot(root));
|
|
111
|
+
assertUsage(normalizeViteRoot(root) === normalizeViteRoot(config.root), errMsg);
|
|
112
|
+
}
|
|
@@ -3,5 +3,5 @@ export { plugin };
|
|
|
3
3
|
export { plugin as ssr };
|
|
4
4
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
5
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
|
-
import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig
|
|
6
|
+
import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
|
|
@@ -17,7 +17,7 @@ import { extractAssetsPlugin } from './plugins/extractAssetsPlugin.js';
|
|
|
17
17
|
import { extractExportNamesPlugin } from './plugins/extractExportNamesPlugin.js';
|
|
18
18
|
import { suppressRollupWarning } from './plugins/suppressRollupWarning.js';
|
|
19
19
|
import { setGlobalContext } from './plugins/setGlobalContext.js';
|
|
20
|
-
import {
|
|
20
|
+
import { buildEntry } from './plugins/buildEntry/index.js';
|
|
21
21
|
import { commonConfig } from './plugins/commonConfig.js';
|
|
22
22
|
import { baseUrls } from './plugins/baseUrls.js';
|
|
23
23
|
import { envVarsPlugin } from './plugins/envVars.js';
|
|
@@ -26,12 +26,12 @@ import { fileEnv } from './plugins/fileEnv.js';
|
|
|
26
26
|
import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.js';
|
|
27
27
|
import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
|
|
28
28
|
import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
|
|
29
|
-
import {
|
|
29
|
+
import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegression.js';
|
|
30
30
|
markSetup_vikeVitePlugin();
|
|
31
31
|
assertViteVersion();
|
|
32
32
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
33
33
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
34
|
-
function plugin(vikeVitePluginOptions) {
|
|
34
|
+
function plugin(vikeVitePluginOptions = {}) {
|
|
35
35
|
const plugins = [
|
|
36
36
|
...commonConfig(vikeVitePluginOptions),
|
|
37
37
|
importUserCode(),
|
|
@@ -46,13 +46,14 @@ function plugin(vikeVitePluginOptions) {
|
|
|
46
46
|
extractExportNamesPlugin(),
|
|
47
47
|
suppressRollupWarning(),
|
|
48
48
|
...setGlobalContext(),
|
|
49
|
-
...
|
|
49
|
+
...buildEntry(),
|
|
50
50
|
baseUrls(vikeVitePluginOptions),
|
|
51
51
|
envVarsPlugin(),
|
|
52
52
|
fileEnv(),
|
|
53
53
|
workaroundCssModuleHmr(),
|
|
54
|
-
|
|
54
|
+
workaroundVite6HmrRegression()
|
|
55
55
|
];
|
|
56
|
+
Object.assign(plugins, { __vikeVitePluginOptions: vikeVitePluginOptions });
|
|
56
57
|
return plugins;
|
|
57
58
|
}
|
|
58
59
|
// Error upon wrong usage
|
|
@@ -3,6 +3,7 @@ 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 { isPrerenderEnabled } from '../../prerender/isPrerenderEnabled.js';
|
|
6
7
|
import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
|
|
7
8
|
import pc from '@brillout/picocolors';
|
|
8
9
|
import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
|
|
@@ -90,9 +91,7 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
|
|
|
90
91
|
logErrorHint(err);
|
|
91
92
|
process.exit(1);
|
|
92
93
|
}
|
|
93
|
-
if (vikeConfigGlobal
|
|
94
|
-
!vikeConfigGlobal.prerender.disableAutoRun &&
|
|
95
|
-
vikeConfigGlobal.disableAutoFullBuild !== 'prerender') {
|
|
94
|
+
if (isPrerenderEnabled(vikeConfigGlobal)) {
|
|
96
95
|
await runPrerenderFromAutoRun(configInline, false);
|
|
97
96
|
forceExit = true;
|
|
98
97
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
|
-
|
|
4
|
-
declare function baseUrls(vikeVitePluginOptions?: VikeVitePluginOptions): Plugin;
|
|
3
|
+
declare function baseUrls(vikeVitePluginOptions: unknown): Plugin;
|
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
2
|
import { resolveBase, resolveBaseFromResolvedConfig } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
|
-
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
4
|
+
import { getVikeConfig, getVikeConfig2 } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
+
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
5
6
|
function baseUrls(vikeVitePluginOptions) {
|
|
6
|
-
let
|
|
7
|
+
let basesResolved;
|
|
8
|
+
let root;
|
|
7
9
|
return {
|
|
8
10
|
name: 'vike:baseUrls',
|
|
9
11
|
enforce: 'post',
|
|
10
|
-
async config(config) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
12
|
+
async config(config, env) {
|
|
13
|
+
const isDev = config._isDev;
|
|
14
|
+
assert(typeof isDev === 'boolean');
|
|
15
|
+
const operation = env.command === 'build' ? 'build' : env.isPreview ? 'preview' : 'dev';
|
|
16
|
+
root = config.root ? normalizeViteRoot(config.root) : await getViteRoot(operation);
|
|
17
|
+
assert(root);
|
|
18
|
+
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
19
|
+
const vikeConfig = await getVikeConfig2(root, isDev, vikeVitePluginOptions);
|
|
20
|
+
basesResolved = resolveBase(baseViteOriginal, vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets);
|
|
14
21
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
15
|
-
process.env.BASE_SERVER = baseServer;
|
|
16
|
-
process.env.BASE_ASSETS = baseAssets;
|
|
22
|
+
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
23
|
+
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
17
24
|
return {
|
|
18
25
|
envPrefix: [
|
|
19
26
|
'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
|
|
20
27
|
'BASE_SERVER',
|
|
21
28
|
'BASE_ASSETS'
|
|
22
29
|
],
|
|
23
|
-
base: baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
|
|
24
|
-
_baseViteOriginal:
|
|
30
|
+
base: basesResolved.baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
|
|
31
|
+
_baseViteOriginal: baseViteOriginal
|
|
25
32
|
};
|
|
26
33
|
},
|
|
27
34
|
async configResolved(config) {
|
|
35
|
+
assertViteRoot(root, config);
|
|
28
36
|
const vikeConfig = await getVikeConfig(config);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
assert(basesResolved.baseServer === bases.baseServer);
|
|
33
|
-
assert(basesResolved.baseAssets === bases.baseAssets);
|
|
37
|
+
const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets, config);
|
|
38
|
+
assert(basesResolved2.baseServer === basesResolved.baseServer);
|
|
39
|
+
assert(basesResolved2.baseAssets === basesResolved.baseAssets);
|
|
34
40
|
/* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
|
|
35
41
|
* - 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/'`.)
|
|
36
42
|
* - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
|
|
@@ -39,7 +45,3 @@ function baseUrls(vikeVitePluginOptions) {
|
|
|
39
45
|
}
|
|
40
46
|
};
|
|
41
47
|
}
|
|
42
|
-
function resolveBaseFromUserConfig(config, vikeVitePluginOptions) {
|
|
43
|
-
const baseViteOriginal = config.base ?? null;
|
|
44
|
-
return resolveBase(baseViteOriginal, vikeVitePluginOptions?.baseServer ?? null, vikeVitePluginOptions?.baseAssets ?? null);
|
|
45
|
-
}
|
|
@@ -11,7 +11,7 @@ import { createRequire } from 'module';
|
|
|
11
11
|
import fs from 'fs/promises';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
14
|
-
import { set_ASSETS_MAP } from './
|
|
14
|
+
import { set_ASSETS_MAP } from './buildEntry/index.js';
|
|
15
15
|
import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
|
|
16
16
|
import { getFilePathResolved } from '../shared/getFilePath.js';
|
|
17
17
|
import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
@@ -117,7 +117,7 @@ async function getEntries(config) {
|
|
|
117
117
|
if (viteIsSSR(config)) {
|
|
118
118
|
const pageEntries = getPageEntries(pageConfigs);
|
|
119
119
|
const entries = {
|
|
120
|
-
//
|
|
120
|
+
// buildEntry: resolve('dist/esm/node/buildEntry.js'), // TODO/next-major-release: remove
|
|
121
121
|
...pageFileEntries,
|
|
122
122
|
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
123
123
|
...pageEntries
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getVikeManifest };
|
|
2
2
|
import { type PluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
3
|
-
import type { VikeConfigGlobal } from '../importUserCode/v1-design/getVikeConfig
|
|
3
|
+
import type { VikeConfigGlobal } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
4
4
|
import type { ResolvedConfig } from 'vite';
|
|
5
5
|
declare function getVikeManifest(vikeConfigGlobal: VikeConfigGlobal, viteConfig: ResolvedConfig): PluginManifest;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { buildEntry };
|
|
2
2
|
export { set_ASSETS_MAP };
|
|
3
3
|
import type { Plugin, Rollup } from 'vite';
|
|
4
4
|
type Bundle = Rollup.OutputBundle;
|
|
5
5
|
type Options = Rollup.NormalizedOutputOptions;
|
|
6
|
-
declare function
|
|
6
|
+
declare function buildEntry(): Plugin[];
|
|
7
7
|
/** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
8
8
|
declare function set_ASSETS_MAP(options: Options, bundle: Bundle): Promise<void>;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { buildEntry };
|
|
2
2
|
export { set_ASSETS_MAP };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
|
+
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
5
|
+
import { getVikeManifest } from './getVikeManifest.js';
|
|
6
|
+
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
4
7
|
import { assert, getOutDirs, toPosixPath } from '../../utils.js';
|
|
8
|
+
import fs from 'fs/promises';
|
|
5
9
|
import path from 'path';
|
|
6
10
|
import { createRequire } from 'module';
|
|
7
|
-
import { getVikeManifest } from './getVikeManifest.js';
|
|
8
|
-
import fs from 'fs/promises';
|
|
9
|
-
import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
10
|
-
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
11
11
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
12
12
|
const importMetaUrl = import.meta.url;
|
|
13
13
|
const require_ = createRequire(importMetaUrl);
|
|
14
14
|
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
15
|
-
function
|
|
15
|
+
function buildEntry() {
|
|
16
16
|
let config;
|
|
17
17
|
let vikeConfigGlobal;
|
|
18
18
|
return [
|
|
19
19
|
{
|
|
20
|
-
name: 'vike:
|
|
20
|
+
name: 'vike:buildEntry',
|
|
21
21
|
enforce: 'post',
|
|
22
22
|
async configResolved(config_) {
|
|
23
23
|
config = config_;
|
|
@@ -38,17 +38,16 @@ function getServerProductionEntryCode(config, vikeConfigGlobal) {
|
|
|
38
38
|
const vikeManifest = getVikeManifest(vikeConfigGlobal, config);
|
|
39
39
|
// Let's eventually simplify and move everything to a single virtual module
|
|
40
40
|
const importerCode = [
|
|
41
|
-
` import {
|
|
41
|
+
` import { setBuildEntry } from '${importPath}';`,
|
|
42
42
|
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
43
43
|
` {`,
|
|
44
44
|
// We first set the values to a variable because of a Rollup bug, and this workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
45
45
|
` const assetsManifest = ${ASSETS_MAP};`,
|
|
46
46
|
` const pluginManifest = ${JSON.stringify(vikeManifest, null, 2)};`,
|
|
47
|
-
'
|
|
48
|
-
` pageFiles
|
|
49
|
-
`
|
|
50
|
-
|
|
51
|
-
` pluginManifest: () => pluginManifest,`,
|
|
47
|
+
' setBuildEntry({',
|
|
48
|
+
` pageFiles,`,
|
|
49
|
+
` assetsManifest,`,
|
|
50
|
+
` pluginManifest,`,
|
|
52
51
|
' });',
|
|
53
52
|
` }`,
|
|
54
53
|
''
|
|
@@ -85,12 +84,12 @@ function find_ASSETS_MAP(bundle) {
|
|
|
85
84
|
function getImportPath(config) {
|
|
86
85
|
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
87
86
|
const filePathAbsolute = toPosixPath(
|
|
88
|
-
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
89
|
-
require_.resolve(`../../../../../../dist/esm/
|
|
87
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/buildEntry/index.js
|
|
88
|
+
require_.resolve(`../../../../../../dist/esm/__internal/index.js`));
|
|
90
89
|
if (
|
|
91
|
-
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal
|
|
90
|
+
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
92
91
|
true) {
|
|
93
|
-
return 'vike/__internal
|
|
92
|
+
return 'vike/__internal';
|
|
94
93
|
}
|
|
95
94
|
else {
|
|
96
95
|
const { outDirServer } = getOutDirs(config);
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
2
|
import { type Plugin } from 'vite';
|
|
3
|
-
declare
|
|
3
|
+
declare module 'vite' {
|
|
4
|
+
interface UserConfig {
|
|
5
|
+
_isDev?: boolean;
|
|
6
|
+
_vikeVitePluginOptions?: unknown;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
|
|
@@ -6,11 +6,11 @@ import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
9
|
-
import { pluginName } from './commonConfig/pluginName.js';
|
|
10
9
|
import { getEnvVarObject } from '../shared/getEnvVarObject.js';
|
|
11
10
|
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
12
11
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
13
|
-
|
|
12
|
+
const pluginName = 'vike:commonConfig';
|
|
13
|
+
function commonConfig(vikeVitePluginOptions) {
|
|
14
14
|
return [
|
|
15
15
|
{
|
|
16
16
|
name: `${pluginName}:pre`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
2
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type { VikeConfigGlobal } from './v1-design/getVikeConfig
|
|
3
|
+
import type { VikeConfigGlobal } from './v1-design/getVikeConfig.js';
|
|
4
4
|
declare function getVirtualFileImportUserCode(id: string, options: {
|
|
5
5
|
ssr?: boolean;
|
|
6
6
|
} | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
|
|
@@ -143,9 +143,7 @@ const configDefinitionsBuiltInGlobal = {
|
|
|
143
143
|
env: { server: true, client: 'if-client-routing' },
|
|
144
144
|
eager: true
|
|
145
145
|
},
|
|
146
|
-
prerender: {
|
|
147
|
-
env: { config: true }
|
|
148
|
-
},
|
|
146
|
+
prerender: { env: { config: true } },
|
|
149
147
|
disableAutoFullBuild: { env: { config: true } },
|
|
150
148
|
includeAssetsImportedByServer: { env: { config: true } },
|
|
151
149
|
baseAssets: { env: { config: true } },
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { crawlPlusFiles };
|
|
2
|
-
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string
|
|
2
|
+
declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: null | string): Promise<{
|
|
3
3
|
filePathAbsoluteUserRootDir: string;
|
|
4
4
|
}[]>;
|