vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
51 lines (50 loc) • 2.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.build = build;
const prepareViteApiCall_js_1 = require("./prepareViteApiCall.js");
const vite_1 = require("vite");
const context_js_1 = require("../cli/context.js");
const context_js_2 = require("../prerender/context.js");
const utils_js_1 = require("./utils.js");
/**
* Programmatically trigger `$ vike build`
*
* https://vike.dev/api#build
*/
async function build(options = {}) {
const { viteConfigFromUserEnhanced, vikeConfig } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'build');
// Pass it to pluginAutoFullBuild()
if (viteConfigFromUserEnhanced)
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
if (vikeConfig.config.vite6BuilderApp) {
// This assertion isn't reliable: the user may still use a Vite version older than 6.0.0 — see https://github.com/vitejs/vite/pull/19355
(0, utils_js_1.assertVersion)('Vite', vite_1.version, '6.0.0');
const builder = await (0, vite_1.createBuilder)(viteConfigFromUserEnhanced);
// See Vite plugin vike:build:pluginBuildApp
await builder.buildApp();
}
else {
// This buildVite() call does everything:
// 1. Build client-side
// 2. Build server-side
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L90
// 3. Pre-render (if enabled)
// > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
// > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
// > Rationale: https://github.com/vikejs/vike/issues/2123
await (0, vite_1.build)(viteConfigFromUserEnhanced);
// After pre-rendering, when using the Vike CLI, the process is forcefully exited at the end of the buildVite() call above.
if (
// When calling Vike's prerender() API pre-rendering is run without force exit
![false, 'prerender()'].includes((0, context_js_2.wasPrerenderRun)()) &&
// When calling Vike's build() API pre-rendering is auto run without force exit
(0, context_js_1.isVikeCli)()) {
(0, utils_js_1.assert)(false);
}
}
return {
/* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
viteConfig: viteConfigFromUserEnhanced,
*/
};
}