vike 0.4.237-commit-fd8294f → 0.4.237-commit-2d6f480
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 +1 -1
- package/dist/cjs/node/api/prepareViteApiCall.js +0 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +120 -14
- package/dist/cjs/node/vite/plugins/pluginBuild.js +1 -2
- package/dist/cjs/node/vite/plugins/pluginPreview.js +1 -11
- package/dist/cjs/node/vite/shared/getOutDirs.js +0 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/api/build.js +1 -1
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -2
- package/dist/esm/node/api/prepareViteApiCall.js +0 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +4 -0
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +120 -17
- package/dist/esm/node/vite/plugins/pluginBuild.js +1 -2
- package/dist/esm/node/vite/plugins/pluginPreview.js +3 -13
- package/dist/esm/node/vite/shared/getOutDirs.d.ts +1 -3
- package/dist/esm/node/vite/shared/getOutDirs.js +1 -8
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -132
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.d.ts +0 -5
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -127
|
@@ -14,7 +14,7 @@ async function build(options = {}) {
|
|
|
14
14
|
if (viteConfigFromUserEnhanced)
|
|
15
15
|
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
|
|
16
16
|
const builder = await (0, vite_1.createBuilder)(viteConfigFromUserEnhanced);
|
|
17
|
-
//
|
|
17
|
+
// buildApp() is implemented by vike:build:pluginBuildApp
|
|
18
18
|
await builder.buildApp();
|
|
19
19
|
return {
|
|
20
20
|
/* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
@@ -71,7 +71,6 @@ async function resolveConfigs(viteConfigFromUserApiOptions, operation) {
|
|
|
71
71
|
const viteConfigFromUserEnhanced = applyVikeViteConfig(viteInfo.viteConfigFromUserEnhanced, vikeConfig);
|
|
72
72
|
const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteConfigFromUserEnhanced, operation);
|
|
73
73
|
return {
|
|
74
|
-
vikeConfig,
|
|
75
74
|
viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
|
|
76
75
|
viteConfigFromUserEnhanced,
|
|
77
76
|
};
|
|
@@ -4,7 +4,7 @@ exports.pluginBuildApp = pluginBuildApp;
|
|
|
4
4
|
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
5
5
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
6
6
|
const utils_js_1 = require("../../utils.js");
|
|
7
|
-
const
|
|
7
|
+
const pluginBuildConfig_js_1 = require("./pluginBuildConfig.js");
|
|
8
8
|
function pluginBuildApp() {
|
|
9
9
|
return [
|
|
10
10
|
{
|
|
@@ -22,7 +22,7 @@ function pluginBuildApp() {
|
|
|
22
22
|
(0, utils_js_1.assert)(builder.environments.ssr);
|
|
23
23
|
await builder.build(builder.environments.client);
|
|
24
24
|
await builder.build(builder.environments.ssr);
|
|
25
|
-
if ((0,
|
|
25
|
+
if ((0, pluginBuildConfig_js_1.isPrerenderForceExit)()) {
|
|
26
26
|
(0, runPrerenderEntry_js_1.runPrerender_forceExit)();
|
|
27
27
|
(0, utils_js_1.assert)(false);
|
|
28
28
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.pluginBuildConfig = pluginBuildConfig;
|
|
4
7
|
exports.assertRollupInput = assertRollupInput;
|
|
5
8
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
9
|
+
exports.pluginAutoFullBuild = pluginAutoFullBuild;
|
|
10
|
+
exports.isPrerenderForceExit = isPrerenderForceExit;
|
|
6
11
|
const utils_js_1 = require("../../utils.js");
|
|
7
12
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
8
13
|
const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
|
|
@@ -12,12 +17,20 @@ const prependEntriesDir_js_1 = require("../../../shared/prependEntriesDir.js");
|
|
|
12
17
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
13
18
|
const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
14
19
|
const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
|
|
15
|
-
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
16
20
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
17
21
|
const retrievePageAssetsProd_js_1 = require("../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js");
|
|
22
|
+
const context_js_1 = require("../../../prerender/context.js");
|
|
23
|
+
const isViteCliCall_js_1 = require("../../shared/isViteCliCall.js");
|
|
24
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
25
|
+
const logErrorHint_js_1 = require("../../../runtime/renderPage/logErrorHint.js");
|
|
26
|
+
const context_js_2 = require("../../../api/context.js");
|
|
27
|
+
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
28
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
29
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('build/pluginAutoFullBuild.ts', {
|
|
30
|
+
forceExit: false,
|
|
31
|
+
});
|
|
18
32
|
function pluginBuildConfig() {
|
|
19
33
|
let config;
|
|
20
|
-
let configUnresolved;
|
|
21
34
|
return [
|
|
22
35
|
{
|
|
23
36
|
name: 'vike:build:pluginBuildConfig',
|
|
@@ -36,21 +49,9 @@ function pluginBuildConfig() {
|
|
|
36
49
|
(0, handleAssetsManifest_js_1.handleAssetsManifest_assertUsageCssCodeSplit)(config);
|
|
37
50
|
},
|
|
38
51
|
},
|
|
39
|
-
configEnvironment: {
|
|
40
|
-
order: 'post',
|
|
41
|
-
async handler(envName, configEnv) {
|
|
42
|
-
(0, utils_js_1.assert)(configUnresolved);
|
|
43
|
-
return {
|
|
44
|
-
build: {
|
|
45
|
-
outDir: (0, getOutDirs_js_1.resolveOutDir_configEnvironment)(configUnresolved, envName, configEnv),
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
52
|
config: {
|
|
51
53
|
order: 'post',
|
|
52
54
|
async handler(config) {
|
|
53
|
-
configUnresolved = config;
|
|
54
55
|
(0, utils_js_1.onSetupBuild)();
|
|
55
56
|
const build = await (0, handleAssetsManifest_js_1.handleAssetsManifest_getBuildConfig)(config);
|
|
56
57
|
return { build };
|
|
@@ -232,3 +233,108 @@ function assertRollupInput(config) {
|
|
|
232
233
|
const htmlInput = htmlInputs[0];
|
|
233
234
|
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
234
235
|
}
|
|
236
|
+
function pluginAutoFullBuild() {
|
|
237
|
+
let config;
|
|
238
|
+
return [
|
|
239
|
+
{
|
|
240
|
+
name: 'vike:build:pluginAutoFullBuild',
|
|
241
|
+
apply: 'build',
|
|
242
|
+
enforce: 'pre',
|
|
243
|
+
async configResolved(config_) {
|
|
244
|
+
config = config_;
|
|
245
|
+
await abortViteBuildSsr();
|
|
246
|
+
},
|
|
247
|
+
writeBundle: {
|
|
248
|
+
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
249
|
+
sequential: true,
|
|
250
|
+
order: 'pre',
|
|
251
|
+
*/
|
|
252
|
+
async handler(options, bundle) {
|
|
253
|
+
try {
|
|
254
|
+
await (0, handleAssetsManifest_js_1.handleAssetsManifest)(config, this.environment, options, bundle);
|
|
255
|
+
await triggerPrerendering(config, this.environment, bundle);
|
|
256
|
+
}
|
|
257
|
+
catch (err) {
|
|
258
|
+
// We use try-catch also because:
|
|
259
|
+
// - Vite/Rollup swallows errors thrown inside the writeBundle() hook. (It doesn't swallow errors thrown inside the first writeBundle() hook while building the client-side, but it does swallow errors thrown inside the second writeBundle() while building the server-side triggered after Vike calls Vite's `build()` API.)
|
|
260
|
+
// - Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
261
|
+
console.error(err);
|
|
262
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'vike:build:pluginAutoFullBuild:post',
|
|
270
|
+
apply: 'build',
|
|
271
|
+
enforce: 'post',
|
|
272
|
+
closeBundle: {
|
|
273
|
+
sequential: true,
|
|
274
|
+
order: 'post',
|
|
275
|
+
handler() {
|
|
276
|
+
(0, utils_js_1.onSetupBuild)();
|
|
277
|
+
(0, handleAssetsManifest_js_1.handleAssetsManifest_assertUsageCssTarget)(config, this.environment);
|
|
278
|
+
/* Let vike:build:pluginBuildApp force exit
|
|
279
|
+
runPrerender_forceExit()
|
|
280
|
+
*/
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
];
|
|
285
|
+
}
|
|
286
|
+
async function triggerPrerendering(config, viteEnv, bundle) {
|
|
287
|
+
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
288
|
+
if (!(0, isViteServerSide_js_1.isViteServerSide_onlySsrEnv)(config, viteEnv))
|
|
289
|
+
return;
|
|
290
|
+
if (isDisabled(vikeConfig))
|
|
291
|
+
return;
|
|
292
|
+
// Workaround for @vitejs/plugin-legacy
|
|
293
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
294
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
295
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
296
|
+
if (!bundle[(0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(config.build.manifest)])
|
|
297
|
+
return;
|
|
298
|
+
const configInline = getFullBuildInlineConfig(config);
|
|
299
|
+
if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
|
|
300
|
+
const res = await (0, runPrerenderEntry_js_1.runPrerenderFromAutoRun)(configInline);
|
|
301
|
+
globalObject.forceExit = res.forceExit;
|
|
302
|
+
(0, utils_js_1.assert)((0, context_js_1.wasPrerenderRun)());
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
async function abortViteBuildSsr() {
|
|
306
|
+
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
307
|
+
if (vikeConfig.config.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
|
|
308
|
+
(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 });
|
|
309
|
+
process.exit(0);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function isDisabled(vikeConfig) {
|
|
313
|
+
const { disableAutoFullBuild } = vikeConfig.config;
|
|
314
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
315
|
+
const isUserUsingViteApi = !(0, isViteCliCall_js_1.isViteCliCall)() && !(0, context_js_2.isVikeCliOrApi)();
|
|
316
|
+
return isUserUsingViteApi;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
return disableAutoFullBuild;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function isPrerenderForceExit() {
|
|
323
|
+
return globalObject.forceExit;
|
|
324
|
+
}
|
|
325
|
+
function getFullBuildInlineConfig(config) {
|
|
326
|
+
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
327
|
+
if (config._viteConfigFromUserEnhanced) {
|
|
328
|
+
return config._viteConfigFromUserEnhanced;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
return {
|
|
332
|
+
...configFromCli,
|
|
333
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
334
|
+
root: config.root,
|
|
335
|
+
build: {
|
|
336
|
+
...configFromCli?.build,
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
@@ -5,7 +5,6 @@ const pluginBuildApp_js_1 = require("./pluginBuild/pluginBuildApp.js");
|
|
|
5
5
|
const pluginDistPackageJsonFile_js_1 = require("./pluginBuild/pluginDistPackageJsonFile.js");
|
|
6
6
|
const pluginSuppressRollupWarning_js_1 = require("./pluginBuild/pluginSuppressRollupWarning.js");
|
|
7
7
|
const pluginDistFileNames_js_1 = require("./pluginBuild/pluginDistFileNames.js");
|
|
8
|
-
const pluginAutoFullBuild_js_1 = require("./pluginBuild/pluginAutoFullBuild.js");
|
|
9
8
|
const pluginBuildEntry_js_1 = require("./pluginBuild/pluginBuildEntry.js");
|
|
10
9
|
const pluginBuildConfig_js_1 = require("./pluginBuild/pluginBuildConfig.js");
|
|
11
10
|
const pluginModuleBanner_js_1 = require("./pluginBuild/pluginModuleBanner.js");
|
|
@@ -13,7 +12,7 @@ function pluginBuild() {
|
|
|
13
12
|
return [
|
|
14
13
|
...(0, pluginBuildConfig_js_1.pluginBuildConfig)(),
|
|
15
14
|
...(0, pluginBuildApp_js_1.pluginBuildApp)(),
|
|
16
|
-
...(0,
|
|
15
|
+
...(0, pluginBuildConfig_js_1.pluginAutoFullBuild)(),
|
|
17
16
|
...(0, pluginBuildEntry_js_1.pluginBuildEntry)(),
|
|
18
17
|
(0, pluginDistPackageJsonFile_js_1.pluginDistPackageJsonFile)(),
|
|
19
18
|
(0, pluginSuppressRollupWarning_js_1.pluginSuppressRollupWarning)(),
|
|
@@ -15,25 +15,15 @@ const sirv_1 = __importDefault(require("sirv"));
|
|
|
15
15
|
const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInternal.js");
|
|
16
16
|
function pluginPreview() {
|
|
17
17
|
let config;
|
|
18
|
-
let configUnresolved;
|
|
19
18
|
let vikeConfig;
|
|
20
19
|
return {
|
|
21
20
|
name: 'vike:pluginPreview',
|
|
22
21
|
apply: utils_js_1.applyPreview,
|
|
23
|
-
config(
|
|
24
|
-
configUnresolved = config;
|
|
22
|
+
config() {
|
|
25
23
|
return {
|
|
26
24
|
appType: 'custom',
|
|
27
25
|
};
|
|
28
26
|
},
|
|
29
|
-
configEnvironment(envName, configEnv) {
|
|
30
|
-
(0, utils_js_1.assert)(configUnresolved);
|
|
31
|
-
return {
|
|
32
|
-
build: {
|
|
33
|
-
outDir: (0, getOutDirs_js_1.resolveOutDir_configEnvironment)(configUnresolved, envName, configEnv),
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
27
|
async configResolved(config_) {
|
|
38
28
|
config = config_;
|
|
39
29
|
vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
@@ -5,7 +5,6 @@ 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
|
-
exports.resolveOutDir_configEnvironment = resolveOutDir_configEnvironment;
|
|
9
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
10
9
|
const utils_js_1 = require("../utils.js");
|
|
11
10
|
const isViteServerSide_js_1 = require("./isViteServerSide.js");
|
|
@@ -20,12 +19,6 @@ function getOutDirs(configGlobal, viteEnv) {
|
|
|
20
19
|
assertNormalization(outDirs.outDirServer);
|
|
21
20
|
return outDirs;
|
|
22
21
|
}
|
|
23
|
-
function resolveOutDir_configEnvironment(configGlobal, envName, configEnv) {
|
|
24
|
-
(0, utils_js_1.assert)(configGlobal && envName && configEnv);
|
|
25
|
-
const viteEnv = { name: envName, config: configEnv };
|
|
26
|
-
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide)(configGlobal, viteEnv);
|
|
27
|
-
return resolveOutDir(configEnv, isServerSide);
|
|
28
|
-
}
|
|
29
22
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
30
23
|
function resolveOutDir(config, isServerSide) {
|
|
31
24
|
debug('resolveOutDir()', new Error().stack);
|
|
@@ -12,7 +12,7 @@ async function build(options = {}) {
|
|
|
12
12
|
if (viteConfigFromUserEnhanced)
|
|
13
13
|
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
|
|
14
14
|
const builder = await createBuilder(viteConfigFromUserEnhanced);
|
|
15
|
-
//
|
|
15
|
+
// buildApp() is implemented by vike:build:pluginBuildApp
|
|
16
16
|
await builder.buildApp();
|
|
17
17
|
return {
|
|
18
18
|
/* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
|
|
@@ -4,9 +4,7 @@ export { assertViteRoot };
|
|
|
4
4
|
export { normalizeViteRoot };
|
|
5
5
|
import type { InlineConfig, ResolvedConfig } from 'vite';
|
|
6
6
|
import type { APIOptions, Operation } from './types.js';
|
|
7
|
-
import { type VikeConfigInternal } from '../vite/shared/resolveVikeConfigInternal.js';
|
|
8
7
|
declare function prepareViteApiCall(options: APIOptions, operation: Operation): Promise<{
|
|
9
|
-
vikeConfig: VikeConfigInternal;
|
|
10
8
|
viteConfigResolved: ResolvedConfig;
|
|
11
9
|
viteConfigFromUserEnhanced: InlineConfig | undefined;
|
|
12
10
|
}>;
|
|
@@ -33,7 +33,6 @@ async function resolveConfigs(viteConfigFromUserApiOptions, operation) {
|
|
|
33
33
|
const viteConfigFromUserEnhanced = applyVikeViteConfig(viteInfo.viteConfigFromUserEnhanced, vikeConfig);
|
|
34
34
|
const { viteConfigResolved } = await assertViteRoot2(viteInfo.root, viteConfigFromUserEnhanced, operation);
|
|
35
35
|
return {
|
|
36
|
-
vikeConfig,
|
|
37
36
|
viteConfigResolved, // ONLY USE if strictly necessary. (We plan to remove assertViteRoot2() as explained in the comments of that function.)
|
|
38
37
|
viteConfigFromUserEnhanced,
|
|
39
38
|
};
|
|
@@ -2,7 +2,7 @@ export { pluginBuildApp };
|
|
|
2
2
|
import { runPrerender_forceExit } from '../../../prerender/runPrerenderEntry.js';
|
|
3
3
|
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
4
4
|
import { assert } from '../../utils.js';
|
|
5
|
-
import { isPrerenderForceExit } from './
|
|
5
|
+
import { isPrerenderForceExit } from './pluginBuildConfig.js';
|
|
6
6
|
function pluginBuildApp() {
|
|
7
7
|
return [
|
|
8
8
|
{
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
+
export { pluginAutoFullBuild };
|
|
5
|
+
export { isPrerenderForceExit };
|
|
4
6
|
import type { ResolvedConfig, Plugin } from 'vite';
|
|
5
7
|
import type { PageConfigBuildTime } from '../../../../types/PageConfig.js';
|
|
6
8
|
declare function pluginBuildConfig(): Plugin[];
|
|
@@ -10,3 +12,5 @@ declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config
|
|
|
10
12
|
clientEntries: Record<string, string>;
|
|
11
13
|
};
|
|
12
14
|
declare function assertRollupInput(config: ResolvedConfig): void;
|
|
15
|
+
declare function pluginAutoFullBuild(): Plugin[];
|
|
16
|
+
declare function isPrerenderForceExit(): boolean;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
|
|
4
|
+
export { pluginAutoFullBuild };
|
|
5
|
+
export { isPrerenderForceExit };
|
|
6
|
+
import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, assertWarning, getGlobalObject, } from '../../utils.js';
|
|
5
7
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
6
8
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
7
9
|
import { generateVirtualFileId } from '../../../shared/virtualFileId.js';
|
|
@@ -9,13 +11,21 @@ import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
|
9
11
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
10
12
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
11
13
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
12
|
-
import { isViteServerSide_withoutEnv } from '../../shared/isViteServerSide.js';
|
|
13
|
-
import {
|
|
14
|
-
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
|
|
14
|
+
import { isViteServerSide_withoutEnv, isViteServerSide_onlySsrEnv } from '../../shared/isViteServerSide.js';
|
|
15
|
+
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget, } from './handleAssetsManifest.js';
|
|
15
16
|
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
17
|
+
import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/context.js';
|
|
18
|
+
import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
|
|
19
|
+
import pc from '@brillout/picocolors';
|
|
20
|
+
import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
|
|
21
|
+
import { isVikeCliOrApi } from '../../../api/context.js';
|
|
22
|
+
import { runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
|
|
23
|
+
import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
|
|
24
|
+
const globalObject = getGlobalObject('build/pluginAutoFullBuild.ts', {
|
|
25
|
+
forceExit: false,
|
|
26
|
+
});
|
|
16
27
|
function pluginBuildConfig() {
|
|
17
28
|
let config;
|
|
18
|
-
let configUnresolved;
|
|
19
29
|
return [
|
|
20
30
|
{
|
|
21
31
|
name: 'vike:build:pluginBuildConfig',
|
|
@@ -34,21 +44,9 @@ function pluginBuildConfig() {
|
|
|
34
44
|
handleAssetsManifest_assertUsageCssCodeSplit(config);
|
|
35
45
|
},
|
|
36
46
|
},
|
|
37
|
-
configEnvironment: {
|
|
38
|
-
order: 'post',
|
|
39
|
-
async handler(envName, configEnv) {
|
|
40
|
-
assert(configUnresolved);
|
|
41
|
-
return {
|
|
42
|
-
build: {
|
|
43
|
-
outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
47
|
config: {
|
|
49
48
|
order: 'post',
|
|
50
49
|
async handler(config) {
|
|
51
|
-
configUnresolved = config;
|
|
52
50
|
onSetupBuild();
|
|
53
51
|
const build = await handleAssetsManifest_getBuildConfig(config);
|
|
54
52
|
return { build };
|
|
@@ -230,3 +228,108 @@ function assertRollupInput(config) {
|
|
|
230
228
|
const htmlInput = htmlInputs[0];
|
|
231
229
|
assertUsage(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
232
230
|
}
|
|
231
|
+
function pluginAutoFullBuild() {
|
|
232
|
+
let config;
|
|
233
|
+
return [
|
|
234
|
+
{
|
|
235
|
+
name: 'vike:build:pluginAutoFullBuild',
|
|
236
|
+
apply: 'build',
|
|
237
|
+
enforce: 'pre',
|
|
238
|
+
async configResolved(config_) {
|
|
239
|
+
config = config_;
|
|
240
|
+
await abortViteBuildSsr();
|
|
241
|
+
},
|
|
242
|
+
writeBundle: {
|
|
243
|
+
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
244
|
+
sequential: true,
|
|
245
|
+
order: 'pre',
|
|
246
|
+
*/
|
|
247
|
+
async handler(options, bundle) {
|
|
248
|
+
try {
|
|
249
|
+
await handleAssetsManifest(config, this.environment, options, bundle);
|
|
250
|
+
await triggerPrerendering(config, this.environment, bundle);
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
// We use try-catch also because:
|
|
254
|
+
// - Vite/Rollup swallows errors thrown inside the writeBundle() hook. (It doesn't swallow errors thrown inside the first writeBundle() hook while building the client-side, but it does swallow errors thrown inside the second writeBundle() while building the server-side triggered after Vike calls Vite's `build()` API.)
|
|
255
|
+
// - Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
256
|
+
console.error(err);
|
|
257
|
+
logErrorHint(err);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: 'vike:build:pluginAutoFullBuild:post',
|
|
265
|
+
apply: 'build',
|
|
266
|
+
enforce: 'post',
|
|
267
|
+
closeBundle: {
|
|
268
|
+
sequential: true,
|
|
269
|
+
order: 'post',
|
|
270
|
+
handler() {
|
|
271
|
+
onSetupBuild();
|
|
272
|
+
handleAssetsManifest_assertUsageCssTarget(config, this.environment);
|
|
273
|
+
/* Let vike:build:pluginBuildApp force exit
|
|
274
|
+
runPrerender_forceExit()
|
|
275
|
+
*/
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
async function triggerPrerendering(config, viteEnv, bundle) {
|
|
282
|
+
const vikeConfig = await getVikeConfigInternal();
|
|
283
|
+
if (!isViteServerSide_onlySsrEnv(config, viteEnv))
|
|
284
|
+
return;
|
|
285
|
+
if (isDisabled(vikeConfig))
|
|
286
|
+
return;
|
|
287
|
+
// Workaround for @vitejs/plugin-legacy
|
|
288
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
289
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
290
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
291
|
+
if (!bundle[getManifestFilePathRelative(config.build.manifest)])
|
|
292
|
+
return;
|
|
293
|
+
const configInline = getFullBuildInlineConfig(config);
|
|
294
|
+
if (isPrerenderAutoRunEnabled(vikeConfig)) {
|
|
295
|
+
const res = await runPrerenderFromAutoRun(configInline);
|
|
296
|
+
globalObject.forceExit = res.forceExit;
|
|
297
|
+
assert(wasPrerenderRun());
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function abortViteBuildSsr() {
|
|
301
|
+
const vikeConfig = await getVikeConfigInternal();
|
|
302
|
+
if (vikeConfig.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
303
|
+
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 });
|
|
304
|
+
process.exit(0);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function isDisabled(vikeConfig) {
|
|
308
|
+
const { disableAutoFullBuild } = vikeConfig.config;
|
|
309
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
310
|
+
const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
|
|
311
|
+
return isUserUsingViteApi;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
return disableAutoFullBuild;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function isPrerenderForceExit() {
|
|
318
|
+
return globalObject.forceExit;
|
|
319
|
+
}
|
|
320
|
+
function getFullBuildInlineConfig(config) {
|
|
321
|
+
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
322
|
+
if (config._viteConfigFromUserEnhanced) {
|
|
323
|
+
return config._viteConfigFromUserEnhanced;
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
return {
|
|
327
|
+
...configFromCli,
|
|
328
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
329
|
+
root: config.root,
|
|
330
|
+
build: {
|
|
331
|
+
...configFromCli?.build,
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
@@ -3,9 +3,8 @@ import { pluginBuildApp } from './pluginBuild/pluginBuildApp.js';
|
|
|
3
3
|
import { pluginDistPackageJsonFile } from './pluginBuild/pluginDistPackageJsonFile.js';
|
|
4
4
|
import { pluginSuppressRollupWarning } from './pluginBuild/pluginSuppressRollupWarning.js';
|
|
5
5
|
import { pluginDistFileNames } from './pluginBuild/pluginDistFileNames.js';
|
|
6
|
-
import { pluginAutoFullBuild } from './pluginBuild/pluginAutoFullBuild.js';
|
|
7
6
|
import { pluginBuildEntry } from './pluginBuild/pluginBuildEntry.js';
|
|
8
|
-
import { pluginBuildConfig } from './pluginBuild/pluginBuildConfig.js';
|
|
7
|
+
import { pluginBuildConfig, pluginAutoFullBuild } from './pluginBuild/pluginBuildConfig.js';
|
|
9
8
|
import { pluginModuleBanner } from './pluginBuild/pluginModuleBanner.js';
|
|
10
9
|
function pluginBuild() {
|
|
11
10
|
return [
|
|
@@ -1,34 +1,24 @@
|
|
|
1
1
|
export { pluginPreview };
|
|
2
|
-
import { assertUsage, applyPreview
|
|
2
|
+
import { assertUsage, applyPreview } from '../utils.js';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
7
7
|
import { logDockerHint } from './pluginDev.js';
|
|
8
|
-
import { getOutDirs
|
|
8
|
+
import { getOutDirs } from '../shared/getOutDirs.js';
|
|
9
9
|
import sirv from 'sirv';
|
|
10
10
|
import { getVikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
|
|
11
11
|
function pluginPreview() {
|
|
12
12
|
let config;
|
|
13
|
-
let configUnresolved;
|
|
14
13
|
let vikeConfig;
|
|
15
14
|
return {
|
|
16
15
|
name: 'vike:pluginPreview',
|
|
17
16
|
apply: applyPreview,
|
|
18
|
-
config(
|
|
19
|
-
configUnresolved = config;
|
|
17
|
+
config() {
|
|
20
18
|
return {
|
|
21
19
|
appType: 'custom',
|
|
22
20
|
};
|
|
23
21
|
},
|
|
24
|
-
configEnvironment(envName, configEnv) {
|
|
25
|
-
assert(configUnresolved);
|
|
26
|
-
return {
|
|
27
|
-
build: {
|
|
28
|
-
outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
22
|
async configResolved(config_) {
|
|
33
23
|
config = config_;
|
|
34
24
|
vikeConfig = await getVikeConfigInternal();
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { getOutDirs };
|
|
2
2
|
export { resolveOutDir };
|
|
3
|
-
export { resolveOutDir_configEnvironment };
|
|
4
3
|
export type { OutDirs };
|
|
5
|
-
import type { UserConfig, ResolvedConfig
|
|
4
|
+
import type { UserConfig, ResolvedConfig } from 'vite';
|
|
6
5
|
import { ViteEnv } from './isViteServerSide.js';
|
|
7
6
|
type OutDirs = {
|
|
8
7
|
/** Absolute path to `outDir` */
|
|
@@ -13,6 +12,5 @@ type OutDirs = {
|
|
|
13
12
|
outDirServer: string;
|
|
14
13
|
};
|
|
15
14
|
declare function getOutDirs(configGlobal: ResolvedConfig, viteEnv: ViteEnv | undefined): OutDirs;
|
|
16
|
-
declare function resolveOutDir_configEnvironment(configGlobal: UserConfig, envName: string, configEnv: EnvironmentOptions): string;
|
|
17
15
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
18
16
|
declare function resolveOutDir(config: UserConfig, isServerSide: boolean): string;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { getOutDirs };
|
|
2
2
|
export { resolveOutDir };
|
|
3
|
-
export { resolveOutDir_configEnvironment };
|
|
4
3
|
import pc from '@brillout/picocolors';
|
|
5
4
|
import { assert, assertPosixPath, assertUsage, createDebugger, pathJoin, toPosixPath } from '../utils.js';
|
|
6
|
-
import {
|
|
5
|
+
import { isViteServerSide_withoutEnv } from './isViteServerSide.js';
|
|
7
6
|
const debug = createDebugger('vike:outDir');
|
|
8
7
|
function getOutDirs(configGlobal, viteEnv) {
|
|
9
8
|
debug('getOutDirs()', new Error().stack);
|
|
@@ -15,12 +14,6 @@ function getOutDirs(configGlobal, viteEnv) {
|
|
|
15
14
|
assertNormalization(outDirs.outDirServer);
|
|
16
15
|
return outDirs;
|
|
17
16
|
}
|
|
18
|
-
function resolveOutDir_configEnvironment(configGlobal, envName, configEnv) {
|
|
19
|
-
assert(configGlobal && envName && configEnv);
|
|
20
|
-
const viteEnv = { name: envName, config: configEnv };
|
|
21
|
-
const isServerSide = isViteServerSide(configGlobal, viteEnv);
|
|
22
|
-
return resolveOutDir(configEnv, isServerSide);
|
|
23
|
-
}
|
|
24
17
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
25
18
|
function resolveOutDir(config, isServerSide) {
|
|
26
19
|
debug('resolveOutDir()', new Error().stack);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.237-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.237-commit-2d6f480";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.237-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.237-commit-2d6f480';
|
package/package.json
CHANGED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.pluginAutoFullBuild = pluginAutoFullBuild;
|
|
7
|
-
exports.isPrerenderForceExit = isPrerenderForceExit;
|
|
8
|
-
const utils_js_1 = require("../../utils.js");
|
|
9
|
-
const context_js_1 = require("../../../prerender/context.js");
|
|
10
|
-
const isViteCliCall_js_1 = require("../../shared/isViteCliCall.js");
|
|
11
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
|
-
const logErrorHint_js_1 = require("../../../runtime/renderPage/logErrorHint.js");
|
|
13
|
-
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
14
|
-
const context_js_2 = require("../../../api/context.js");
|
|
15
|
-
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
16
|
-
const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
|
|
17
|
-
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
18
|
-
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
19
|
-
const globalObject = (0, utils_js_1.getGlobalObject)('build/pluginAutoFullBuild.ts', {
|
|
20
|
-
forceExit: false,
|
|
21
|
-
});
|
|
22
|
-
function pluginAutoFullBuild() {
|
|
23
|
-
let config;
|
|
24
|
-
return [
|
|
25
|
-
{
|
|
26
|
-
name: 'vike:build:pluginAutoFullBuild',
|
|
27
|
-
apply: 'build',
|
|
28
|
-
enforce: 'pre',
|
|
29
|
-
async configResolved(config_) {
|
|
30
|
-
config = config_;
|
|
31
|
-
await abortViteBuildSsr();
|
|
32
|
-
},
|
|
33
|
-
writeBundle: {
|
|
34
|
-
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
35
|
-
sequential: true,
|
|
36
|
-
order: 'pre',
|
|
37
|
-
*/
|
|
38
|
-
async handler(options, bundle) {
|
|
39
|
-
try {
|
|
40
|
-
await (0, handleAssetsManifest_js_1.handleAssetsManifest)(config, this.environment, options, bundle);
|
|
41
|
-
await triggerFullBuild(config, this.environment, bundle);
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
// We use try-catch also because:
|
|
45
|
-
// - Vite/Rollup swallows errors thrown inside the writeBundle() hook. (It doesn't swallow errors thrown inside the first writeBundle() hook while building the client-side, but it does swallow errors thrown inside the second writeBundle() while building the server-side triggered after Vike calls Vite's `build()` API.)
|
|
46
|
-
// - Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
47
|
-
console.error(err);
|
|
48
|
-
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: 'vike:build:pluginAutoFullBuild:post',
|
|
56
|
-
apply: 'build',
|
|
57
|
-
enforce: 'post',
|
|
58
|
-
closeBundle: {
|
|
59
|
-
sequential: true,
|
|
60
|
-
order: 'post',
|
|
61
|
-
handler() {
|
|
62
|
-
(0, utils_js_1.onSetupBuild)();
|
|
63
|
-
(0, handleAssetsManifest_js_1.handleAssetsManifest_assertUsageCssTarget)(config, this.environment);
|
|
64
|
-
/* Let vike:build:pluginBuildApp force exit
|
|
65
|
-
runPrerender_forceExit()
|
|
66
|
-
*/
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
async function triggerFullBuild(config, viteEnv, bundle) {
|
|
73
|
-
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
74
|
-
// Whether builder.buildApp() is being used, see plugin:build:pluginBuildApp
|
|
75
|
-
// If builder.buildApp() => trigger at end of `this.environment.name === 'ssr'`.
|
|
76
|
-
// Else => trigger at end of client-side build.
|
|
77
|
-
if (!(0, isViteServerSide_js_1.isViteServerSide_onlySsrEnv)(config, viteEnv))
|
|
78
|
-
return;
|
|
79
|
-
if (isEntirelyDisabled(vikeConfig))
|
|
80
|
-
return;
|
|
81
|
-
// Workaround for @vitejs/plugin-legacy
|
|
82
|
-
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
83
|
-
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
84
|
-
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
85
|
-
if (!bundle[(0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(config.build.manifest)])
|
|
86
|
-
return;
|
|
87
|
-
const configInline = getFullBuildInlineConfig(config);
|
|
88
|
-
/* Already triggered by vike:build:pluginBuildApp
|
|
89
|
-
await build(setSSR(configInline))
|
|
90
|
-
*/
|
|
91
|
-
if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
|
|
92
|
-
const res = await (0, runPrerenderEntry_js_1.runPrerenderFromAutoRun)(configInline);
|
|
93
|
-
globalObject.forceExit = res.forceExit;
|
|
94
|
-
(0, utils_js_1.assert)((0, context_js_1.wasPrerenderRun)());
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async function abortViteBuildSsr() {
|
|
98
|
-
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
99
|
-
if (vikeConfig.config.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
|
|
100
|
-
(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 });
|
|
101
|
-
process.exit(0);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function isEntirelyDisabled(vikeConfig) {
|
|
105
|
-
const { disableAutoFullBuild } = vikeConfig.config;
|
|
106
|
-
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
107
|
-
const isUserUsingViteApi = !(0, isViteCliCall_js_1.isViteCliCall)() && !(0, context_js_2.isVikeCliOrApi)();
|
|
108
|
-
return isUserUsingViteApi;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return disableAutoFullBuild;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function isPrerenderForceExit() {
|
|
115
|
-
return globalObject.forceExit;
|
|
116
|
-
}
|
|
117
|
-
function getFullBuildInlineConfig(config) {
|
|
118
|
-
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
119
|
-
if (config._viteConfigFromUserEnhanced) {
|
|
120
|
-
return config._viteConfigFromUserEnhanced;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return {
|
|
124
|
-
...configFromCli,
|
|
125
|
-
configFile: configFromCli?.configFile || config.configFile,
|
|
126
|
-
root: config.root,
|
|
127
|
-
build: {
|
|
128
|
-
...configFromCli?.build,
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
export { pluginAutoFullBuild };
|
|
2
|
-
export { isPrerenderForceExit };
|
|
3
|
-
import { assert, assertWarning, getGlobalObject, onSetupBuild } from '../../utils.js';
|
|
4
|
-
import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/context.js';
|
|
5
|
-
import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
|
|
6
|
-
import pc from '@brillout/picocolors';
|
|
7
|
-
import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
|
|
8
|
-
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
9
|
-
import { isVikeCliOrApi } from '../../../api/context.js';
|
|
10
|
-
import { handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget } from './handleAssetsManifest.js';
|
|
11
|
-
import { isViteServerSide_onlySsrEnv } from '../../shared/isViteServerSide.js';
|
|
12
|
-
import { runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
|
|
13
|
-
import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
|
|
14
|
-
const globalObject = getGlobalObject('build/pluginAutoFullBuild.ts', {
|
|
15
|
-
forceExit: false,
|
|
16
|
-
});
|
|
17
|
-
function pluginAutoFullBuild() {
|
|
18
|
-
let config;
|
|
19
|
-
return [
|
|
20
|
-
{
|
|
21
|
-
name: 'vike:build:pluginAutoFullBuild',
|
|
22
|
-
apply: 'build',
|
|
23
|
-
enforce: 'pre',
|
|
24
|
-
async configResolved(config_) {
|
|
25
|
-
config = config_;
|
|
26
|
-
await abortViteBuildSsr();
|
|
27
|
-
},
|
|
28
|
-
writeBundle: {
|
|
29
|
-
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
30
|
-
sequential: true,
|
|
31
|
-
order: 'pre',
|
|
32
|
-
*/
|
|
33
|
-
async handler(options, bundle) {
|
|
34
|
-
try {
|
|
35
|
-
await handleAssetsManifest(config, this.environment, options, bundle);
|
|
36
|
-
await triggerFullBuild(config, this.environment, bundle);
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
// We use try-catch also because:
|
|
40
|
-
// - Vite/Rollup swallows errors thrown inside the writeBundle() hook. (It doesn't swallow errors thrown inside the first writeBundle() hook while building the client-side, but it does swallow errors thrown inside the second writeBundle() while building the server-side triggered after Vike calls Vite's `build()` API.)
|
|
41
|
-
// - Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
42
|
-
console.error(err);
|
|
43
|
-
logErrorHint(err);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: 'vike:build:pluginAutoFullBuild:post',
|
|
51
|
-
apply: 'build',
|
|
52
|
-
enforce: 'post',
|
|
53
|
-
closeBundle: {
|
|
54
|
-
sequential: true,
|
|
55
|
-
order: 'post',
|
|
56
|
-
handler() {
|
|
57
|
-
onSetupBuild();
|
|
58
|
-
handleAssetsManifest_assertUsageCssTarget(config, this.environment);
|
|
59
|
-
/* Let vike:build:pluginBuildApp force exit
|
|
60
|
-
runPrerender_forceExit()
|
|
61
|
-
*/
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
];
|
|
66
|
-
}
|
|
67
|
-
async function triggerFullBuild(config, viteEnv, bundle) {
|
|
68
|
-
const vikeConfig = await getVikeConfigInternal();
|
|
69
|
-
// Whether builder.buildApp() is being used, see plugin:build:pluginBuildApp
|
|
70
|
-
// If builder.buildApp() => trigger at end of `this.environment.name === 'ssr'`.
|
|
71
|
-
// Else => trigger at end of client-side build.
|
|
72
|
-
if (!isViteServerSide_onlySsrEnv(config, viteEnv))
|
|
73
|
-
return;
|
|
74
|
-
if (isEntirelyDisabled(vikeConfig))
|
|
75
|
-
return;
|
|
76
|
-
// Workaround for @vitejs/plugin-legacy
|
|
77
|
-
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
78
|
-
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
79
|
-
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
80
|
-
if (!bundle[getManifestFilePathRelative(config.build.manifest)])
|
|
81
|
-
return;
|
|
82
|
-
const configInline = getFullBuildInlineConfig(config);
|
|
83
|
-
/* Already triggered by vike:build:pluginBuildApp
|
|
84
|
-
await build(setSSR(configInline))
|
|
85
|
-
*/
|
|
86
|
-
if (isPrerenderAutoRunEnabled(vikeConfig)) {
|
|
87
|
-
const res = await runPrerenderFromAutoRun(configInline);
|
|
88
|
-
globalObject.forceExit = res.forceExit;
|
|
89
|
-
assert(wasPrerenderRun());
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async function abortViteBuildSsr() {
|
|
93
|
-
const vikeConfig = await getVikeConfigInternal();
|
|
94
|
-
if (vikeConfig.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
95
|
-
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 });
|
|
96
|
-
process.exit(0);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function isEntirelyDisabled(vikeConfig) {
|
|
100
|
-
const { disableAutoFullBuild } = vikeConfig.config;
|
|
101
|
-
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
102
|
-
const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
|
|
103
|
-
return isUserUsingViteApi;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return disableAutoFullBuild;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function isPrerenderForceExit() {
|
|
110
|
-
return globalObject.forceExit;
|
|
111
|
-
}
|
|
112
|
-
function getFullBuildInlineConfig(config) {
|
|
113
|
-
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
114
|
-
if (config._viteConfigFromUserEnhanced) {
|
|
115
|
-
return config._viteConfigFromUserEnhanced;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
return {
|
|
119
|
-
...configFromCli,
|
|
120
|
-
configFile: configFromCli?.configFile || config.configFile,
|
|
121
|
-
root: config.root,
|
|
122
|
-
build: {
|
|
123
|
-
...configFromCli?.build,
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|