vike 0.4.223 → 0.4.224
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/node/api/build.js +4 -37
- package/dist/cjs/node/api/prepareViteApiCall.js +9 -3
- package/dist/cjs/node/plugin/index.js +8 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/cjs/node/plugin/plugins/{buildConfig/fixServerAssets.js → build/handleAssetsManifest.js} +130 -52
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +145 -0
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +52 -0
- package/dist/cjs/node/plugin/plugins/{buildConfig.js → build/pluginBuildConfig.js} +22 -84
- package/dist/cjs/node/plugin/plugins/{buildEntry/index.js → build/pluginBuildEntry.js} +9 -9
- package/dist/cjs/node/plugin/plugins/{distFileNames.js → build/pluginDistFileNames.js} +7 -7
- package/dist/cjs/node/plugin/plugins/{packageJsonFile.js → build/pluginDistPackageJsonFile.js} +6 -6
- package/dist/cjs/node/plugin/plugins/{suppressRollupWarning.js → build/pluginSuppressRollupWarning.js} +3 -3
- package/dist/cjs/node/plugin/plugins/build.js +21 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +22 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +9 -9
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +16 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +50 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +19 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +277 -212
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js +4 -4
- package/dist/cjs/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/cjs/node/plugin/shared/getOutDirs.js +8 -7
- package/dist/cjs/node/plugin/shared/isViteServerBuild.js +47 -0
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/context.js +3 -8
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +23 -21
- package/dist/cjs/node/prerender/runPrerender.js +28 -28
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/cjs/shared/getPageContextUrlComputed.js +1 -1
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -5
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +20 -9
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/findFile.js +1 -1
- package/dist/cjs/utils/findPackageJson.js +1 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +10 -4
- package/dist/cjs/utils/path.js +1 -0
- package/dist/cjs/utils/requireResolve.js +11 -4
- package/dist/cjs/utils/sorter.js +0 -3
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +10 -1
- package/dist/esm/node/api/build.js +4 -4
- package/dist/esm/node/api/prepareViteApiCall.js +9 -3
- package/dist/esm/node/plugin/index.d.ts +2 -1
- package/dist/esm/node/plugin/index.js +4 -17
- package/dist/esm/node/plugin/plugins/baseUrls.js +3 -1
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.d.ts +18 -0
- package/dist/esm/node/plugin/plugins/{buildConfig/fixServerAssets.js → build/handleAssetsManifest.js} +131 -53
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +140 -0
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +50 -0
- package/dist/esm/node/plugin/plugins/{buildConfig.d.ts → build/pluginBuildConfig.d.ts} +3 -3
- package/dist/esm/node/plugin/plugins/{buildConfig.js → build/pluginBuildConfig.js} +22 -81
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/{buildEntry/index.js → build/pluginBuildEntry.js} +9 -9
- package/dist/esm/node/plugin/plugins/build/pluginDistFileNames.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{distFileNames.js → build/pluginDistFileNames.js} +7 -7
- package/dist/esm/node/plugin/plugins/build/pluginDistPackageJsonFile.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{packageJsonFile.js → build/pluginDistPackageJsonFile.js} +7 -6
- package/dist/esm/node/plugin/plugins/build/pluginSuppressRollupWarning.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{suppressRollupWarning.js → build/pluginSuppressRollupWarning.js} +3 -3
- package/dist/esm/node/plugin/plugins/build.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/build.js +19 -0
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +15 -6
- package/dist/esm/node/plugin/plugins/commonConfig.js +22 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/envVars.js +2 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +10 -10
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +13 -0
- 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 +50 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +279 -214
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/virtual-files/getVirtualFilePageConfigValuesAll.js +4 -4
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -3
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -3
- package/dist/esm/node/plugin/shared/getOutDirs.d.ts +2 -2
- package/dist/esm/node/plugin/shared/getOutDirs.js +8 -7
- package/dist/esm/node/plugin/shared/isViteServerBuild.d.ts +15 -0
- package/dist/esm/node/plugin/shared/isViteServerBuild.js +45 -0
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/context.d.ts +0 -2
- package/dist/esm/node/prerender/context.js +4 -9
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +10 -6
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +24 -22
- package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
- package/dist/esm/node/prerender/runPrerender.js +29 -29
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.d.ts +2 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +7 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +165 -5
- package/dist/esm/shared/getPageContextUrlComputed.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +12 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +5 -5
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -5
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +3 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +20 -9
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/findPackageJson.js +1 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +8 -2
- package/dist/esm/utils/path.js +1 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +11 -4
- package/dist/esm/utils/sorter.d.ts +18 -5
- package/dist/esm/utils/sorter.js +0 -3
- package/package.json +8 -16
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -119
- package/dist/cjs/node/plugin/plugins/buildApp.js +0 -76
- package/dist/cjs/node/plugin/plugins/removeRequireHookPlugin.js +0 -17
- package/dist/cjs/node/plugin/shared/getFullBuildInlineConfig.js +0 -20
- package/dist/cjs/node/plugin/shared/viteIsSSR.js +0 -31
- package/dist/esm/node/plugin/plugins/autoFullBuild.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -114
- package/dist/esm/node/plugin/plugins/buildApp.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/buildApp.js +0 -74
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +0 -20
- package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/distFileNames.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/packageJsonFile.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/removeRequireHookPlugin.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/removeRequireHookPlugin.js +0 -15
- package/dist/esm/node/plugin/plugins/suppressRollupWarning.d.ts +0 -3
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.d.ts +0 -2
- package/dist/esm/node/plugin/shared/getFullBuildInlineConfig.js +0 -17
- package/dist/esm/node/plugin/shared/viteIsSSR.d.ts +0 -11
- package/dist/esm/node/plugin/shared/viteIsSSR.js +0 -29
- package/dist-cjs-fixup.mjs +0 -41
|
@@ -7,7 +7,7 @@ const assertSetup_js_1 = require("./assertSetup.js");
|
|
|
7
7
|
const path_js_1 = require("./path.js");
|
|
8
8
|
const isScriptFile_js_1 = require("./isScriptFile.js");
|
|
9
9
|
const module_1 = require("module");
|
|
10
|
-
// @ts-ignore
|
|
10
|
+
// @ts-ignore `file://${__filename}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
11
11
|
const importMetaUrl = `file://${__filename}`;
|
|
12
12
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
13
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
@@ -34,6 +34,13 @@ function requireResolve(importPath, cwd) {
|
|
|
34
34
|
return importedFile;
|
|
35
35
|
}
|
|
36
36
|
function removeFileExtention(importPath) {
|
|
37
|
+
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
38
|
+
//@ts-ignore
|
|
39
|
+
if (typeof Bun !== 'undefined') {
|
|
40
|
+
// https://bun.sh/guides/util/detect-bun
|
|
41
|
+
(0, assert_js_1.assert)(process.versions.bun);
|
|
42
|
+
return importPath;
|
|
43
|
+
}
|
|
37
44
|
for (const ext of isScriptFile_js_1.scriptFileExtensionList) {
|
|
38
45
|
const suffix = `.${ext}`;
|
|
39
46
|
if (importPath.endsWith(suffix)) {
|
|
@@ -47,14 +54,14 @@ function addFileExtensionsToRequireResolve() {
|
|
|
47
54
|
isScriptFile_js_1.scriptFileExtensionList.forEach((ext) => {
|
|
48
55
|
(0, assert_js_1.assert)(!ext.includes('.'));
|
|
49
56
|
ext = `.${ext}`;
|
|
50
|
-
if (!
|
|
51
|
-
|
|
57
|
+
if (!require_.extensions[ext]) {
|
|
58
|
+
require_.extensions[ext] = require_.extensions['.js'];
|
|
52
59
|
added.push(ext);
|
|
53
60
|
}
|
|
54
61
|
});
|
|
55
62
|
const clean = () => {
|
|
56
63
|
added.forEach((ext) => {
|
|
57
|
-
delete
|
|
64
|
+
delete require_.extensions[ext];
|
|
58
65
|
});
|
|
59
66
|
};
|
|
60
67
|
return clean;
|
package/dist/cjs/utils/sorter.js
CHANGED
|
@@ -6,9 +6,6 @@ exports.makeFirst = makeFirst;
|
|
|
6
6
|
exports.makeLast = makeLast;
|
|
7
7
|
exports.reverse = reverse;
|
|
8
8
|
const assert_js_1 = require("./assert.js");
|
|
9
|
-
// -1 => element1 first (i.e. `indexOf(element1) < indexOf(element2)`)
|
|
10
|
-
// +1 => element2 first (i.e. `indexOf(element2) < indexOf(element1)`)
|
|
11
|
-
// 0 => keep original order of element1 and element2
|
|
12
9
|
/**
|
|
13
10
|
* ```js
|
|
14
11
|
* let arr = [
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { navigate, reload } from './navigate.js';
|
|
2
2
|
export { prefetch } from './prefetch.js';
|
|
3
|
+
export { getPageContextClient } from './renderPageClientSide.js';
|
|
3
4
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
4
5
|
import type { PageContextBuiltInClientWithClientRouting } from '../../shared/types.js';
|
|
5
6
|
/** @deprecated
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
// Use package.json#exports to make the imports isomorphic.
|
|
6
6
|
export { navigate, reload } from './navigate.js';
|
|
7
7
|
export { prefetch } from './prefetch.js';
|
|
8
|
+
export { getPageContextClient } from './renderPageClientSide.js';
|
|
8
9
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
@@ -2,8 +2,10 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
+
export { getPageContextClient };
|
|
5
6
|
import { type PageContextFromRewrite } from '../../shared/route/abort.js';
|
|
6
7
|
import { type ScrollTarget } from './setScrollPosition.js';
|
|
8
|
+
import type { PageContextClient } from '../../shared/types.js';
|
|
7
9
|
declare const firstRenderStartPromise: Promise<void>;
|
|
8
10
|
type RenderArgs = {
|
|
9
11
|
scrollTarget: ScrollTarget;
|
|
@@ -24,3 +26,9 @@ declare global {
|
|
|
24
26
|
}
|
|
25
27
|
declare function disableClientRouting(err: unknown, log: boolean): void;
|
|
26
28
|
declare function getRenderCount(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Get the `pageContext` object on the client-side.
|
|
31
|
+
*
|
|
32
|
+
* https://vike.dev/getPageContextClient
|
|
33
|
+
*/
|
|
34
|
+
declare function getPageContextClient(): PageContextClient | null;
|
|
@@ -2,6 +2,7 @@ export { renderPageClientSide };
|
|
|
2
2
|
export { getRenderCount };
|
|
3
3
|
export { disableClientRouting };
|
|
4
4
|
export { firstRenderStartPromise };
|
|
5
|
+
export { getPageContextClient };
|
|
5
6
|
import { assert, isSameErrorMessage, objectAssign, redirectHard, getGlobalObject, executeHook, hasProp, augmentType, genPromise, isCallable, catchInfiniteLoop } from './utils.js';
|
|
6
7
|
import { getPageContextFromClientHooks, getPageContextFromServerHooks, getPageContextFromHooks_isHydration, getPageContextFromHooks_serialized, setPageContextInitIsPassedToClient } from './getPageContextFromHooks.js';
|
|
7
8
|
import { createPageContext } from './createPageContext.js';
|
|
@@ -23,7 +24,6 @@ import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
|
23
24
|
const globalObject = getGlobalObject('client-routing-runtime/renderPageClientSide.ts', (() => {
|
|
24
25
|
const { promise: firstRenderStartPromise, resolve: firstRenderStartPromiseResolve } = genPromise();
|
|
25
26
|
return {
|
|
26
|
-
previousPageContext: null,
|
|
27
27
|
renderCounter: 0,
|
|
28
28
|
firstRenderStartPromise,
|
|
29
29
|
firstRenderStartPromiseResolve
|
|
@@ -484,6 +484,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
484
484
|
// Add link prefetch handlers
|
|
485
485
|
addLinkPrefetchHandlers_watch();
|
|
486
486
|
addLinkPrefetchHandlers();
|
|
487
|
+
globalObject.renderedPageContext = pageContext;
|
|
487
488
|
stampFinished(urlOriginal);
|
|
488
489
|
}
|
|
489
490
|
}
|
|
@@ -595,3 +596,11 @@ function areKeysEqual(key1, key2) {
|
|
|
595
596
|
return false;
|
|
596
597
|
return key1.length === key2.length && key1.every((_, i) => key1[i] === key2[i]);
|
|
597
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Get the `pageContext` object on the client-side.
|
|
601
|
+
*
|
|
602
|
+
* https://vike.dev/getPageContextClient
|
|
603
|
+
*/
|
|
604
|
+
function getPageContextClient() {
|
|
605
|
+
return globalObject.renderedPageContext ?? null;
|
|
606
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { build };
|
|
2
2
|
import { prepareViteApiCall } from './prepareViteApiCall.js';
|
|
3
|
-
import { build as buildVite, version } from 'vite';
|
|
3
|
+
import { build as buildVite, version, createBuilder } from 'vite';
|
|
4
4
|
import assert from 'assert';
|
|
5
5
|
import { isVikeCli } from '../cli/context.js';
|
|
6
6
|
import { isPrerendering } from '../prerender/context.js';
|
|
@@ -12,13 +12,13 @@ import { assertVersion } from './utils.js';
|
|
|
12
12
|
*/
|
|
13
13
|
async function build(options = {}) {
|
|
14
14
|
const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options.viteConfig, 'build');
|
|
15
|
-
// Pass it to
|
|
15
|
+
// Pass it to pluginAutoFullBuild()
|
|
16
16
|
if (viteConfigEnhanced)
|
|
17
17
|
viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
|
|
18
|
-
if (vikeConfig.global.config.
|
|
18
|
+
if (vikeConfig.global.config.vite6BuilderApp) {
|
|
19
19
|
assertVersion('Vite', version, '6.0.0');
|
|
20
|
-
const { createBuilder } = await import('vite');
|
|
21
20
|
const builder = await createBuilder(viteConfigEnhanced);
|
|
21
|
+
// See Vite plugin vike:build:pluginBuildApp
|
|
22
22
|
await builder.buildApp();
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
@@ -2,7 +2,6 @@ export { prepareViteApiCall };
|
|
|
2
2
|
export { getViteRoot };
|
|
3
3
|
export { assertViteRoot };
|
|
4
4
|
export { normalizeViteRoot };
|
|
5
|
-
// TODO: enable Vike extensions to add Vite plugins
|
|
6
5
|
import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
|
|
7
6
|
import { clearContextApiOperation, setContextApiOperation } from './context.js';
|
|
8
7
|
import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
@@ -50,7 +49,10 @@ async function getViteRoot(operation) {
|
|
|
50
49
|
}
|
|
51
50
|
async function getInfoFromVite(viteConfigFromOptions, operation) {
|
|
52
51
|
const viteConfigFromUserViteFile = await loadViteConfigFile(viteConfigFromOptions, operation);
|
|
53
|
-
const root = normalizeViteRoot(
|
|
52
|
+
const root = normalizeViteRoot(
|
|
53
|
+
// `viteConfigFromOptions.root` before `viteConfigFromUserViteFile.root` replicates Vite's precedence:
|
|
54
|
+
// https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1001
|
|
55
|
+
viteConfigFromOptions?.root ?? viteConfigFromUserViteFile?.root ?? process.cwd());
|
|
54
56
|
globalObject.root = root;
|
|
55
57
|
let vikeVitePluginOptions;
|
|
56
58
|
let viteConfigEnhanced = viteConfigFromOptions;
|
|
@@ -116,7 +118,11 @@ function getResolveConfigArgs(viteConfig = {}, operation) {
|
|
|
116
118
|
return [inlineConfig, command, defaultMode, defaultNodeEnv, isPreview];
|
|
117
119
|
}
|
|
118
120
|
function normalizeViteRoot(root) {
|
|
119
|
-
|
|
121
|
+
// `path.resolve(viteConfigFromUserViteFile.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:
|
|
122
|
+
// https://github.com/vitejs/vite/blob/4f5845a3182fc950eb9cd76d7161698383113b18/packages/vite/src/node/config.ts#L1063
|
|
123
|
+
return toPosixPath(
|
|
124
|
+
// Equivalent to `path.resolve(process.cwd(), root)`
|
|
125
|
+
path.resolve(root));
|
|
120
126
|
}
|
|
121
127
|
const errMsg = `A Vite plugin is modifying Vite's setting ${pc.cyan('root')} which is forbidden`;
|
|
122
128
|
async function assertViteRoot2(root, viteConfigEnhanced, operation) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export default plugin;
|
|
2
2
|
export { plugin };
|
|
3
3
|
export { plugin as ssr };
|
|
4
|
+
export { getVikeConfigPublic as getVikeConfig } from './plugins/commonConfig.js';
|
|
5
|
+
export { PROJECT_VERSION as version } from './utils.js';
|
|
4
6
|
export type { VikeVitePluginOptions as UserConfig };
|
|
5
7
|
export type { VikeVitePluginOptions };
|
|
6
|
-
export { PROJECT_VERSION as version } from './utils.js';
|
|
7
8
|
type PluginInterop = Record<string, unknown> & {
|
|
8
9
|
name: string;
|
|
9
10
|
};
|
|
@@ -2,21 +2,16 @@ export default plugin;
|
|
|
2
2
|
export { plugin };
|
|
3
3
|
// TODO/v1-release: remove
|
|
4
4
|
export { plugin as ssr };
|
|
5
|
+
export { getVikeConfigPublic as getVikeConfig } from './plugins/commonConfig.js';
|
|
5
6
|
export { PROJECT_VERSION as version } from './utils.js';
|
|
6
7
|
import { assertUsage } from './utils.js';
|
|
7
|
-
import {
|
|
8
|
+
import { build } from './plugins/build.js';
|
|
8
9
|
import { previewConfig } from './plugins/previewConfig.js';
|
|
9
|
-
import { autoFullBuild } from './plugins/autoFullBuild.js';
|
|
10
10
|
import { devConfig } from './plugins/devConfig/index.js';
|
|
11
|
-
import { packageJsonFile } from './plugins/packageJsonFile.js';
|
|
12
|
-
import { removeRequireHookPlugin } from './plugins/removeRequireHookPlugin.js';
|
|
13
11
|
import { importUserCode } from './plugins/importUserCode/index.js';
|
|
14
|
-
import { distFileNames } from './plugins/distFileNames.js';
|
|
15
12
|
import { extractAssetsPlugin } from './plugins/extractAssetsPlugin.js';
|
|
16
13
|
import { extractExportNamesPlugin } from './plugins/extractExportNamesPlugin.js';
|
|
17
|
-
import { suppressRollupWarning } from './plugins/suppressRollupWarning.js';
|
|
18
14
|
import { setGlobalContext } from './plugins/setGlobalContext.js';
|
|
19
|
-
import { buildEntry } from './plugins/buildEntry/index.js';
|
|
20
15
|
import { commonConfig } from './plugins/commonConfig.js';
|
|
21
16
|
import { baseUrls } from './plugins/baseUrls.js';
|
|
22
17
|
import { envVarsPlugin } from './plugins/envVars.js';
|
|
@@ -26,7 +21,6 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
|
|
|
26
21
|
import { resolveClientEntriesDev } from './shared/resolveClientEntriesDev.js';
|
|
27
22
|
import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
|
|
28
23
|
import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegression.js';
|
|
29
|
-
import { buildApp } from './plugins/buildApp.js';
|
|
30
24
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
31
25
|
setResolveClientEntriesDev(resolveClientEntriesDev);
|
|
32
26
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
@@ -35,18 +29,11 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
35
29
|
...commonConfig(vikeVitePluginOptions),
|
|
36
30
|
importUserCode(),
|
|
37
31
|
...devConfig(),
|
|
38
|
-
...
|
|
39
|
-
...buildApp(),
|
|
32
|
+
...build(),
|
|
40
33
|
previewConfig(),
|
|
41
|
-
...autoFullBuild(),
|
|
42
|
-
packageJsonFile(),
|
|
43
|
-
removeRequireHookPlugin(),
|
|
44
|
-
distFileNames(),
|
|
45
34
|
...extractAssetsPlugin(),
|
|
46
35
|
extractExportNamesPlugin(),
|
|
47
|
-
suppressRollupWarning(),
|
|
48
36
|
...setGlobalContext(),
|
|
49
|
-
...buildEntry(),
|
|
50
37
|
baseUrls(),
|
|
51
38
|
envVarsPlugin(),
|
|
52
39
|
fileEnv(),
|
|
@@ -63,7 +50,7 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
63
50
|
assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
|
|
64
51
|
}
|
|
65
52
|
});
|
|
66
|
-
//
|
|
53
|
+
// CJS default export `const vike = require('vike/plugin')`
|
|
67
54
|
// - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
|
|
68
55
|
try {
|
|
69
56
|
module.exports = Object.assign(exports.default, exports);
|
|
@@ -2,6 +2,7 @@ export { baseUrls };
|
|
|
2
2
|
import { resolveBase } from '../../shared/resolveBase.js';
|
|
3
3
|
import { assert } from '../utils.js';
|
|
4
4
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
5
|
+
import { getVikeConfigPublic } from './commonConfig.js';
|
|
5
6
|
function baseUrls() {
|
|
6
7
|
let basesResolved;
|
|
7
8
|
return {
|
|
@@ -11,7 +12,8 @@ function baseUrls() {
|
|
|
11
12
|
const isDev = config._isDev;
|
|
12
13
|
assert(typeof isDev === 'boolean');
|
|
13
14
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
14
|
-
|
|
15
|
+
const vike = getVikeConfigPublic(config);
|
|
16
|
+
basesResolved = resolveBase(baseViteOriginal, vike.config.baseServer ?? null, vike.config.baseAssets ?? null);
|
|
15
17
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
16
18
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
17
19
|
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { handleAssetsManifest };
|
|
2
|
+
export { handleAssetsManifest_getBuildConfig };
|
|
3
|
+
export { handleAssetsManifest_isFixEnabled };
|
|
4
|
+
export { handleAssetsManifest_assertUsageCssCodeSplit };
|
|
5
|
+
export { handleAssetsManifest_assertUsageCssTarget };
|
|
6
|
+
import type { Environment, ResolvedConfig, Rollup, UserConfig } from 'vite';
|
|
7
|
+
type Bundle = Rollup.OutputBundle;
|
|
8
|
+
type Options = Rollup.NormalizedOutputOptions;
|
|
9
|
+
declare function handleAssetsManifest_isFixEnabled(config: ResolvedConfig | UserConfig): boolean;
|
|
10
|
+
declare function handleAssetsManifest_assertUsageCssCodeSplit(config: ResolvedConfig): void;
|
|
11
|
+
declare function handleAssetsManifest_assertUsageCssTarget(config: ResolvedConfig): void;
|
|
12
|
+
declare function handleAssetsManifest_getBuildConfig(config: UserConfig): {
|
|
13
|
+
readonly ssrEmitAssets: true | undefined;
|
|
14
|
+
readonly cssMinify: "esbuild" | undefined;
|
|
15
|
+
readonly manifest: "_temp_manifest.json";
|
|
16
|
+
readonly copyPublicDir: boolean | undefined;
|
|
17
|
+
};
|
|
18
|
+
declare function handleAssetsManifest(config: ResolvedConfig, viteEnv: Environment | undefined, options: Options, bundle: Bundle): Promise<void>;
|
|
@@ -1,56 +1,48 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { handleAssetsManifest };
|
|
2
|
+
export { handleAssetsManifest_getBuildConfig };
|
|
3
|
+
export { handleAssetsManifest_isFixEnabled };
|
|
4
|
+
export { handleAssetsManifest_assertUsageCssCodeSplit };
|
|
5
|
+
export { handleAssetsManifest_assertUsageCssTarget };
|
|
5
6
|
import fs from 'fs/promises';
|
|
6
7
|
import fs_sync from 'fs';
|
|
7
8
|
import path from 'path';
|
|
8
9
|
import { existsSync } from 'fs';
|
|
9
|
-
import { assert, assertWarning, isEqualStringList, pLimit, unique } from '../../utils.js';
|
|
10
|
+
import { assert, assertIsSingleModuleInstance, assertWarning, isEqualStringList, isObject, pLimit, unique } from '../../utils.js';
|
|
10
11
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
11
|
-
import { manifestTempFile } from '
|
|
12
|
+
import { manifestTempFile } from './pluginBuildConfig.js';
|
|
12
13
|
import { getAssetsDir } from '../../shared/getAssetsDir.js';
|
|
13
14
|
import pc from '@brillout/picocolors';
|
|
14
15
|
import { isV1Design } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
15
16
|
import { getOutDirs } from '../../shared/getOutDirs.js';
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
return true;
|
|
17
|
+
import { isViteServerBuild_onlySsrEnv, isViteServerBuild } from '../../shared/isViteServerBuild.js';
|
|
18
|
+
import { getVikeConfigPublic } from '../commonConfig.js';
|
|
19
|
+
import { set_macro_ASSETS_MANIFEST } from './pluginBuildEntry.js';
|
|
20
|
+
assertIsSingleModuleInstance('build/handleAssetsManifest.ts');
|
|
21
|
+
let assetsJsonFilePath;
|
|
22
|
+
// true => use workaround config.build.ssrEmitAssets
|
|
23
|
+
// false => use workaround extractAssets plugin
|
|
24
|
+
function handleAssetsManifest_isFixEnabled(config) {
|
|
25
|
+
// Allow user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
|
|
26
|
+
return isV1Design(config);
|
|
27
27
|
}
|
|
28
28
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
29
29
|
async function fixServerAssets(config) {
|
|
30
30
|
const outDirs = getOutDirs(config);
|
|
31
|
-
const clientManifest = await
|
|
32
|
-
const serverManifest = await
|
|
33
|
-
const { clientManifestMod, serverManifestMod,
|
|
34
|
-
await copyAssets(
|
|
31
|
+
const clientManifest = await readManifestFile(outDirs.outDirClient);
|
|
32
|
+
const serverManifest = await readManifestFile(outDirs.outDirServer);
|
|
33
|
+
const { clientManifestMod, serverManifestMod, filesToMove, filesToRemove } = addServerAssets(clientManifest, serverManifest);
|
|
34
|
+
await copyAssets(filesToMove, filesToRemove, config);
|
|
35
35
|
return { clientManifestMod, serverManifestMod };
|
|
36
36
|
}
|
|
37
|
-
async function
|
|
38
|
-
const manifestFilePath = path.posix.join(outDir, manifestTempFile);
|
|
39
|
-
const manifestFileContent = await fs.readFile(manifestFilePath, 'utf-8');
|
|
40
|
-
assert(manifestFileContent);
|
|
41
|
-
const manifest = JSON.parse(manifestFileContent);
|
|
42
|
-
assert(manifest);
|
|
43
|
-
return manifest;
|
|
44
|
-
}
|
|
45
|
-
async function copyAssets(filesToCopy, filesToRemove, config) {
|
|
37
|
+
async function copyAssets(filesToMove, filesToRemove, config) {
|
|
46
38
|
const { outDirClient, outDirServer } = getOutDirs(config);
|
|
47
39
|
const assetsDir = getAssetsDir(config);
|
|
48
40
|
const assetsDirServer = path.posix.join(outDirServer, assetsDir);
|
|
49
|
-
if (!
|
|
41
|
+
if (!filesToMove.length && !filesToRemove.length && !existsSync(assetsDirServer))
|
|
50
42
|
return;
|
|
51
43
|
assert(existsSync(assetsDirServer));
|
|
52
44
|
const concurrencyLimit = pLimit(10);
|
|
53
|
-
await Promise.all(
|
|
45
|
+
await Promise.all(filesToMove.map((file) => concurrencyLimit(async () => {
|
|
54
46
|
const source = path.posix.join(outDirServer, file);
|
|
55
47
|
const target = path.posix.join(outDirClient, file);
|
|
56
48
|
await fs.mkdir(path.posix.dirname(target), { recursive: true });
|
|
@@ -86,19 +78,20 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
86
78
|
assert(!entriesServer.has(pageId));
|
|
87
79
|
entriesServer.set(pageId, { key, ...resources });
|
|
88
80
|
}
|
|
89
|
-
let
|
|
81
|
+
let filesToMove = [];
|
|
90
82
|
let filesToRemove = [];
|
|
83
|
+
// Copy page assets
|
|
91
84
|
for (const [pageId, entryClient] of entriesClient.entries()) {
|
|
92
85
|
const entryServer = entriesServer.get(pageId);
|
|
93
86
|
if (!entryServer)
|
|
94
87
|
continue;
|
|
95
|
-
const
|
|
88
|
+
const cssToMove = [];
|
|
96
89
|
const cssToRemove = [];
|
|
97
|
-
const
|
|
90
|
+
const assetsToMove = [];
|
|
98
91
|
const assetsToRemove = [];
|
|
99
92
|
entryServer.css.forEach((cssServer) => {
|
|
100
93
|
if (!entryClient.css.some((cssClient) => cssServer.hash === cssClient.hash)) {
|
|
101
|
-
|
|
94
|
+
cssToMove.push(cssServer.src);
|
|
102
95
|
}
|
|
103
96
|
else {
|
|
104
97
|
cssToRemove.push(cssServer.src);
|
|
@@ -106,17 +99,17 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
106
99
|
});
|
|
107
100
|
entryServer.assets.forEach((assetServer) => {
|
|
108
101
|
if (!entryClient.assets.some((assetClient) => assetServer.hash === assetClient.hash)) {
|
|
109
|
-
|
|
102
|
+
assetsToMove.push(assetServer.src);
|
|
110
103
|
}
|
|
111
104
|
else {
|
|
112
105
|
assetsToRemove.push(assetServer.src);
|
|
113
106
|
}
|
|
114
107
|
});
|
|
115
|
-
if (
|
|
108
|
+
if (cssToMove.length) {
|
|
116
109
|
const { key } = entryClient;
|
|
117
|
-
|
|
110
|
+
filesToMove.push(...cssToMove);
|
|
118
111
|
(_a = clientManifest[key]).css ?? (_a.css = []);
|
|
119
|
-
clientManifest[key].css?.push(...
|
|
112
|
+
clientManifest[key].css?.push(...cssToMove);
|
|
120
113
|
}
|
|
121
114
|
if (cssToRemove.length) {
|
|
122
115
|
const { key } = entryServer;
|
|
@@ -124,11 +117,11 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
124
117
|
(_b = serverManifest[key]).css ?? (_b.css = []);
|
|
125
118
|
serverManifest[key].css = serverManifest[key].css.filter((entry) => !cssToRemove.includes(entry));
|
|
126
119
|
}
|
|
127
|
-
if (
|
|
120
|
+
if (assetsToMove.length) {
|
|
128
121
|
const { key } = entryClient;
|
|
129
|
-
|
|
122
|
+
filesToMove.push(...assetsToMove);
|
|
130
123
|
(_c = clientManifest[key]).assets ?? (_c.assets = []);
|
|
131
|
-
clientManifest[key].assets?.push(...
|
|
124
|
+
clientManifest[key].assets?.push(...assetsToMove);
|
|
132
125
|
}
|
|
133
126
|
if (assetsToRemove.length) {
|
|
134
127
|
const { key } = entryServer;
|
|
@@ -137,11 +130,40 @@ function addServerAssets(clientManifest, serverManifest) {
|
|
|
137
130
|
serverManifest[key].assets = serverManifest[key].assets.filter((entry) => !assetsToRemove.includes(entry));
|
|
138
131
|
}
|
|
139
132
|
}
|
|
133
|
+
// Also copy assets of virtual:@brillout/vite-plugin-server-entry:serverEntry
|
|
134
|
+
{
|
|
135
|
+
const filesClientAll = [];
|
|
136
|
+
for (const key in clientManifest) {
|
|
137
|
+
const entry = clientManifest[key];
|
|
138
|
+
filesClientAll.push(entry.file);
|
|
139
|
+
filesClientAll.push(...(entry.assets ?? []));
|
|
140
|
+
filesClientAll.push(...(entry.css ?? []));
|
|
141
|
+
}
|
|
142
|
+
for (const key in serverManifest) {
|
|
143
|
+
const entry = serverManifest[key];
|
|
144
|
+
if (!entry.isEntry)
|
|
145
|
+
continue;
|
|
146
|
+
const resources = collectResources(entry, serverManifest);
|
|
147
|
+
const css = resources.css.map((css) => css.src).filter((file) => !filesClientAll.includes(file));
|
|
148
|
+
const assets = resources.assets.map((asset) => asset.src).filter((file) => !filesClientAll.includes(file));
|
|
149
|
+
filesToMove.push(...css, ...assets);
|
|
150
|
+
if (css.length > 0 || assets.length > 0) {
|
|
151
|
+
assert(!clientManifest[key]);
|
|
152
|
+
clientManifest[key] = {
|
|
153
|
+
...entry,
|
|
154
|
+
css,
|
|
155
|
+
assets,
|
|
156
|
+
dynamicImports: undefined,
|
|
157
|
+
imports: undefined
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
140
162
|
const clientManifestMod = clientManifest;
|
|
141
163
|
const serverManifestMod = serverManifest;
|
|
142
|
-
|
|
143
|
-
filesToRemove = unique(filesToRemove).filter((file) => !
|
|
144
|
-
return { clientManifestMod, serverManifestMod,
|
|
164
|
+
filesToMove = unique(filesToMove);
|
|
165
|
+
filesToRemove = unique(filesToRemove).filter((file) => !filesToMove.includes(file));
|
|
166
|
+
return { clientManifestMod, serverManifestMod, filesToMove, filesToRemove };
|
|
145
167
|
}
|
|
146
168
|
function getPageId(key) {
|
|
147
169
|
// Normalize from:
|
|
@@ -184,22 +206,22 @@ function collectResources(entryRoot, manifest) {
|
|
|
184
206
|
// </head>
|
|
185
207
|
// ```
|
|
186
208
|
function getHash(src) {
|
|
187
|
-
// src is guarenteed to end with `.[hash][extname]`, see
|
|
209
|
+
// src is guarenteed to end with `.[hash][extname]`, see pluginDistFileNames.ts
|
|
188
210
|
const hash = src.split('.').at(-2);
|
|
189
211
|
assert(hash);
|
|
190
212
|
return hash;
|
|
191
213
|
}
|
|
192
214
|
// https://github.com/vikejs/vike/issues/1993
|
|
193
|
-
function
|
|
215
|
+
function handleAssetsManifest_assertUsageCssCodeSplit(config) {
|
|
216
|
+
if (!handleAssetsManifest_isFixEnabled(config))
|
|
217
|
+
return;
|
|
194
218
|
assertWarning(config.build.cssCodeSplit, `${pc.cyan('build.cssCodeSplit')} shouldn't be set to ${pc.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
|
|
195
219
|
}
|
|
196
220
|
const targets = [];
|
|
197
|
-
|
|
198
|
-
if (!
|
|
199
|
-
return;
|
|
200
|
-
if (!(await isV1Design(config)))
|
|
221
|
+
function handleAssetsManifest_assertUsageCssTarget(config) {
|
|
222
|
+
if (!handleAssetsManifest_isFixEnabled(config))
|
|
201
223
|
return;
|
|
202
|
-
const isServerSide =
|
|
224
|
+
const isServerSide = isViteServerBuild(config);
|
|
203
225
|
assert(typeof isServerSide === 'boolean');
|
|
204
226
|
assert(config.build.target !== undefined);
|
|
205
227
|
targets.push({ global: config.build.target, css: config.build.cssTarget, isServerSide });
|
|
@@ -244,3 +266,59 @@ function removeEmptyDirectories(dirPath) {
|
|
|
244
266
|
fs_sync.rmdirSync(dirPath);
|
|
245
267
|
}
|
|
246
268
|
}
|
|
269
|
+
async function readManifestFile(outDir) {
|
|
270
|
+
const manifestFilePath = path.posix.join(outDir, manifestTempFile);
|
|
271
|
+
const manifestFileContent = await fs.readFile(manifestFilePath, 'utf-8');
|
|
272
|
+
assert(manifestFileContent);
|
|
273
|
+
const manifest = JSON.parse(manifestFileContent);
|
|
274
|
+
assert(manifest);
|
|
275
|
+
assert(isObject(manifest));
|
|
276
|
+
return manifest;
|
|
277
|
+
}
|
|
278
|
+
async function writeManifestFile(manifest, manifestFilePath) {
|
|
279
|
+
assert(isObject(manifest));
|
|
280
|
+
const manifestFileContent = JSON.stringify(manifest, null, 2);
|
|
281
|
+
await fs.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
|
|
282
|
+
}
|
|
283
|
+
function handleAssetsManifest_getBuildConfig(config) {
|
|
284
|
+
const vike = getVikeConfigPublic(config);
|
|
285
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
286
|
+
return {
|
|
287
|
+
// https://github.com/vikejs/vike/issues/1339
|
|
288
|
+
ssrEmitAssets: isFixEnabled ? true : undefined,
|
|
289
|
+
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
290
|
+
cssMinify: isFixEnabled ? 'esbuild' : undefined,
|
|
291
|
+
manifest: manifestTempFile,
|
|
292
|
+
copyPublicDir: vike.config.vite6BuilderApp
|
|
293
|
+
? // Already set by vike:build:pluginBuildApp
|
|
294
|
+
undefined
|
|
295
|
+
: !isViteServerBuild(config)
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
299
|
+
if (isViteServerBuild_onlySsrEnv(config, viteEnv)) {
|
|
300
|
+
assert(!assetsJsonFilePath);
|
|
301
|
+
const outDirs = getOutDirs(config, viteEnv);
|
|
302
|
+
assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
303
|
+
await writeAssetsManifestFile(outDirs, assetsJsonFilePath, config);
|
|
304
|
+
}
|
|
305
|
+
if (isViteServerBuild(config, viteEnv)) {
|
|
306
|
+
assert(assetsJsonFilePath);
|
|
307
|
+
// Replace __VITE_ASSETS_MANIFEST__ in all server-side bundles
|
|
308
|
+
await set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
|
|
312
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
313
|
+
const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
314
|
+
const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
315
|
+
if (!isFixEnabled) {
|
|
316
|
+
await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
const { clientManifestMod } = await fixServerAssets(config);
|
|
320
|
+
await writeManifestFile(clientManifestMod, assetsJsonFilePath);
|
|
321
|
+
}
|
|
322
|
+
await fs.rm(clientManifestFilePath);
|
|
323
|
+
await fs.rm(serverManifestFilePath);
|
|
324
|
+
}
|