vike 0.4.219 → 0.4.220-commit-9a798ce
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 +23 -58
- package/dist/cjs/node/api/context.js +6 -8
- package/dist/cjs/node/api/prepareViteApiCall.js +6 -7
- package/dist/cjs/node/api/utils.js +1 -1
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +2 -0
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/{utils → node/plugin}/getOutDirs.js +11 -11
- package/dist/cjs/node/plugin/index.js +1 -7
- package/dist/cjs/node/plugin/onLoad.js +6 -1
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +43 -31
- package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -3
- package/dist/cjs/node/plugin/plugins/buildEntry/index.js +24 -21
- package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -8
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +158 -176
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/context.js +26 -0
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
- package/dist/cjs/node/prerender/runPrerender.js +64 -37
- package/dist/cjs/node/prerender/utils.js +3 -2
- package/dist/cjs/node/runtime/globalContext.js +44 -58
- package/dist/cjs/node/runtime/page-files/setup.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
- package/dist/cjs/node/runtime/renderPage.js +10 -5
- package/dist/cjs/node/runtime/utils.js +3 -2
- package/dist/cjs/node/shared/resolveBase.js +9 -0
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +15 -1
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/findFile.js +3 -3
- package/dist/cjs/utils/isDev.js +4 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/requireResolve.js +3 -3
- 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/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/shared/normalizeClientSideUrl.js +2 -3
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +20 -25
- package/dist/esm/node/api/context.d.ts +4 -4
- package/dist/esm/node/api/context.js +6 -9
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
- package/dist/esm/node/api/prepareViteApiCall.js +7 -8
- package/dist/esm/node/api/utils.d.ts +1 -1
- package/dist/esm/node/api/utils.js +1 -1
- 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 +2 -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/{utils → node/plugin}/getOutDirs.js +5 -5
- package/dist/esm/node/plugin/index.d.ts +29 -1
- package/dist/esm/node/plugin/index.js +2 -8
- package/dist/esm/node/plugin/onLoad.js +7 -2
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +43 -31
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
- package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
- package/dist/esm/node/plugin/plugins/commonConfig.js +9 -6
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -95
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +159 -177
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
- package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/context.d.ts +9 -0
- package/dist/esm/node/prerender/context.js +24 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
- package/dist/esm/node/prerender/runPrerender.js +65 -38
- package/dist/esm/node/prerender/utils.d.ts +3 -2
- package/dist/esm/node/prerender/utils.js +3 -2
- package/dist/esm/node/runtime/globalContext.d.ts +15 -9
- package/dist/esm/node/runtime/globalContext.js +45 -59
- package/dist/esm/node/runtime/page-files/setup.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
- package/dist/esm/node/runtime/renderPage.js +10 -5
- package/dist/esm/node/runtime/utils.d.ts +3 -2
- package/dist/esm/node/runtime/utils.js +3 -2
- package/dist/esm/node/shared/resolveBase.d.ts +4 -1
- package/dist/esm/node/shared/resolveBase.js +9 -0
- package/dist/esm/shared/page-configs/Config.d.ts +76 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -16
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +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/assertSetup.js +15 -1
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/findFile.js +1 -1
- package/dist/esm/utils/isDev.js +4 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
- package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +0 -16
- package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +0 -5
- package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +0 -14
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
- package/dist/esm/node/shared/assertPluginManifest.js +0 -18
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
- package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
- /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
- /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
- /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
- /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
|
@@ -1,72 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.build = build;
|
|
37
7
|
const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
|
|
38
8
|
const vite_1 = require("vite");
|
|
39
|
-
const
|
|
9
|
+
const assert_1 = __importDefault(require("assert"));
|
|
10
|
+
const context_js_1 = require("../cli/context.js");
|
|
11
|
+
const context_js_2 = require("../prerender/context.js");
|
|
40
12
|
/**
|
|
41
13
|
* Programmatically trigger `$ vike build`
|
|
42
14
|
*
|
|
43
15
|
* https://vike.dev/api#build
|
|
44
16
|
*/
|
|
45
17
|
async function build(options = {}) {
|
|
46
|
-
const { viteConfigEnhanced
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
rollupOutputClient: outputClient,
|
|
61
|
-
rollupOutputServer: outputServer
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function setSSR(viteConfig) {
|
|
18
|
+
const { viteConfigEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options.viteConfig, 'build');
|
|
19
|
+
// Pass it to autoFullBuild()
|
|
20
|
+
if (viteConfigEnhanced)
|
|
21
|
+
viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
|
|
22
|
+
// 1. Build client-side
|
|
23
|
+
// 2. Build server-side
|
|
24
|
+
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L90
|
|
25
|
+
// 3. Pre-render (if enabled)
|
|
26
|
+
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
|
|
27
|
+
// > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
|
|
28
|
+
// > Rationale: https://github.com/vikejs/vike/issues/2123
|
|
29
|
+
await (0, vite_1.build)(viteConfigEnhanced);
|
|
30
|
+
// When using the Vike CLI with pre-rendering the process is forcefully exited at the end of the buildVite() call above
|
|
31
|
+
(0, assert_1.default)(!((0, context_js_1.isVikeCli)() && (0, context_js_2.isPrerendering)()));
|
|
65
32
|
return {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ssr: true
|
|
70
|
-
}
|
|
33
|
+
/* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
34
|
+
viteConfig: viteConfigEnhanced,
|
|
35
|
+
*/
|
|
71
36
|
};
|
|
72
37
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setOperation = setOperation;
|
|
4
|
-
exports.clearOperation = clearOperation;
|
|
5
3
|
exports.isVikeCliOrApi = isVikeCliOrApi;
|
|
4
|
+
exports.setContextApiOperation = setContextApiOperation;
|
|
5
|
+
exports.clearContextApiOperation = clearContextApiOperation;
|
|
6
6
|
const utils_js_1 = require("./utils.js");
|
|
7
|
-
const globalObject = (0, utils_js_1.getGlobalObject)('context.ts', {
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
function getOperation() {
|
|
7
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('api/context.ts', {});
|
|
8
|
+
function getApiOperation() {
|
|
11
9
|
(0, utils_js_1.assert)(globalObject.apiOperation);
|
|
12
10
|
return globalObject.apiOperation;
|
|
13
11
|
}
|
|
@@ -15,10 +13,10 @@ function isVikeCliOrApi() {
|
|
|
15
13
|
// The CLI uses the API
|
|
16
14
|
return !!globalObject.apiOperation;
|
|
17
15
|
}
|
|
18
|
-
function
|
|
16
|
+
function setContextApiOperation(operation) {
|
|
19
17
|
(0, utils_js_1.assert)(!globalObject.apiOperation);
|
|
20
18
|
globalObject.apiOperation = operation;
|
|
21
19
|
}
|
|
22
|
-
function
|
|
20
|
+
function clearContextApiOperation() {
|
|
23
21
|
globalObject.apiOperation = undefined;
|
|
24
22
|
}
|
|
@@ -51,31 +51,30 @@ const globalContext_js_1 = require("../runtime/globalContext.js");
|
|
|
51
51
|
const globalObject = (0, utils_js_1.getGlobalObject)('prepareViteApiCall.ts', {});
|
|
52
52
|
async function prepareViteApiCall(viteConfig, operation) {
|
|
53
53
|
clear();
|
|
54
|
-
(0, context_js_1.
|
|
54
|
+
(0, context_js_1.setContextApiOperation)(operation);
|
|
55
55
|
return enhanceViteConfig(viteConfig, operation);
|
|
56
56
|
}
|
|
57
57
|
// For subsequent API calls, e.g. calling prerender() after build()
|
|
58
58
|
function clear() {
|
|
59
|
-
(0, context_js_1.
|
|
59
|
+
(0, context_js_1.clearContextApiOperation)();
|
|
60
60
|
(0, globalContext_js_1.clearGlobalContext)();
|
|
61
61
|
}
|
|
62
62
|
async function enhanceViteConfig(viteConfig, operation) {
|
|
63
63
|
const viteInfo = await getInfoFromVite(viteConfig, operation);
|
|
64
64
|
await assertViteRoot2(viteInfo.root, viteInfo.viteConfigEnhanced, operation);
|
|
65
65
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(viteInfo.root, operation === 'dev', viteInfo.vikeVitePluginOptions);
|
|
66
|
-
const viteConfigEnhanced =
|
|
66
|
+
const viteConfigEnhanced = addViteSettingsSetByVikeConfig(viteInfo.viteConfigEnhanced, vikeConfig);
|
|
67
67
|
return {
|
|
68
|
-
viteConfigEnhanced
|
|
69
|
-
vikeConfigGlobal: vikeConfig.vikeConfigGlobal
|
|
68
|
+
viteConfigEnhanced
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
|
-
function
|
|
71
|
+
function addViteSettingsSetByVikeConfig(viteConfigEnhanced, vikeConfig) {
|
|
73
72
|
const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
|
|
74
73
|
if (!viteConfigs)
|
|
75
74
|
return viteConfigEnhanced;
|
|
76
75
|
viteConfigs.values.forEach((v) => {
|
|
77
76
|
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(v.value), `${v.definedAt} should be an object`);
|
|
78
|
-
viteConfigEnhanced = (0, vite_1.mergeConfig)(
|
|
77
|
+
viteConfigEnhanced = (0, vite_1.mergeConfig)(viteConfigEnhanced ?? {}, v.value);
|
|
79
78
|
});
|
|
80
79
|
return viteConfigEnhanced;
|
|
81
80
|
}
|
|
@@ -20,5 +20,5 @@ const onLoad_js_1 = require("./onLoad.js");
|
|
|
20
20
|
(0, onLoad_js_1.onLoad)();
|
|
21
21
|
__exportStar(require("../../utils/assert.js"), exports);
|
|
22
22
|
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
23
|
-
__exportStar(require("../../utils/
|
|
23
|
+
__exportStar(require("../../utils/toPosixPath.js"), exports);
|
|
24
24
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVikeCli = isVikeCli;
|
|
4
|
+
exports.setContextCliCommand = setContextCliCommand;
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('cli/context.ts', {});
|
|
7
|
+
function getCliCommand() {
|
|
8
|
+
return globalObject.cliCommand;
|
|
9
|
+
}
|
|
10
|
+
function isVikeCli() {
|
|
11
|
+
return !!globalObject.cliCommand;
|
|
12
|
+
}
|
|
13
|
+
function setContextCliCommand(command) {
|
|
14
|
+
(0, utils_js_1.assert)(!globalObject.cliCommand);
|
|
15
|
+
globalObject.cliCommand = command;
|
|
16
|
+
}
|
|
@@ -40,9 +40,11 @@ const utils_js_1 = require("./utils.js");
|
|
|
40
40
|
const index_js_1 = require("../api/index.js");
|
|
41
41
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
42
42
|
const parseCli_js_1 = require("./parseCli.js");
|
|
43
|
+
const context_js_1 = require("./context.js");
|
|
43
44
|
cli();
|
|
44
45
|
async function cli() {
|
|
45
46
|
const { command } = (0, parseCli_js_1.parseCli)();
|
|
47
|
+
(0, context_js_1.setContextCliCommand)(command);
|
|
46
48
|
if (command === 'dev') {
|
|
47
49
|
await cmdDev();
|
|
48
50
|
}
|
|
@@ -21,3 +21,4 @@ const onLoad_js_1 = require("./onLoad.js");
|
|
|
21
21
|
__exportStar(require("../../utils/assert.js"), exports);
|
|
22
22
|
__exportStar(require("../../utils/projectInfo.js"), exports);
|
|
23
23
|
__exportStar(require("../../utils/includes.js"), exports);
|
|
24
|
+
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getOutDirs = getOutDirs;
|
|
7
7
|
exports.resolveOutDir = resolveOutDir;
|
|
8
|
-
const viteIsSSR_js_1 = require("
|
|
9
|
-
const assert_js_1 = require("
|
|
10
|
-
const path_shim_js_1 = require("
|
|
11
|
-
const
|
|
8
|
+
const viteIsSSR_js_1 = require("../../utils/viteIsSSR.js");
|
|
9
|
+
const assert_js_1 = require("../../utils/assert.js");
|
|
10
|
+
const path_shim_js_1 = require("../../utils/path-shim.js");
|
|
11
|
+
const toPosixPath_js_1 = require("../../utils/toPosixPath.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
const debug_js_1 = require("
|
|
13
|
+
const debug_js_1 = require("../../utils/debug.js");
|
|
14
14
|
const debug = (0, debug_js_1.createDebugger)('vike:outDir');
|
|
15
15
|
function getOutDirs(config) {
|
|
16
16
|
debug('getOutDirs()', new Error().stack);
|
|
@@ -55,7 +55,7 @@ function resolveOutDir(config) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function determineOutDirs(outDirRoot) {
|
|
58
|
-
(0,
|
|
58
|
+
(0, toPosixPath_js_1.assertPosixPath)(outDirRoot);
|
|
59
59
|
(0, assert_js_1.assert)(!outDirRoot.endsWith('/'));
|
|
60
60
|
(0, assert_js_1.assert)(isOutDirRoot(outDirRoot));
|
|
61
61
|
const outDirClient = (0, path_shim_js_1.pathJoin)(outDirRoot, 'client');
|
|
@@ -66,8 +66,8 @@ function determineOutDirs(outDirRoot) {
|
|
|
66
66
|
}
|
|
67
67
|
function getOutDirsAll(outDirRoot, root) {
|
|
68
68
|
if (!outDirIsAbsolutePath(outDirRoot)) {
|
|
69
|
-
(0,
|
|
70
|
-
(0,
|
|
69
|
+
(0, toPosixPath_js_1.assertPosixPath)(outDirRoot);
|
|
70
|
+
(0, toPosixPath_js_1.assertPosixPath)(root);
|
|
71
71
|
outDirRoot = (0, path_shim_js_1.pathJoin)(root, outDirRoot);
|
|
72
72
|
}
|
|
73
73
|
let { outDirClient, outDirServer } = determineOutDirs(outDirRoot);
|
|
@@ -80,7 +80,7 @@ function getOutDirsAll(outDirRoot, root) {
|
|
|
80
80
|
return { outDirRoot, outDirClient, outDirServer };
|
|
81
81
|
}
|
|
82
82
|
function assertNormalization(outDirAny) {
|
|
83
|
-
(0,
|
|
83
|
+
(0, toPosixPath_js_1.assertPosixPath)(outDirAny);
|
|
84
84
|
(0, assert_js_1.assert)(outDirIsAbsolutePath(outDirAny));
|
|
85
85
|
(0, assert_js_1.assert)(outDirAny.endsWith('/'));
|
|
86
86
|
(0, assert_js_1.assert)(!outDirAny.endsWith('//'));
|
|
@@ -95,7 +95,7 @@ function assertIsNotOutDirRoot(outDir) {
|
|
|
95
95
|
}
|
|
96
96
|
/** `outDir` ends with `/server` or `/client` */
|
|
97
97
|
function assertOutDirResolved(outDir, config) {
|
|
98
|
-
(0,
|
|
98
|
+
(0, toPosixPath_js_1.assertPosixPath)(outDir);
|
|
99
99
|
assertIsNotOutDirRoot(outDir);
|
|
100
100
|
(0, assert_js_1.assert)('/client'.length === '/server'.length);
|
|
101
101
|
const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
|
|
@@ -121,7 +121,7 @@ function getOutDirFromViteResolvedConfig(config) {
|
|
|
121
121
|
return outDir;
|
|
122
122
|
}
|
|
123
123
|
function normalize(outDir) {
|
|
124
|
-
outDir = (0,
|
|
124
|
+
outDir = (0, toPosixPath_js_1.toPosixPath)(outDir);
|
|
125
125
|
outDir = outDir.replace(/\/+$/, ''); // remove trailing slashes
|
|
126
126
|
return outDir;
|
|
127
127
|
}
|
|
@@ -9,7 +9,6 @@ exports.ssr = plugin;
|
|
|
9
9
|
exports.default = plugin;
|
|
10
10
|
var utils_js_1 = require("./utils.js");
|
|
11
11
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
12
|
-
const vite_1 = require("vite");
|
|
13
12
|
const utils_js_2 = require("./utils.js");
|
|
14
13
|
const buildConfig_js_1 = require("./plugins/buildConfig.js");
|
|
15
14
|
const previewConfig_js_1 = require("./plugins/previewConfig.js");
|
|
@@ -33,8 +32,7 @@ const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
|
|
|
33
32
|
const resolveClientEntriesDev_js_1 = require("./resolveClientEntriesDev.js");
|
|
34
33
|
const workaroundCssModuleHmr_js_1 = require("./plugins/workaroundCssModuleHmr.js");
|
|
35
34
|
const workaroundVite6HmrRegression_js_1 = require("./plugins/workaroundVite6HmrRegression.js");
|
|
36
|
-
|
|
37
|
-
assertViteVersion();
|
|
35
|
+
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
38
36
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
39
37
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
40
38
|
function plugin(vikeVitePluginOptions = {}) {
|
|
@@ -69,10 +67,6 @@ Object.defineProperty(plugin, 'apply', {
|
|
|
69
67
|
(0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.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 });
|
|
70
68
|
}
|
|
71
69
|
});
|
|
72
|
-
// package.json#peerDependencies isn't enough as users can ignore it
|
|
73
|
-
function assertViteVersion() {
|
|
74
|
-
(0, utils_js_2.assertVersion)('Vite', vite_1.version, '5.1.0');
|
|
75
|
-
}
|
|
76
70
|
// Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
|
|
77
71
|
// - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
|
|
78
72
|
try {
|
|
@@ -4,9 +4,14 @@ exports.onLoad = onLoad;
|
|
|
4
4
|
const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
|
|
5
5
|
const assertSetup_js_1 = require("../../utils/assertSetup.js");
|
|
6
6
|
const assertNodeVersion_js_1 = require("../../utils/assertNodeVersion.js");
|
|
7
|
+
const assertVersion_js_1 = require("../../utils/assertVersion.js");
|
|
8
|
+
const vite_1 = require("vite");
|
|
7
9
|
function onLoad() {
|
|
10
|
+
(0, assertSetup_js_1.markSetup_vikeVitePlugin)();
|
|
8
11
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
|
|
9
12
|
(0, assertNodeVersion_js_1.assertNodeVersion)();
|
|
10
|
-
//
|
|
13
|
+
// package.json#peerDependencies isn't enough as users can ignore it
|
|
14
|
+
(0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, '5.1.0');
|
|
15
|
+
// Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
|
|
11
16
|
(0, assertSetup_js_1.assertIsNotProductionRuntime)();
|
|
12
17
|
}
|
|
@@ -8,26 +8,27 @@ exports.autoFullBuild = autoFullBuild;
|
|
|
8
8
|
const vite_1 = require("vite");
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
10
10
|
const runPrerender_js_1 = require("../../prerender/runPrerender.js");
|
|
11
|
-
const
|
|
11
|
+
const context_js_1 = require("../../prerender/context.js");
|
|
12
12
|
const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const logErrorHint_js_1 = require("../../runtime/renderPage/logErrorHint.js");
|
|
15
15
|
const buildConfig_js_1 = require("./buildConfig.js");
|
|
16
16
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
17
|
+
const context_js_2 = require("../../api/context.js");
|
|
18
|
+
const context_js_3 = require("../../cli/context.js");
|
|
17
19
|
let forceExit = false;
|
|
18
20
|
function autoFullBuild() {
|
|
19
21
|
let config;
|
|
20
|
-
let
|
|
22
|
+
let vikeConfig;
|
|
21
23
|
return [
|
|
22
24
|
{
|
|
23
25
|
name: 'vike:autoFullBuild',
|
|
24
26
|
apply: 'build',
|
|
25
27
|
enforce: 'pre',
|
|
26
28
|
async configResolved(config_) {
|
|
27
|
-
|
|
28
|
-
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
29
|
+
vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
|
|
29
30
|
config = config_;
|
|
30
|
-
abortViteBuildSsr(
|
|
31
|
+
abortViteBuildSsr(vikeConfig);
|
|
31
32
|
},
|
|
32
33
|
writeBundle: {
|
|
33
34
|
/* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
|
|
@@ -36,7 +37,7 @@ function autoFullBuild() {
|
|
|
36
37
|
*/
|
|
37
38
|
async handler(_options, bundle) {
|
|
38
39
|
try {
|
|
39
|
-
await triggerFullBuild(config,
|
|
40
|
+
await triggerFullBuild(config, vikeConfig, bundle);
|
|
40
41
|
}
|
|
41
42
|
catch (err) {
|
|
42
43
|
// Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
@@ -62,10 +63,10 @@ function autoFullBuild() {
|
|
|
62
63
|
}
|
|
63
64
|
];
|
|
64
65
|
}
|
|
65
|
-
async function triggerFullBuild(config,
|
|
66
|
+
async function triggerFullBuild(config, vikeConfig, bundle) {
|
|
66
67
|
if (config.build.ssr)
|
|
67
68
|
return; // already triggered
|
|
68
|
-
if (isDisabled(
|
|
69
|
+
if (isDisabled(vikeConfig))
|
|
69
70
|
return;
|
|
70
71
|
// Workaround for @vitejs/plugin-legacy
|
|
71
72
|
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
@@ -74,43 +75,54 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
|
|
|
74
75
|
if (!bundle[buildConfig_js_1.manifestTempFile])
|
|
75
76
|
return;
|
|
76
77
|
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
await (0, vite_1.build)({
|
|
87
|
-
...configInline,
|
|
78
|
+
let configInline;
|
|
79
|
+
if (config._viteConfigEnhanced) {
|
|
80
|
+
configInline = config._viteConfigEnhanced;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
configInline = {
|
|
84
|
+
...configFromCli,
|
|
85
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
86
|
+
root: config.root,
|
|
88
87
|
build: {
|
|
89
|
-
...
|
|
90
|
-
ssr: true
|
|
88
|
+
...configFromCli?.build
|
|
91
89
|
}
|
|
92
|
-
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
await (0, vite_1.build)(setSSR(configInline));
|
|
93
94
|
}
|
|
94
95
|
catch (err) {
|
|
95
96
|
console.error(err);
|
|
96
97
|
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
97
98
|
process.exit(1);
|
|
98
99
|
}
|
|
99
|
-
if ((0,
|
|
100
|
-
await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline);
|
|
101
|
-
|
|
100
|
+
if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
|
|
101
|
+
const { prerenderContextPublic } = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline);
|
|
102
|
+
config.vike.prerenderContext = prerenderContextPublic;
|
|
103
|
+
forceExit = (0, context_js_3.isVikeCli)() || (0, isViteCliCall_js_1.isViteCliCall)();
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
+
function setSSR(configInline) {
|
|
107
|
+
return {
|
|
108
|
+
...configInline,
|
|
109
|
+
build: {
|
|
110
|
+
...configInline.build,
|
|
111
|
+
ssr: true
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function abortViteBuildSsr(vikeConfig) {
|
|
116
|
+
if (vikeConfig.global.config.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
|
|
106
117
|
(0, utils_js_1.assertWarning)(false, `The CLI call ${picocolors_1.default.cyan('$ vite build --ssr')} is superfluous since ${picocolors_1.default.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 ${picocolors_1.default.cyan('build()')} API.`, { onlyOnce: true });
|
|
107
118
|
process.exit(0);
|
|
108
119
|
}
|
|
109
120
|
}
|
|
110
|
-
function isDisabled(
|
|
111
|
-
const { disableAutoFullBuild } =
|
|
112
|
-
if (disableAutoFullBuild ===
|
|
113
|
-
|
|
121
|
+
function isDisabled(vikeConfig) {
|
|
122
|
+
const { disableAutoFullBuild } = vikeConfig.global.config;
|
|
123
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
124
|
+
const isViteApi = !(0, isViteCliCall_js_1.isViteCliCall)() && !(0, context_js_2.isVikeCliOrApi)();
|
|
125
|
+
return isViteApi;
|
|
114
126
|
}
|
|
115
127
|
else {
|
|
116
128
|
return disableAutoFullBuild;
|
|
@@ -13,7 +13,7 @@ function baseUrls() {
|
|
|
13
13
|
const isDev = config._isDev;
|
|
14
14
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
15
15
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
16
|
-
basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config.vike.
|
|
16
|
+
basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config.vike.global.config.baseServer ?? null, config.vike.global.config.baseAssets ?? null);
|
|
17
17
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
18
18
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
19
19
|
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
@@ -29,7 +29,7 @@ function baseUrls() {
|
|
|
29
29
|
},
|
|
30
30
|
async configResolved(config) {
|
|
31
31
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
|
|
32
|
-
const basesResolved2 = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfig.
|
|
32
|
+
const basesResolved2 = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
|
|
33
33
|
(0, utils_js_1.assert)(basesResolved2.baseServer === basesResolved.baseServer);
|
|
34
34
|
(0, utils_js_1.assert)(basesResolved2.baseAssets === basesResolved.baseAssets);
|
|
35
35
|
/* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
|
|
@@ -85,7 +85,7 @@ function buildConfig() {
|
|
|
85
85
|
name: 'vike:buildConfig:pre',
|
|
86
86
|
apply: 'build',
|
|
87
87
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
88
|
-
// -
|
|
88
|
+
// - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
|
|
89
89
|
// - 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
|
|
90
90
|
enforce: 'pre',
|
|
91
91
|
writeBundle: {
|
|
@@ -108,7 +108,7 @@ function buildConfig() {
|
|
|
108
108
|
}
|
|
109
109
|
await promises_1.default.rm(clientManifestFilePath);
|
|
110
110
|
await promises_1.default.rm(serverManifestFilePath);
|
|
111
|
-
await (0, index_js_1.
|
|
111
|
+
await (0, index_js_1.set_ASSETS_MANIFEST)(options, bundle);
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -118,7 +118,10 @@ function buildConfig() {
|
|
|
118
118
|
async function getEntries(config) {
|
|
119
119
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
|
|
120
120
|
const { pageConfigs } = vikeConfig;
|
|
121
|
-
|
|
121
|
+
// TODO/v1-release: remove
|
|
122
|
+
const pageFileEntries = await getPageFileEntries(config,
|
|
123
|
+
// TODO/now: add meta.default
|
|
124
|
+
vikeConfig.global.config.includeAssetsImportedByServer ?? true);
|
|
122
125
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
123
126
|
if ((0, utils_js_1.viteIsSSR)(config)) {
|
|
124
127
|
const pageEntries = getPageEntries(pageConfigs);
|
|
@@ -4,11 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.buildEntry = buildEntry;
|
|
7
|
-
exports.
|
|
7
|
+
exports.set_ASSETS_MANIFEST = set_ASSETS_MANIFEST;
|
|
8
8
|
const plugin_1 = require("@brillout/vite-plugin-server-entry/plugin");
|
|
9
9
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
10
|
-
const getVikeManifest_js_1 = require("./getVikeManifest.js");
|
|
11
|
-
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
12
10
|
const utils_js_1 = require("../../utils.js");
|
|
13
11
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
14
12
|
const path_1 = __importDefault(require("path"));
|
|
@@ -16,69 +14,74 @@ const module_1 = require("module");
|
|
|
16
14
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
17
15
|
const importMetaUrl = `file://${__filename}`;
|
|
18
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
19
|
-
const
|
|
17
|
+
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
18
|
+
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
19
|
+
const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
|
|
20
20
|
function buildEntry() {
|
|
21
21
|
let config;
|
|
22
|
-
let vikeConfigGlobal;
|
|
23
22
|
return [
|
|
24
23
|
{
|
|
25
24
|
name: 'vike:buildEntry',
|
|
26
25
|
enforce: 'post',
|
|
27
26
|
async configResolved(config_) {
|
|
28
27
|
config = config_;
|
|
29
|
-
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
|
|
30
|
-
vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
|
|
31
28
|
}
|
|
32
29
|
},
|
|
33
30
|
...(0, plugin_1.serverProductionEntryPlugin)({
|
|
34
31
|
getServerProductionEntry: () => {
|
|
35
|
-
return getServerProductionEntryCode(config
|
|
32
|
+
return getServerProductionEntryCode(config);
|
|
36
33
|
},
|
|
37
34
|
libraryName: 'Vike'
|
|
38
35
|
})
|
|
39
36
|
];
|
|
40
37
|
}
|
|
41
|
-
function getServerProductionEntryCode(config
|
|
38
|
+
function getServerProductionEntryCode(config) {
|
|
42
39
|
const importPath = getImportPath(config);
|
|
43
|
-
const
|
|
44
|
-
|
|
40
|
+
const buildInfo = {
|
|
41
|
+
versionAtBuildTime: utils_js_1.projectInfo.projectVersion,
|
|
42
|
+
usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(), // TODO/v1-release: remove
|
|
43
|
+
viteConfigRuntime: (0, globalContext_js_1.getViteConfigRuntime)(config)
|
|
44
|
+
};
|
|
45
|
+
(0, globalContext_js_1.assertBuildInfo)(buildInfo);
|
|
46
|
+
// After the old design is removed, let's maybe simplify and move everything into a single virtual module
|
|
45
47
|
const importerCode = [
|
|
46
48
|
` import { setGlobalContext_buildEntry } from '${importPath}';`,
|
|
47
49
|
` import * as pageFiles from '${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer}';`,
|
|
48
50
|
` {`,
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
` const
|
|
51
|
+
// Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_buildEntry()
|
|
52
|
+
// - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
53
|
+
` const assetsManifest = ${ASSETS_MANIFEST};`,
|
|
54
|
+
` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
|
|
52
55
|
' setGlobalContext_buildEntry({',
|
|
53
56
|
` pageFiles,`,
|
|
54
57
|
` assetsManifest,`,
|
|
55
|
-
`
|
|
58
|
+
` buildInfo,`,
|
|
56
59
|
' });',
|
|
57
60
|
` }`,
|
|
58
61
|
''
|
|
59
62
|
].join('\n');
|
|
60
63
|
return importerCode;
|
|
61
64
|
}
|
|
62
|
-
/** Set the value of the
|
|
63
|
-
async function
|
|
65
|
+
/** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
|
|
66
|
+
async function set_ASSETS_MANIFEST(options, bundle) {
|
|
64
67
|
const { dir } = options;
|
|
65
68
|
(0, utils_js_1.assert)(dir);
|
|
66
|
-
const chunkPath =
|
|
69
|
+
const chunkPath = find_ASSETS_MANIFEST(bundle);
|
|
67
70
|
const chunkFilePath = path_1.default.join(dir, chunkPath);
|
|
68
71
|
const assetsJsonFilePath = path_1.default.join(dir, '..', 'assets.json');
|
|
69
72
|
const [assetsJsonString, chunkFileContent] = await Promise.all([
|
|
70
73
|
await promises_1.default.readFile(assetsJsonFilePath, 'utf8'),
|
|
71
74
|
await promises_1.default.readFile(chunkFilePath, 'utf8')
|
|
72
75
|
]);
|
|
73
|
-
const serverEntryFileContentPatched = chunkFileContent.replace(
|
|
76
|
+
const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MANIFEST, assetsJsonString);
|
|
74
77
|
(0, utils_js_1.assert)(serverEntryFileContentPatched !== chunkFileContent);
|
|
75
78
|
await promises_1.default.writeFile(chunkFilePath, serverEntryFileContentPatched);
|
|
76
79
|
}
|
|
77
|
-
function
|
|
80
|
+
function find_ASSETS_MANIFEST(bundle) {
|
|
78
81
|
let chunkPath;
|
|
79
82
|
for (const filePath in bundle) {
|
|
80
83
|
const chunk = bundle[filePath];
|
|
81
|
-
if ('code' in chunk && chunk.code.includes(
|
|
84
|
+
if ('code' in chunk && chunk.code.includes(ASSETS_MANIFEST)) {
|
|
82
85
|
(0, utils_js_1.assert)(!chunkPath);
|
|
83
86
|
chunkPath = filePath;
|
|
84
87
|
}
|