vike 0.4.218 → 0.4.220-commit-a9f46b8
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 +11 -11
- package/dist/cjs/node/api/build.js +22 -48
- package/dist/cjs/node/api/context.js +8 -6
- package/dist/cjs/node/api/index.js +17 -7
- package/dist/cjs/node/api/prepareViteApiCall.js +40 -13
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +21 -7
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +5 -5
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -10
- 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 +41 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +171 -68
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- 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/context.js +24 -0
- package/dist/cjs/node/prerender/runPrerender.js +146 -96
- package/dist/cjs/node/prerender/utils.js +2 -0
- package/dist/cjs/node/runtime/globalContext.js +109 -55
- 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/page-files/setup.js +2 -4
- 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 +11 -33
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/cjs/node/runtime/renderPage.js +21 -22
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/runtime-dev/index.js +17 -7
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- 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/loadConfigValues.js +5 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- 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/cjs/utils/assertSetup.js +47 -16
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/debug.js +11 -6
- package/dist/cjs/utils/getGlobalObject.js +1 -2
- package/dist/cjs/utils/isDev.js +2 -0
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/objectReplace.js +9 -0
- package/dist/esm/__internal/index.d.ts +3 -5
- package/dist/esm/__internal/index.js +6 -8
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -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/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +23 -18
- package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/index.js +0 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
- 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/client-routing-runtime/renderPageClientSide.js +15 -15
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- 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 +5 -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/normalizeClientSideUrl.js +2 -3
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +20 -26
- package/dist/esm/node/api/context.d.ts +4 -2
- package/dist/esm/node/api/context.js +8 -7
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
- package/dist/esm/node/api/prepareViteApiCall.js +26 -9
- package/dist/esm/node/cli/context.d.ts +5 -0
- package/dist/esm/node/cli/context.js +14 -0
- package/dist/esm/node/cli/entry.js +4 -0
- package/dist/esm/node/cli/parseCli.d.ts +3 -1
- package/dist/esm/node/cli/utils.d.ts +1 -0
- package/dist/esm/node/cli/utils.js +1 -0
- package/dist/esm/node/plugin/index.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +5 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +4 -11
- 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 +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +42 -5
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +96 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +167 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- 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/prerender/context.d.ts +9 -0
- package/dist/esm/node/prerender/context.js +22 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -2
- package/dist/esm/node/prerender/runPrerender.js +130 -90
- package/dist/esm/node/prerender/utils.d.ts +2 -0
- package/dist/esm/node/prerender/utils.js +2 -0
- package/dist/esm/node/runtime/globalContext.d.ts +23 -7
- package/dist/esm/node/runtime/globalContext.js +109 -55
- 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/page-files/setup.js +3 -3
- 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 +31 -46
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/esm/node/runtime/renderPage.js +22 -23
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +3 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- 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/PageContextConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/Config.d.ts +20 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +13 -6
- package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +26 -12
- package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +26 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- 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/assertSetup.js +47 -16
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +11 -6
- package/dist/esm/utils/getGlobalObject.js +1 -2
- package/dist/esm/utils/isDev.js +2 -0
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -0
- package/dist/esm/utils/objectReplace.d.ts +1 -0
- package/dist/esm/utils/objectReplace.js +6 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +4 -13
- package/__internal/loadImportBuild.js +0 -3
- 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/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/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/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/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { executeOnRenderClientHook };
|
|
2
2
|
export type { PageContextBeforeRenderClient };
|
|
3
|
-
import type { PageFile,
|
|
3
|
+
import type { PageFile, PageConfigUserFriendly } from '../../shared/getPageFiles.js';
|
|
4
4
|
import { type PageContextForUserConsumptionClientSide } from './preparePageContextForUserConsumptionClientSide.js';
|
|
5
5
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
6
6
|
type PageContextBeforeRenderClient = {
|
|
@@ -9,5 +9,5 @@ type PageContextBeforeRenderClient = {
|
|
|
9
9
|
urlPathname?: string;
|
|
10
10
|
pageId: string;
|
|
11
11
|
_pageConfigs: PageConfigRuntime[];
|
|
12
|
-
} &
|
|
12
|
+
} & PageConfigUserFriendly & PageContextForUserConsumptionClientSide;
|
|
13
13
|
declare function executeOnRenderClientHook<PC extends PageContextBeforeRenderClient>(pageContext: PC, isClientRouting: boolean): Promise<void>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { loadUserFilesClientSide };
|
|
2
2
|
export { isErrorFetchingStaticAssets };
|
|
3
3
|
export type { PageContextUserFiles };
|
|
4
|
-
import { type PageFile, type
|
|
4
|
+
import { type PageFile, type PageConfigUserFriendly } from '../../shared/getPageFiles.js';
|
|
5
5
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
6
|
-
type PageContextUserFilesLoaded =
|
|
6
|
+
type PageContextUserFilesLoaded = PageConfigUserFriendly & {
|
|
7
7
|
_pageFilesLoaded: PageFile[];
|
|
8
8
|
};
|
|
9
9
|
type PageContextUserFiles = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { loadUserFilesClientSide };
|
|
2
2
|
export { isErrorFetchingStaticAssets };
|
|
3
|
-
import { getPageFilesClientSide,
|
|
3
|
+
import { getPageFilesClientSide, getPageConfigUserFriendly } from '../../shared/getPageFiles.js';
|
|
4
4
|
import { findPageConfig } from '../../shared/page-configs/findPageConfig.js';
|
|
5
5
|
import { loadConfigValues } from '../../shared/page-configs/loadConfigValues.js';
|
|
6
6
|
import { objectAssign } from '../server-routing-runtime/utils.js';
|
|
@@ -29,7 +29,7 @@ async function loadUserFilesClientSide(pageId, pageFilesAll, pageConfigs) {
|
|
|
29
29
|
}
|
|
30
30
|
throw err;
|
|
31
31
|
}
|
|
32
|
-
const pageContextExports =
|
|
32
|
+
const pageContextExports = getPageConfigUserFriendly(pageFilesClientSide, pageConfigLoaded);
|
|
33
33
|
const pageContextAddendum = {};
|
|
34
34
|
objectAssign(pageContextAddendum, pageContextExports);
|
|
35
35
|
objectAssign(pageContextAddendum, { _pageFilesLoaded: pageFilesClientSide });
|
|
@@ -2,9 +2,8 @@ export { normalizeClientSideUrl };
|
|
|
2
2
|
import { assert, parseUrl } from './utils.js';
|
|
3
3
|
/** Resolves relative URLs */
|
|
4
4
|
function normalizeClientSideUrl(url, options) {
|
|
5
|
-
// This function doesn't work for `url === '#some-hash'` because `searchOriginal`
|
|
6
|
-
// -
|
|
7
|
-
// - It makes sense that `parseUrl()` returns `searchOriginal === null` since there isn't any search string in `url`.
|
|
5
|
+
// This function doesn't work for `url === '#some-hash'` because `searchOriginal` will be missing: if window.location.href has a search string then it's going to be missing in the returned `urlCurrent` value because `parseUrl(url)` returns `searchOriginal: null` since there isn't any search string in `url`.
|
|
6
|
+
// - Maybe `const { searchOriginal } = parseUrl(window.location.href)` can be a fix. (Let's check how `normalizeClientSideUrl()` is being used.)
|
|
8
7
|
assert(!url.startsWith('#'));
|
|
9
8
|
const { searchOriginal, hashOriginal, pathname } = parseUrl(url, '/');
|
|
10
9
|
let urlCurrent = `${pathname}${searchOriginal || ''}`;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { preparePageContextForUserConsumptionClientSide };
|
|
2
2
|
export type { PageContextForUserConsumptionClientSide };
|
|
3
|
-
import type {
|
|
3
|
+
import type { PageConfigUserFriendly } from '../../shared/getPageFiles.js';
|
|
4
4
|
import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import { PageContextForPassToClientWarning } from './getPageContextProxyForUser.js';
|
|
6
|
-
type PageContextForUserConsumptionClientSide =
|
|
6
|
+
type PageContextForUserConsumptionClientSide = PageConfigUserFriendly & PageContextForPassToClientWarning & {
|
|
7
7
|
pageId: string;
|
|
8
8
|
_pageConfigs: PageConfigRuntime[];
|
|
9
9
|
};
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
export { build };
|
|
2
|
-
import { type Rollup } from 'vite';
|
|
3
2
|
import type { APIOptions } from './types.js';
|
|
4
|
-
type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
|
|
5
3
|
/**
|
|
6
4
|
* Programmatically trigger `$ vike build`
|
|
7
5
|
*
|
|
8
6
|
* https://vike.dev/api#build
|
|
9
7
|
*/
|
|
10
|
-
declare function build(options?: APIOptions): Promise<{
|
|
11
|
-
rollupOutputClient: RollupOutput;
|
|
12
|
-
rollupOutputServer: RollupOutput;
|
|
13
|
-
}>;
|
|
8
|
+
declare function build(options?: APIOptions): Promise<{}>;
|
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
export { build };
|
|
2
2
|
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
3
|
import { build as buildVite } from 'vite';
|
|
4
|
+
import assert from 'assert';
|
|
5
|
+
import { isVikeCli } from '../cli/context.js';
|
|
6
|
+
import { isPrerendering } from '../prerender/context.js';
|
|
4
7
|
/**
|
|
5
8
|
* Programmatically trigger `$ vike build`
|
|
6
9
|
*
|
|
7
10
|
* https://vike.dev/api#build
|
|
8
11
|
*/
|
|
9
12
|
async function build(options = {}) {
|
|
10
|
-
const { viteConfigEnhanced
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'build');
|
|
14
|
+
// Pass it to autoFullBuild()
|
|
15
|
+
if (viteConfigEnhanced)
|
|
16
|
+
viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
|
|
17
|
+
// 1. Build client-side
|
|
18
|
+
// 2. Build server-side
|
|
19
|
+
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L90
|
|
20
|
+
// 3. Pre-render (if enabled)
|
|
21
|
+
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
|
|
22
|
+
// > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
|
|
23
|
+
// > Rationale: https://github.com/vikejs/vike/issues/2123
|
|
24
|
+
await buildVite(viteConfigEnhanced);
|
|
25
|
+
// When using the Vike CLI with pre-rendering the process is forcefully exited at the end of the buildVite() call above
|
|
26
|
+
assert(!(isVikeCli() && isPrerendering()));
|
|
22
27
|
return {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rollupOutputClient: outputClient,
|
|
27
|
-
rollupOutputServer: outputServer
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function setSSR(viteConfig) {
|
|
31
|
-
return {
|
|
32
|
-
...viteConfig,
|
|
33
|
-
build: {
|
|
34
|
-
...viteConfig?.build,
|
|
35
|
-
ssr: true
|
|
36
|
-
}
|
|
28
|
+
/* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
29
|
+
viteConfig: viteConfigEnhanced,
|
|
30
|
+
*/
|
|
37
31
|
};
|
|
38
32
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { isVikeCliOrApi };
|
|
2
|
-
export {
|
|
2
|
+
export { setContextApiOperation };
|
|
3
|
+
export { clearContextApiOperation };
|
|
3
4
|
import type { Operation } from './types.js';
|
|
4
5
|
declare function isVikeCliOrApi(): boolean;
|
|
5
|
-
declare function
|
|
6
|
+
declare function setContextApiOperation(operation: Operation): void;
|
|
7
|
+
declare function clearContextApiOperation(): void;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export { isVikeCliOrApi };
|
|
2
|
-
|
|
3
|
-
export {
|
|
2
|
+
export { setContextApiOperation };
|
|
3
|
+
export { clearContextApiOperation };
|
|
4
4
|
import { assert, getGlobalObject } from './utils.js';
|
|
5
|
-
const globalObject = getGlobalObject('context.ts', {
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
function getOperation() {
|
|
5
|
+
const globalObject = getGlobalObject('api/context.ts', {});
|
|
6
|
+
function getApiOperation() {
|
|
9
7
|
assert(globalObject.apiOperation);
|
|
10
8
|
return globalObject.apiOperation;
|
|
11
9
|
}
|
|
@@ -13,7 +11,10 @@ function isVikeCliOrApi() {
|
|
|
13
11
|
// The CLI uses the API
|
|
14
12
|
return !!globalObject.apiOperation;
|
|
15
13
|
}
|
|
16
|
-
function
|
|
14
|
+
function setContextApiOperation(operation) {
|
|
17
15
|
assert(!globalObject.apiOperation);
|
|
18
16
|
globalObject.apiOperation = operation;
|
|
19
17
|
}
|
|
18
|
+
function clearContextApiOperation() {
|
|
19
|
+
globalObject.apiOperation = undefined;
|
|
20
|
+
}
|
|
@@ -6,7 +6,6 @@ import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
|
6
6
|
import type { Operation } from './types.js';
|
|
7
7
|
declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
|
|
8
8
|
viteConfigEnhanced: InlineConfig | undefined;
|
|
9
|
-
vikeConfigGlobal: import("../plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js").VikeConfigGlobal;
|
|
10
9
|
}>;
|
|
11
10
|
declare function getViteRoot(operation: 'build' | 'dev' | 'preview' | 'prerender'): Promise<string>;
|
|
12
11
|
declare function normalizeViteRoot(root: string): string;
|
|
@@ -3,26 +3,43 @@ export { getViteRoot };
|
|
|
3
3
|
export { assertViteRoot };
|
|
4
4
|
export { normalizeViteRoot };
|
|
5
5
|
// TODO: enable Vike extensions to add Vite plugins
|
|
6
|
-
import { loadConfigFromFile, resolveConfig } from 'vite';
|
|
7
|
-
import {
|
|
6
|
+
import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
|
|
7
|
+
import { clearContextApiOperation, setContextApiOperation } from './context.js';
|
|
8
8
|
import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import { assert, assertUsage, getGlobalObject, toPosixPath } from './utils.js';
|
|
10
|
+
import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './utils.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
|
+
import { clearGlobalContext } from '../runtime/globalContext.js';
|
|
12
13
|
const globalObject = getGlobalObject('prepareViteApiCall.ts', {});
|
|
13
14
|
async function prepareViteApiCall(viteConfig, operation) {
|
|
14
|
-
|
|
15
|
+
clear();
|
|
16
|
+
setContextApiOperation(operation);
|
|
15
17
|
return enhanceViteConfig(viteConfig, operation);
|
|
16
18
|
}
|
|
19
|
+
// For subsequent API calls, e.g. calling prerender() after build()
|
|
20
|
+
function clear() {
|
|
21
|
+
clearContextApiOperation();
|
|
22
|
+
clearGlobalContext();
|
|
23
|
+
}
|
|
17
24
|
async function enhanceViteConfig(viteConfig, operation) {
|
|
18
|
-
const
|
|
19
|
-
await assertViteRoot2(root, viteConfigEnhanced, operation);
|
|
20
|
-
const
|
|
25
|
+
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
26
|
+
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
27
|
+
const vikeConfig = await getVikeConfig2(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
28
|
+
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
21
29
|
return {
|
|
22
|
-
viteConfigEnhanced
|
|
23
|
-
vikeConfigGlobal
|
|
30
|
+
viteConfigEnhanced
|
|
24
31
|
};
|
|
25
32
|
}
|
|
33
|
+
function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
34
|
+
const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
|
|
35
|
+
if (!viteConfigs)
|
|
36
|
+
return viteConfigEnhanced;
|
|
37
|
+
viteConfigs.values.forEach((v) => {
|
|
38
|
+
assertUsage(isObject(v.value), `${v.definedAt} should be an object`);
|
|
39
|
+
viteConfigEnhanced = mergeConfig(viteConfigEnhanced ?? {}, v.value);
|
|
40
|
+
});
|
|
41
|
+
return viteConfigEnhanced;
|
|
42
|
+
}
|
|
26
43
|
async function getViteRoot(operation) {
|
|
27
44
|
if (!globalObject.root)
|
|
28
45
|
await getInfoFromVite(undefined, operation);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { isVikeCli };
|
|
2
|
+
export { setContextCliCommand };
|
|
3
|
+
import { assert, getGlobalObject } from './utils.js';
|
|
4
|
+
const globalObject = getGlobalObject('cli/context.ts', {});
|
|
5
|
+
function getCliCommand() {
|
|
6
|
+
return globalObject.cliCommand;
|
|
7
|
+
}
|
|
8
|
+
function isVikeCli() {
|
|
9
|
+
return !!globalObject.cliCommand;
|
|
10
|
+
}
|
|
11
|
+
function setContextCliCommand(command) {
|
|
12
|
+
assert(!globalObject.cliCommand);
|
|
13
|
+
globalObject.cliCommand = command;
|
|
14
|
+
}
|
|
@@ -2,9 +2,11 @@ import { projectInfo } from './utils.js';
|
|
|
2
2
|
import { dev, build, preview } from '../api/index.js';
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
import { parseCli } from './parseCli.js';
|
|
5
|
+
import { setContextCliCommand } from './context.js';
|
|
5
6
|
cli();
|
|
6
7
|
async function cli() {
|
|
7
8
|
const { command } = parseCli();
|
|
9
|
+
setContextCliCommand(command);
|
|
8
10
|
if (command === 'dev') {
|
|
9
11
|
await cmdDev();
|
|
10
12
|
}
|
|
@@ -49,6 +51,8 @@ async function cmdBuild() {
|
|
|
49
51
|
console.error(err);
|
|
50
52
|
process.exit(1);
|
|
51
53
|
}
|
|
54
|
+
// See comments at runPrerender_forceExit()
|
|
55
|
+
process.exit(0);
|
|
52
56
|
}
|
|
53
57
|
async function cmdPreview() {
|
|
54
58
|
try {
|
|
@@ -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,7 +26,7 @@ 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);
|
|
@@ -46,12 +46,12 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
46
46
|
extractExportNamesPlugin(),
|
|
47
47
|
suppressRollupWarning(),
|
|
48
48
|
...setGlobalContext(),
|
|
49
|
-
...
|
|
50
|
-
baseUrls(
|
|
49
|
+
...buildEntry(),
|
|
50
|
+
baseUrls(),
|
|
51
51
|
envVarsPlugin(),
|
|
52
52
|
fileEnv(),
|
|
53
53
|
workaroundCssModuleHmr(),
|
|
54
|
-
|
|
54
|
+
workaroundVite6HmrRegression()
|
|
55
55
|
];
|
|
56
56
|
Object.assign(plugins, { __vikeVitePluginOptions: vikeVitePluginOptions });
|
|
57
57
|
return plugins;
|
|
@@ -3,11 +3,14 @@ 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 { isPrerenderAutoRunEnabled } from '../../prerender/context.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';
|
|
9
10
|
import { manifestTempFile } from './buildConfig.js';
|
|
10
11
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
12
|
+
import { isVikeCliOrApi } from '../../api/context.js';
|
|
13
|
+
import { isVikeCli } from '../../cli/context.js';
|
|
11
14
|
let forceExit = false;
|
|
12
15
|
function autoFullBuild() {
|
|
13
16
|
let config;
|
|
@@ -68,35 +71,43 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
|
|
|
68
71
|
if (!bundle[manifestTempFile])
|
|
69
72
|
return;
|
|
70
73
|
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await build({
|
|
81
|
-
...configInline,
|
|
74
|
+
let configInline;
|
|
75
|
+
if (config._viteConfigEnhanced) {
|
|
76
|
+
configInline = config._viteConfigEnhanced;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
configInline = {
|
|
80
|
+
...configFromCli,
|
|
81
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
82
|
+
root: config.root,
|
|
82
83
|
build: {
|
|
83
|
-
...
|
|
84
|
-
ssr: true
|
|
84
|
+
...configFromCli?.build
|
|
85
85
|
}
|
|
86
|
-
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
await build(setSSR(configInline));
|
|
87
90
|
}
|
|
88
91
|
catch (err) {
|
|
89
92
|
console.error(err);
|
|
90
93
|
logErrorHint(err);
|
|
91
94
|
process.exit(1);
|
|
92
95
|
}
|
|
93
|
-
if (vikeConfigGlobal
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
forceExit = true;
|
|
96
|
+
if (isPrerenderAutoRunEnabled(vikeConfigGlobal)) {
|
|
97
|
+
const { prerenderContextPublic } = await runPrerenderFromAutoRun(configInline);
|
|
98
|
+
config.vike.prerenderContext = prerenderContextPublic;
|
|
99
|
+
forceExit = isVikeCli() || isViteCliCall();
|
|
98
100
|
}
|
|
99
101
|
}
|
|
102
|
+
function setSSR(configInline) {
|
|
103
|
+
return {
|
|
104
|
+
...configInline,
|
|
105
|
+
build: {
|
|
106
|
+
...configInline.build,
|
|
107
|
+
ssr: true
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
100
111
|
function abortViteBuildSsr(vikeConfigGlobal) {
|
|
101
112
|
if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
102
113
|
assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
|
|
@@ -106,7 +117,8 @@ function abortViteBuildSsr(vikeConfigGlobal) {
|
|
|
106
117
|
function isDisabled(vikeConfigGlobal) {
|
|
107
118
|
const { disableAutoFullBuild } = vikeConfigGlobal;
|
|
108
119
|
if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
|
|
109
|
-
|
|
120
|
+
const isViteApi = !isViteCliCall() && !isVikeCliOrApi();
|
|
121
|
+
return isViteApi;
|
|
110
122
|
}
|
|
111
123
|
else {
|
|
112
124
|
return disableAutoFullBuild;
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
export { baseUrls };
|
|
2
2
|
import { resolveBase, resolveBaseFromResolvedConfig } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
|
-
import { getVikeConfig
|
|
5
|
-
|
|
6
|
-
function baseUrls(vikeVitePluginOptions) {
|
|
4
|
+
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
+
function baseUrls() {
|
|
7
6
|
let basesResolved;
|
|
8
|
-
let root;
|
|
9
7
|
return {
|
|
10
8
|
name: 'vike:baseUrls',
|
|
11
9
|
enforce: 'post',
|
|
12
|
-
async config(config
|
|
10
|
+
async config(config) {
|
|
13
11
|
const isDev = config._isDev;
|
|
14
12
|
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
13
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
19
|
-
|
|
20
|
-
basesResolved = resolveBase(baseViteOriginal, vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets);
|
|
14
|
+
basesResolved = resolveBase(baseViteOriginal, config._vikeConfigGlobal.baseServer, config._vikeConfigGlobal.baseAssets);
|
|
21
15
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
22
16
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
23
17
|
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
@@ -32,7 +26,6 @@ function baseUrls(vikeVitePluginOptions) {
|
|
|
32
26
|
};
|
|
33
27
|
},
|
|
34
28
|
async configResolved(config) {
|
|
35
|
-
assertViteRoot(root, config);
|
|
36
29
|
const vikeConfig = await getVikeConfig(config);
|
|
37
30
|
const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets, config);
|
|
38
31
|
assert(basesResolved2.baseServer === basesResolved.baseServer);
|
|
@@ -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 { setGlobalContext_buildEntry } 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
|
+
' setGlobalContext_buildEntry({',
|
|
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,9 +1,18 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
|
-
import { type Plugin } from 'vite';
|
|
2
|
+
import { type InlineConfig, type Plugin } from 'vite';
|
|
3
|
+
import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
|
|
4
|
+
import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
|
|
3
5
|
declare module 'vite' {
|
|
4
6
|
interface UserConfig {
|
|
5
7
|
_isDev?: boolean;
|
|
6
8
|
_vikeVitePluginOptions?: unknown;
|
|
9
|
+
_root?: string;
|
|
10
|
+
_viteConfigEnhanced?: InlineConfig;
|
|
11
|
+
vike?: {
|
|
12
|
+
global: VikeConfigObject['global'];
|
|
13
|
+
prerenderContext?: PrerenderContextPublic;
|
|
14
|
+
};
|
|
15
|
+
_vikeConfigGlobal?: VikeConfigObject['vikeConfigGlobal'];
|
|
7
16
|
}
|
|
8
17
|
}
|
|
9
18
|
declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
|