vike 0.4.223 → 0.4.224-commit-f0d0f8a
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/devConfig/index.js +1 -1
- 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/plugins/previewConfig.js +12 -7
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +5 -1
- 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 +30 -21
- package/dist/cjs/node/prerender/runPrerender.js +28 -30
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/html/stream.js +7 -0
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +13 -2
- 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/debug.js +2 -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 +16 -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/devConfig/index.js +1 -1
- 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/plugins/previewConfig.js +12 -7
- package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +1 -1
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +5 -1
- 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 +11 -6
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +31 -22
- package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
- package/dist/esm/node/prerender/runPrerender.js +29 -31
- 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 +3 -2
- package/dist/esm/node/runtime/html/stream.js +7 -0
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +13 -2
- 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/types/index.d.ts +2 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/debug.js +2 -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 +9 -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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export { pluginAutoFullBuild };
|
|
2
|
+
export { isPrerenderForceExit };
|
|
3
|
+
import { build } from 'vite';
|
|
4
|
+
import { assert, assertIsSingleModuleInstance, assertWarning, onSetupBuild } from '../../utils.js';
|
|
5
|
+
import { runPrerenderFromAutoRun, runPrerender_forceExit } from '../../../prerender/runPrerender.js';
|
|
6
|
+
import { isPrerenderAutoRunEnabled } from '../../../prerender/context.js';
|
|
7
|
+
import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
|
|
8
|
+
import pc from '@brillout/picocolors';
|
|
9
|
+
import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
|
|
10
|
+
import { manifestTempFile } from './pluginBuildConfig.js';
|
|
11
|
+
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
12
|
+
import { isVikeCliOrApi } from '../../../api/context.js';
|
|
13
|
+
import { handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget } from './handleAssetsManifest.js';
|
|
14
|
+
import { isViteClientBuild, isViteServerBuild_onlySsrEnv } from '../../shared/isViteServerBuild.js';
|
|
15
|
+
assertIsSingleModuleInstance('build/pluginAutoFullBuild.ts');
|
|
16
|
+
let forceExit = false;
|
|
17
|
+
function pluginAutoFullBuild() {
|
|
18
|
+
let config;
|
|
19
|
+
let vikeConfig;
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
name: 'vike:build:pluginAutoFullBuild',
|
|
23
|
+
apply: 'build',
|
|
24
|
+
enforce: 'pre',
|
|
25
|
+
async configResolved(config_) {
|
|
26
|
+
vikeConfig = await getVikeConfig(config_);
|
|
27
|
+
config = config_;
|
|
28
|
+
abortViteBuildSsr(vikeConfig);
|
|
29
|
+
},
|
|
30
|
+
writeBundle: {
|
|
31
|
+
/* We can't use this because it breaks Vite's logging. TODO/eventually: try again with latest Vite version.
|
|
32
|
+
sequential: true,
|
|
33
|
+
order: 'pre',
|
|
34
|
+
*/
|
|
35
|
+
async handler(options, bundle) {
|
|
36
|
+
await handleAssetsManifest(config, this.environment, options, bundle);
|
|
37
|
+
await triggerFullBuild(config, vikeConfig, this.environment, bundle);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'vike:build:pluginAutoFullBuild:forceExit',
|
|
43
|
+
apply: 'build',
|
|
44
|
+
enforce: 'post',
|
|
45
|
+
closeBundle: {
|
|
46
|
+
sequential: true,
|
|
47
|
+
order: 'post',
|
|
48
|
+
handler() {
|
|
49
|
+
onSetupBuild();
|
|
50
|
+
handleAssetsManifest_assertUsageCssTarget(config);
|
|
51
|
+
if (forceExit &&
|
|
52
|
+
// Let vike:build:pluginBuildApp force exit
|
|
53
|
+
!vikeConfig.global.config.vite6BuilderApp) {
|
|
54
|
+
runPrerender_forceExit();
|
|
55
|
+
assert(false);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
async function triggerFullBuild(config, vikeConfig, viteEnv, bundle) {
|
|
63
|
+
// Whether builder.buildApp() is being used, see plugin:build:pluginBuildApp
|
|
64
|
+
const isBuilderApp = vikeConfig.global.config.vite6BuilderApp;
|
|
65
|
+
// If builder.buildApp() => trigger at end of `this.environment.name === 'ssr'`.
|
|
66
|
+
// Else => trigger at end of client-side build.
|
|
67
|
+
if (isBuilderApp ? !isViteServerBuild_onlySsrEnv(config, viteEnv) : !isViteClientBuild(config, viteEnv))
|
|
68
|
+
return;
|
|
69
|
+
if (isEntirelyDisabled(vikeConfig))
|
|
70
|
+
return;
|
|
71
|
+
// Workaround for @vitejs/plugin-legacy
|
|
72
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
73
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
74
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
75
|
+
if (!bundle[manifestTempFile])
|
|
76
|
+
return;
|
|
77
|
+
const configInline = getFullBuildInlineConfig(config);
|
|
78
|
+
if (!isBuilderApp) {
|
|
79
|
+
try {
|
|
80
|
+
await build(setSSR(configInline));
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
// Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
84
|
+
console.error(err);
|
|
85
|
+
logErrorHint(err);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// The server bulid is already called by builder.buildApp()
|
|
91
|
+
}
|
|
92
|
+
if (isPrerenderAutoRunEnabled(vikeConfig)) {
|
|
93
|
+
const res = await runPrerenderFromAutoRun(configInline, config);
|
|
94
|
+
forceExit = res.forceExit;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function setSSR(configInline) {
|
|
98
|
+
return {
|
|
99
|
+
...configInline,
|
|
100
|
+
build: {
|
|
101
|
+
...configInline.build,
|
|
102
|
+
ssr: true
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function abortViteBuildSsr(vikeConfig) {
|
|
107
|
+
if (vikeConfig.global.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
108
|
+
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 });
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function isEntirelyDisabled(vikeConfig) {
|
|
113
|
+
const { disableAutoFullBuild } = vikeConfig.global.config;
|
|
114
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
115
|
+
const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
|
|
116
|
+
return isUserUsingViteApi;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return disableAutoFullBuild;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function isPrerenderForceExit() {
|
|
123
|
+
return forceExit;
|
|
124
|
+
}
|
|
125
|
+
function getFullBuildInlineConfig(config) {
|
|
126
|
+
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
127
|
+
if (config._viteConfigEnhanced) {
|
|
128
|
+
return config._viteConfigEnhanced;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
return {
|
|
132
|
+
...configFromCli,
|
|
133
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
134
|
+
root: config.root,
|
|
135
|
+
build: {
|
|
136
|
+
...configFromCli?.build
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export { pluginBuildApp };
|
|
2
|
+
import { runPrerender_forceExit } from '../../../prerender/runPrerender.js';
|
|
3
|
+
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
4
|
+
import { assert } from '../../utils.js';
|
|
5
|
+
import { getVikeConfigPublic } from '../commonConfig.js';
|
|
6
|
+
import { isPrerenderForceExit } from './pluginAutoFullBuild.js';
|
|
7
|
+
function pluginBuildApp() {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: 'vike:build:pluginBuildApp',
|
|
11
|
+
apply: 'build',
|
|
12
|
+
config(config) {
|
|
13
|
+
const vike = getVikeConfigPublic(config);
|
|
14
|
+
if (!vike.config.vite6BuilderApp)
|
|
15
|
+
return;
|
|
16
|
+
return {
|
|
17
|
+
builder: {
|
|
18
|
+
// Can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
19
|
+
async buildApp(builder) {
|
|
20
|
+
assert(builder.environments.client);
|
|
21
|
+
assert(builder.environments.ssr);
|
|
22
|
+
await builder.build(builder.environments.client);
|
|
23
|
+
await builder.build(builder.environments.ssr);
|
|
24
|
+
if (isPrerenderForceExit()) {
|
|
25
|
+
runPrerender_forceExit();
|
|
26
|
+
assert(false);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
environments: {
|
|
31
|
+
ssr: {
|
|
32
|
+
consumer: 'server',
|
|
33
|
+
build: {
|
|
34
|
+
outDir: resolveOutDir(config, true),
|
|
35
|
+
ssr: true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
client: {
|
|
39
|
+
consumer: 'client',
|
|
40
|
+
build: {
|
|
41
|
+
copyPublicDir: true,
|
|
42
|
+
ssr: false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
5
|
import type { ResolvedConfig, Plugin } from 'vite';
|
|
6
|
-
import type { PageConfigBuildTime } from '
|
|
6
|
+
import type { PageConfigBuildTime } from '../../../../shared/page-configs/PageConfig.js';
|
|
7
7
|
declare const manifestTempFile = "_temp_manifest.json";
|
|
8
|
-
declare function
|
|
8
|
+
declare function pluginBuildConfig(): Plugin[];
|
|
9
9
|
declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config: ResolvedConfig): {
|
|
10
10
|
hasClientRouting: boolean;
|
|
11
11
|
hasServerRouting: boolean;
|
|
@@ -1,56 +1,41 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
4
|
export { manifestTempFile };
|
|
5
|
-
import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsNpmPackageImport } from '
|
|
6
|
-
import { getVikeConfig
|
|
7
|
-
import { findPageFiles } from '
|
|
8
|
-
import { getVirtualFileIdPageConfigValuesAll } from '
|
|
9
|
-
import { extractAssetsAddQuery } from '
|
|
5
|
+
import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsNpmPackageImport } from '../../utils.js';
|
|
6
|
+
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
7
|
+
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
8
|
+
import { getVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
9
|
+
import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
10
10
|
import { createRequire } from 'module';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import { getOutDirs, resolveOutDir } from '../shared/getOutDirs.js';
|
|
19
|
-
import { viteIsSSR } from '../shared/viteIsSSR.js';
|
|
20
|
-
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
11
|
+
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
12
|
+
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
13
|
+
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
14
|
+
import { isViteServerBuild } from '../../shared/isViteServerBuild.js';
|
|
15
|
+
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
16
|
+
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig } from './handleAssetsManifest.js';
|
|
17
|
+
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
21
18
|
const importMetaUrl = import.meta.url;
|
|
22
19
|
const require_ = createRequire(importMetaUrl);
|
|
23
20
|
const manifestTempFile = '_temp_manifest.json';
|
|
24
|
-
function
|
|
25
|
-
let isServerAssetsFixEnabled;
|
|
26
|
-
let outDirs;
|
|
21
|
+
function pluginBuildConfig() {
|
|
27
22
|
let config;
|
|
28
23
|
return [
|
|
29
24
|
{
|
|
30
|
-
name: 'vike:
|
|
25
|
+
name: 'vike:build:pluginBuildConfig',
|
|
31
26
|
apply: 'build',
|
|
32
27
|
enforce: 'post',
|
|
33
28
|
configResolved: {
|
|
34
29
|
order: 'post',
|
|
35
30
|
async handler(config_) {
|
|
36
|
-
config = config_;
|
|
37
31
|
onSetupBuild();
|
|
32
|
+
config = config_;
|
|
38
33
|
assertRollupInput(config);
|
|
39
34
|
const entries = await getEntries(config);
|
|
40
35
|
assert(Object.keys(entries).length > 0);
|
|
41
36
|
config.build.rollupOptions.input = injectRollupInputs(entries, config);
|
|
42
37
|
addLogHook();
|
|
43
|
-
|
|
44
|
-
{
|
|
45
|
-
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config));
|
|
46
|
-
if (isServerAssetsFixEnabled) {
|
|
47
|
-
// https://github.com/vikejs/vike/issues/1339
|
|
48
|
-
config.build.ssrEmitAssets = true;
|
|
49
|
-
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
50
|
-
config.build.cssMinify = 'esbuild';
|
|
51
|
-
fixServerAssets_assertCssCodeSplit(config);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
38
|
+
handleAssetsManifest_assertUsageCssCodeSplit(config);
|
|
54
39
|
}
|
|
55
40
|
},
|
|
56
41
|
config: {
|
|
@@ -60,56 +45,13 @@ function buildConfig() {
|
|
|
60
45
|
return {
|
|
61
46
|
build: {
|
|
62
47
|
outDir: resolveOutDir(config),
|
|
63
|
-
|
|
64
|
-
copyPublicDir: config.vike.config.viteEnvironmentAPI
|
|
65
|
-
? // Already set by buildApp() plugin
|
|
66
|
-
undefined
|
|
67
|
-
: !viteIsSSR(config)
|
|
48
|
+
...handleAssetsManifest_getBuildConfig(config)
|
|
68
49
|
}
|
|
69
50
|
};
|
|
70
51
|
}
|
|
71
52
|
},
|
|
72
53
|
buildStart() {
|
|
73
54
|
onSetupBuild();
|
|
74
|
-
},
|
|
75
|
-
async closeBundle() {
|
|
76
|
-
onSetupBuild();
|
|
77
|
-
await fixServerAssets_assertCssTarget(config);
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'vike:buildConfig:pre',
|
|
82
|
-
apply: 'build',
|
|
83
|
-
applyToEnvironment(env) {
|
|
84
|
-
return env.name === 'ssr';
|
|
85
|
-
},
|
|
86
|
-
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
87
|
-
// - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
|
|
88
|
-
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
89
|
-
enforce: 'pre',
|
|
90
|
-
writeBundle: {
|
|
91
|
-
order: 'pre',
|
|
92
|
-
sequential: true,
|
|
93
|
-
async handler(options, bundle) {
|
|
94
|
-
if (viteIsSSR(config)) {
|
|
95
|
-
// Ideally we'd move dist/_temp_manifest.json to dist/server/client-assets.json instead of dist/assets.json
|
|
96
|
-
// - But we can't because there is no guarentee whether dist/server/ is generated before or after dist/client/ (generating dist/server/ after dist/client/ erases dist/server/client-assets.json)
|
|
97
|
-
// - We'll able to do so once we replace `$ vite build` with `$ vike build`
|
|
98
|
-
const assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
99
|
-
const clientManifestFilePath = path.posix.join(outDirs.outDirClient, manifestTempFile);
|
|
100
|
-
const serverManifestFilePath = path.posix.join(outDirs.outDirServer, manifestTempFile);
|
|
101
|
-
if (!isServerAssetsFixEnabled) {
|
|
102
|
-
await fs.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
const { clientManifestMod } = await fixServerAssets(config);
|
|
106
|
-
await fs.writeFile(assetsJsonFilePath, JSON.stringify(clientManifestMod, null, 2), 'utf-8');
|
|
107
|
-
}
|
|
108
|
-
await fs.rm(clientManifestFilePath);
|
|
109
|
-
await fs.rm(serverManifestFilePath);
|
|
110
|
-
await set_ASSETS_MANIFEST(options, bundle);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
55
|
}
|
|
114
56
|
}
|
|
115
57
|
];
|
|
@@ -122,10 +64,9 @@ async function getEntries(config) {
|
|
|
122
64
|
// TODO/now: add meta.default
|
|
123
65
|
vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
124
66
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
125
|
-
if (
|
|
67
|
+
if (isViteServerBuild(config)) {
|
|
126
68
|
const pageEntries = getPageEntries(pageConfigs);
|
|
127
69
|
const entries = {
|
|
128
|
-
// buildEntry: resolve('dist/esm/node/buildEntry.js'), // TODO/next-major-release: remove
|
|
129
70
|
...pageFileEntries,
|
|
130
71
|
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
131
72
|
...pageEntries
|
|
@@ -196,7 +137,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
196
137
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
197
138
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
198
139
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
199
|
-
const isForClientSide = !
|
|
140
|
+
const isForClientSide = !isViteServerBuild(config);
|
|
200
141
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
201
142
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
202
143
|
fileTypes.push('.page.server');
|
|
@@ -255,8 +196,8 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
|
255
196
|
}
|
|
256
197
|
function resolve(filePath) {
|
|
257
198
|
assert(filePath.startsWith('dist/'));
|
|
258
|
-
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
259
|
-
return require_.resolve(
|
|
199
|
+
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/build/
|
|
200
|
+
return require_.resolve(`../../../../../../${filePath}`);
|
|
260
201
|
}
|
|
261
202
|
function addLogHook() {
|
|
262
203
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|