vike 0.4.237-commit-2d6f480 → 0.4.237-commit-2c1db32
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/prerender/runPrerenderEntry.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +7 -7
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +121 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -124
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild.js +0 -1
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +4 -4
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +1 -1
- package/dist/cjs/node/vite/shared/getOutDirs.js +2 -6
- package/dist/cjs/node/vite/shared/isViteServerSide.js +25 -56
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/api/build.js +1 -1
- package/dist/esm/node/prerender/runPrerenderEntry.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +3 -3
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +7 -7
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.d.ts +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +118 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -4
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +7 -124
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild.js +1 -2
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +1 -1
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -3
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +1 -1
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +2 -2
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +1 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +4 -4
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +1 -1
- package/dist/esm/node/vite/shared/getOutDirs.d.ts +1 -1
- package/dist/esm/node/vite/shared/getOutDirs.js +3 -7
- package/dist/esm/node/vite/shared/isViteServerSide.d.ts +4 -4
- package/dist/esm/node/vite/shared/isViteServerSide.js +25 -56
- package/dist/esm/types/Config.d.ts +1 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +1 -1
|
@@ -2,57 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isViteServerSide = isViteServerSide;
|
|
4
4
|
exports.isViteClientSide = isViteClientSide;
|
|
5
|
-
exports.
|
|
5
|
+
exports.isViteServerSide_viteEnvOptional = isViteServerSide_viteEnvOptional;
|
|
6
6
|
exports.isViteServerSide_onlySsrEnv = isViteServerSide_onlySsrEnv;
|
|
7
7
|
exports.isViteServerSide_extraSafe = isViteServerSide_extraSafe;
|
|
8
8
|
const assert_js_1 = require("../../../utils/assert.js");
|
|
9
9
|
function isViteServerSide_impl(configGlobal, viteEnv) {
|
|
10
10
|
(0, assert_js_1.assert)(!('consumer' in configGlobal)); // make sure configGlobal isn't viteEnv.config
|
|
11
|
-
const isServerSide1 = !viteEnv?.config.consumer ? null : viteEnv.config.consumer !== 'client';
|
|
12
|
-
const isServerSide2 = !viteEnv?.config.build ? null : getBuildSsrValue(viteEnv.config.build.ssr);
|
|
13
|
-
const isServerSide3 = !configGlobal.build ? null : getBuildSsrValue(configGlobal.build.ssr);
|
|
14
|
-
const isServerSide4 = viteEnv?.name === 'ssr' ? true : viteEnv?.name === 'client' ? false : null;
|
|
15
11
|
const debug = {
|
|
16
12
|
viteEnvIsUndefined: !viteEnv,
|
|
17
13
|
viteEnvName: viteEnv?.name ?? null,
|
|
18
14
|
viteEnvConsumer: viteEnv?.config.consumer ?? null,
|
|
19
15
|
configEnvBuildSsr: viteEnv?.config.build?.ssr ?? null,
|
|
20
16
|
configGlobalBuildSsr: configGlobal.build?.ssr ?? null,
|
|
21
|
-
isServerSide1,
|
|
22
|
-
isServerSide2,
|
|
23
|
-
isServerSide3,
|
|
24
|
-
isServerSide4,
|
|
25
17
|
};
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
return isServerSide1;
|
|
32
|
-
}
|
|
33
|
-
if (isServerSide2 !== null) {
|
|
34
|
-
// assert(isServerSide2 === isServerSide4 || isServerSide4 === null, debug)
|
|
35
|
-
return isServerSide2;
|
|
36
|
-
}
|
|
37
|
-
if (isServerSide3 !== null) {
|
|
38
|
-
// assert(isServerSide3 === isServerSide4 || isServerSide4 === null, debug)
|
|
39
|
-
return isServerSide3;
|
|
18
|
+
if (!viteEnv) {
|
|
19
|
+
const isServerSide = getBuildSsrValue(configGlobal.build?.ssr);
|
|
20
|
+
(0, assert_js_1.assert)(typeof isServerSide === 'boolean', debug);
|
|
21
|
+
return isServerSide;
|
|
40
22
|
}
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
else {
|
|
24
|
+
const isServerSide1 = !viteEnv.config.consumer ? null : viteEnv.config.consumer !== 'client';
|
|
25
|
+
const isServerSide2 = getBuildSsrValue(viteEnv.config.build?.ssr);
|
|
26
|
+
const isServerSide3 = viteEnv.name === 'ssr' ? true : viteEnv.name === 'client' ? false : null;
|
|
27
|
+
const isServerSide = isServerSide1 ?? isServerSide2;
|
|
28
|
+
(0, assert_js_1.assert)(isServerSide === isServerSide1 || isServerSide1 === null, debug);
|
|
29
|
+
(0, assert_js_1.assert)(isServerSide === isServerSide2 || isServerSide2 === null, debug);
|
|
30
|
+
(0, assert_js_1.assert)(isServerSide === isServerSide3 || isServerSide3 === null, debug);
|
|
31
|
+
(0, assert_js_1.assert)(isServerSide !== null);
|
|
32
|
+
return isServerSide;
|
|
43
33
|
}
|
|
44
|
-
(0, assert_js_1.assert)(!viteEnv);
|
|
45
|
-
return !!configGlobal.build?.ssr;
|
|
46
34
|
}
|
|
47
35
|
function getBuildSsrValue(buildSsr) {
|
|
48
36
|
if (buildSsr === undefined)
|
|
49
37
|
return null;
|
|
38
|
+
(0, assert_js_1.assert)(typeof buildSsr === 'boolean' || typeof buildSsr === 'string');
|
|
50
39
|
return !!buildSsr;
|
|
51
40
|
}
|
|
52
41
|
function isViteServerSide(configGlobal, viteEnv) {
|
|
53
42
|
return isViteServerSide_impl(configGlobal, viteEnv);
|
|
54
43
|
}
|
|
55
|
-
function
|
|
44
|
+
function isViteServerSide_viteEnvOptional(configGlobal, viteEnv) {
|
|
56
45
|
return isViteServerSide_impl(configGlobal, viteEnv);
|
|
57
46
|
}
|
|
58
47
|
function isViteClientSide(configGlobal, viteEnv) {
|
|
@@ -63,37 +52,17 @@ function isViteServerSide_onlySsrEnv(configGlobal, viteEnv) {
|
|
|
63
52
|
return viteEnv.name ? viteEnv.name === 'ssr' : isViteServerSide(configGlobal, viteEnv);
|
|
64
53
|
}
|
|
65
54
|
// Vite is quite messy about setting config.build.ssr — for security purposes, we use an extra safe implementation with lots of assertions, which is needed for the .client.js and .server.js guarantee.
|
|
66
|
-
function isViteServerSide_extraSafe(config,
|
|
55
|
+
function isViteServerSide_extraSafe(config, viteEnv, options) {
|
|
67
56
|
const isServerSide = isViteServerSide(config, viteEnv);
|
|
68
57
|
const debug = {
|
|
58
|
+
isServerSide,
|
|
69
59
|
configCommand: config.command,
|
|
70
|
-
configBuildSsr: config.build.ssr,
|
|
60
|
+
configBuildSsr: getBuildSsrValue(config.build.ssr),
|
|
71
61
|
optionsIsUndefined: options === undefined,
|
|
72
|
-
optionsSsr: options?.ssr,
|
|
73
|
-
isServerSide,
|
|
62
|
+
optionsSsr: options?.ssr ?? null,
|
|
74
63
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return res;
|
|
80
|
-
}
|
|
81
|
-
return isServerSide;
|
|
82
|
-
}
|
|
83
|
-
if (config.command === 'build') {
|
|
84
|
-
const res = config.build.ssr;
|
|
85
|
-
(0, assert_js_1.assert)(typeof res === 'boolean', debug);
|
|
86
|
-
(0, assert_js_1.assert)(res === options?.ssr || options?.ssr === undefined, debug);
|
|
87
|
-
(0, assert_js_1.assert)(res === isServerSide, debug);
|
|
88
|
-
return res;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const res = options?.ssr;
|
|
92
|
-
(0, assert_js_1.assert)(typeof res === 'boolean', debug);
|
|
93
|
-
/* This assertion can fail, seems to be a Vite bug? It's very unexpected.
|
|
94
|
-
if (typeof config.build.ssr === 'boolean') assert(res === config.build.ssr)
|
|
95
|
-
*/
|
|
96
|
-
(0, assert_js_1.assert)(res === isServerSide, debug);
|
|
97
|
-
return res;
|
|
98
|
-
}
|
|
64
|
+
(0, assert_js_1.assert)(options, debug);
|
|
65
|
+
(0, assert_js_1.assert)(typeof options.ssr === 'boolean', debug);
|
|
66
|
+
(0, assert_js_1.assert)(options.ssr === isServerSide, debug);
|
|
67
|
+
return isServerSide;
|
|
99
68
|
}
|
|
@@ -8,7 +8,7 @@ import { createBuilder } from 'vite';
|
|
|
8
8
|
*/
|
|
9
9
|
async function build(options = {}) {
|
|
10
10
|
const { viteConfigFromUserEnhanced } = await prepareViteApiCall(options, 'build');
|
|
11
|
-
// Pass it to
|
|
11
|
+
// Pass it to vike:build:pluginBuildApp
|
|
12
12
|
if (viteConfigFromUserEnhanced)
|
|
13
13
|
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
|
|
14
14
|
const builder = await createBuilder(viteConfigFromUserEnhanced);
|
|
@@ -33,7 +33,7 @@ async function runPrerenderFromAutoRun(viteConfig) {
|
|
|
33
33
|
await runPrerender({ viteConfig }, 'auto-run');
|
|
34
34
|
}
|
|
35
35
|
catch (err) {
|
|
36
|
-
// Avoid Rollup prefixing the error with [vike:build:
|
|
36
|
+
// Avoid Rollup prefixing the error with [vike:build:pluginBuildApp], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
37
37
|
console.error(err);
|
|
38
38
|
logErrorHint(err);
|
|
39
39
|
process.exit(1);
|
|
@@ -3,12 +3,12 @@ export { handleAssetsManifest_getBuildConfig };
|
|
|
3
3
|
export { handleAssetsManifest_isFixEnabled };
|
|
4
4
|
export { handleAssetsManifest_assertUsageCssCodeSplit };
|
|
5
5
|
export { handleAssetsManifest_assertUsageCssTarget };
|
|
6
|
-
import type { Environment, ResolvedConfig, Rollup
|
|
6
|
+
import type { Environment, ResolvedConfig, Rollup } from 'vite';
|
|
7
7
|
type Bundle = Rollup.OutputBundle;
|
|
8
|
-
declare function handleAssetsManifest_isFixEnabled(
|
|
8
|
+
declare function handleAssetsManifest_isFixEnabled(): boolean;
|
|
9
9
|
declare function handleAssetsManifest_assertUsageCssCodeSplit(config: ResolvedConfig): void;
|
|
10
10
|
declare function handleAssetsManifest_assertUsageCssTarget(config: ResolvedConfig, env: Environment): void;
|
|
11
|
-
declare function handleAssetsManifest_getBuildConfig(
|
|
11
|
+
declare function handleAssetsManifest_getBuildConfig(): Promise<{
|
|
12
12
|
readonly ssrEmitAssets: true | undefined;
|
|
13
13
|
readonly cssMinify: "esbuild" | undefined;
|
|
14
14
|
readonly manifest: true;
|
|
@@ -21,7 +21,7 @@ const globalObject = getGlobalObject('build/handleAssetsManifest.ts', {
|
|
|
21
21
|
});
|
|
22
22
|
// true => use workaround config.build.ssrEmitAssets
|
|
23
23
|
// false => use workaround extractAssets plugin
|
|
24
|
-
function handleAssetsManifest_isFixEnabled(
|
|
24
|
+
function handleAssetsManifest_isFixEnabled() {
|
|
25
25
|
// Allow user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
|
|
26
26
|
return isV1Design();
|
|
27
27
|
}
|
|
@@ -212,13 +212,13 @@ function getHash(src) {
|
|
|
212
212
|
}
|
|
213
213
|
// https://github.com/vikejs/vike/issues/1993
|
|
214
214
|
function handleAssetsManifest_assertUsageCssCodeSplit(config) {
|
|
215
|
-
if (!handleAssetsManifest_isFixEnabled(
|
|
215
|
+
if (!handleAssetsManifest_isFixEnabled())
|
|
216
216
|
return;
|
|
217
217
|
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 });
|
|
218
218
|
}
|
|
219
219
|
const targets = [];
|
|
220
220
|
function handleAssetsManifest_assertUsageCssTarget(config, env) {
|
|
221
|
-
if (!handleAssetsManifest_isFixEnabled(
|
|
221
|
+
if (!handleAssetsManifest_isFixEnabled())
|
|
222
222
|
return;
|
|
223
223
|
const isServerSide = isViteServerSide(config, env);
|
|
224
224
|
assert(typeof isServerSide === 'boolean');
|
|
@@ -279,8 +279,8 @@ async function writeManifestFile(manifest, manifestFilePath) {
|
|
|
279
279
|
const manifestFileContent = JSON.stringify(manifest, null, 2);
|
|
280
280
|
await fs.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
|
|
281
281
|
}
|
|
282
|
-
async function handleAssetsManifest_getBuildConfig(
|
|
283
|
-
const isFixEnabled = handleAssetsManifest_isFixEnabled(
|
|
282
|
+
async function handleAssetsManifest_getBuildConfig() {
|
|
283
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
284
284
|
return {
|
|
285
285
|
// https://github.com/vikejs/vike/issues/1339
|
|
286
286
|
ssrEmitAssets: isFixEnabled ? true : undefined,
|
|
@@ -288,7 +288,7 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
288
288
|
cssMinify: isFixEnabled ? 'esbuild' : undefined,
|
|
289
289
|
manifest: true,
|
|
290
290
|
/* Already set by vike:build:pluginBuildApp
|
|
291
|
-
copyPublicDir: !
|
|
291
|
+
copyPublicDir: !isViteServerSide_viteEnvOptional(config),
|
|
292
292
|
*/
|
|
293
293
|
};
|
|
294
294
|
}
|
|
@@ -313,7 +313,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
async function writeAssetsManifestFile(assetsJsonFilePath, config) {
|
|
316
|
-
const isFixEnabled = handleAssetsManifest_isFixEnabled(
|
|
316
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
317
317
|
const clientManifestFilePath = getManifestFilePath(config, true);
|
|
318
318
|
const serverManifestFilePath = getManifestFilePath(config, false);
|
|
319
319
|
if (!isFixEnabled) {
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
export { pluginBuildApp };
|
|
2
|
+
export { isPrerenderForceExit };
|
|
2
3
|
import { runPrerender_forceExit } from '../../../prerender/runPrerenderEntry.js';
|
|
3
4
|
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
4
|
-
import { assert } from '../../utils.js';
|
|
5
|
-
import {
|
|
5
|
+
import { assert, assertWarning, getGlobalObject, onSetupBuild } from '../../utils.js';
|
|
6
|
+
import { isPrerenderAutoRunEnabled, wasPrerenderRun } 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 { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
11
|
+
import { isVikeCliOrApi } from '../../../api/context.js';
|
|
12
|
+
import { handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget } from './handleAssetsManifest.js';
|
|
13
|
+
import { isViteServerSide_onlySsrEnv } from '../../shared/isViteServerSide.js';
|
|
14
|
+
import { runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
|
|
15
|
+
import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
|
|
16
|
+
const globalObject = getGlobalObject('build/pluginBuildApp.ts', {
|
|
17
|
+
forceExit: false,
|
|
18
|
+
});
|
|
6
19
|
function pluginBuildApp() {
|
|
20
|
+
let config;
|
|
7
21
|
return [
|
|
8
22
|
{
|
|
9
23
|
name: 'vike:build:pluginBuildApp:pre',
|
|
@@ -55,5 +69,107 @@ function pluginBuildApp() {
|
|
|
55
69
|
};
|
|
56
70
|
},
|
|
57
71
|
},
|
|
72
|
+
{
|
|
73
|
+
name: 'vike:build:pluginBuildApp:autoFullBuild:pre',
|
|
74
|
+
apply: 'build',
|
|
75
|
+
enforce: 'pre',
|
|
76
|
+
async configResolved(config_) {
|
|
77
|
+
config = config_;
|
|
78
|
+
await abortViteBuildSsr();
|
|
79
|
+
},
|
|
80
|
+
// TO-DO/eventually: stop using this writeBundle() hack and, instead, use the buildApp() implementation above.
|
|
81
|
+
// - Could it cause issues if a tool uses the writeBundle() hack together with getVikeConfig() ?
|
|
82
|
+
writeBundle: {
|
|
83
|
+
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
84
|
+
sequential: true,
|
|
85
|
+
order: 'pre',
|
|
86
|
+
*/
|
|
87
|
+
async handler(options, bundle) {
|
|
88
|
+
try {
|
|
89
|
+
await handleAssetsManifest(config, this.environment, options, bundle);
|
|
90
|
+
await triggerPrerendering(config, this.environment, bundle);
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
// We use try-catch also because:
|
|
94
|
+
// - 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.)
|
|
95
|
+
// - Avoid Rollup prefixing the error with [vike:build:pluginBuildApp], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
96
|
+
console.error(err);
|
|
97
|
+
logErrorHint(err);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'vike:build:pluginBuildApp:autoFullBuild:post',
|
|
105
|
+
apply: 'build',
|
|
106
|
+
enforce: 'post',
|
|
107
|
+
closeBundle: {
|
|
108
|
+
sequential: true,
|
|
109
|
+
order: 'post',
|
|
110
|
+
handler() {
|
|
111
|
+
onSetupBuild();
|
|
112
|
+
handleAssetsManifest_assertUsageCssTarget(config, this.environment);
|
|
113
|
+
/* Let vike:build:pluginBuildApp force exit
|
|
114
|
+
runPrerender_forceExit()
|
|
115
|
+
*/
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
58
119
|
];
|
|
59
120
|
}
|
|
121
|
+
async function triggerPrerendering(config, viteEnv, bundle) {
|
|
122
|
+
const vikeConfig = await getVikeConfigInternal();
|
|
123
|
+
if (!isViteServerSide_onlySsrEnv(config, viteEnv))
|
|
124
|
+
return;
|
|
125
|
+
if (isDisabled(vikeConfig))
|
|
126
|
+
return;
|
|
127
|
+
// Workaround for @vitejs/plugin-legacy
|
|
128
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
129
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
130
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
131
|
+
if (!bundle[getManifestFilePathRelative(config.build.manifest)])
|
|
132
|
+
return;
|
|
133
|
+
const configInline = getFullBuildInlineConfig(config);
|
|
134
|
+
if (isPrerenderAutoRunEnabled(vikeConfig)) {
|
|
135
|
+
const res = await runPrerenderFromAutoRun(configInline);
|
|
136
|
+
globalObject.forceExit = res.forceExit;
|
|
137
|
+
assert(wasPrerenderRun());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async function abortViteBuildSsr() {
|
|
141
|
+
const vikeConfig = await getVikeConfigInternal();
|
|
142
|
+
if (vikeConfig.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
|
|
143
|
+
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 });
|
|
144
|
+
process.exit(0);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function isDisabled(vikeConfig) {
|
|
148
|
+
const { disableAutoFullBuild } = vikeConfig.config;
|
|
149
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
150
|
+
const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
|
|
151
|
+
return isUserUsingViteApi;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
return disableAutoFullBuild;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function isPrerenderForceExit() {
|
|
158
|
+
return globalObject.forceExit;
|
|
159
|
+
}
|
|
160
|
+
function getFullBuildInlineConfig(config) {
|
|
161
|
+
const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
|
|
162
|
+
if (config._viteConfigFromUserEnhanced) {
|
|
163
|
+
return config._viteConfigFromUserEnhanced;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
return {
|
|
167
|
+
...configFromCli,
|
|
168
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
169
|
+
root: config.root,
|
|
170
|
+
build: {
|
|
171
|
+
...configFromCli?.build,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
export { pluginAutoFullBuild };
|
|
5
|
-
export { isPrerenderForceExit };
|
|
6
4
|
import type { ResolvedConfig, Plugin } from 'vite';
|
|
7
5
|
import type { PageConfigBuildTime } from '../../../../types/PageConfig.js';
|
|
8
6
|
declare function pluginBuildConfig(): Plugin[];
|
|
@@ -12,5 +10,3 @@ declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config
|
|
|
12
10
|
clientEntries: Record<string, string>;
|
|
13
11
|
};
|
|
14
12
|
declare function assertRollupInput(config: ResolvedConfig): void;
|
|
15
|
-
declare function pluginAutoFullBuild(): Plugin[];
|
|
16
|
-
declare function isPrerenderForceExit(): boolean;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
|
|
5
|
-
export { isPrerenderForceExit };
|
|
6
|
-
import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, assertWarning, getGlobalObject, } from '../../utils.js';
|
|
4
|
+
import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, } from '../../utils.js';
|
|
7
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
8
6
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
9
7
|
import { generateVirtualFileId } from '../../../shared/virtualFileId.js';
|
|
@@ -11,19 +9,9 @@ import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
|
11
9
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
12
10
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
13
11
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
14
|
-
import {
|
|
15
|
-
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig,
|
|
12
|
+
import { isViteServerSide_viteEnvOptional } from '../../shared/isViteServerSide.js';
|
|
13
|
+
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
|
|
16
14
|
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
|
-
});
|
|
27
15
|
function pluginBuildConfig() {
|
|
28
16
|
let config;
|
|
29
17
|
return [
|
|
@@ -46,9 +34,9 @@ function pluginBuildConfig() {
|
|
|
46
34
|
},
|
|
47
35
|
config: {
|
|
48
36
|
order: 'post',
|
|
49
|
-
async handler(
|
|
37
|
+
async handler() {
|
|
50
38
|
onSetupBuild();
|
|
51
|
-
const build = await handleAssetsManifest_getBuildConfig(
|
|
39
|
+
const build = await handleAssetsManifest_getBuildConfig();
|
|
52
40
|
return { build };
|
|
53
41
|
},
|
|
54
42
|
},
|
|
@@ -64,7 +52,7 @@ async function getEntries(config) {
|
|
|
64
52
|
// TO-DO/next-major-release: remove
|
|
65
53
|
const pageFileEntries = await getPageFileEntries(config, resolveIncludeAssetsImportedByServer(vikeConfig.config));
|
|
66
54
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
67
|
-
if (
|
|
55
|
+
if (isViteServerSide_viteEnvOptional(config)) {
|
|
68
56
|
const pageEntries = getPageEntries(pageConfigs);
|
|
69
57
|
const entries = {
|
|
70
58
|
...pageFileEntries,
|
|
@@ -137,7 +125,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
137
125
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
138
126
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
139
127
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
140
|
-
const isForClientSide = !
|
|
128
|
+
const isForClientSide = !isViteServerSide_viteEnvOptional(config);
|
|
141
129
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
142
130
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
143
131
|
fileTypes.push('.page.server');
|
|
@@ -228,108 +216,3 @@ function assertRollupInput(config) {
|
|
|
228
216
|
const htmlInput = htmlInputs[0];
|
|
229
217
|
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`);
|
|
230
218
|
}
|
|
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
|
-
}
|
|
@@ -16,7 +16,7 @@ function pluginModuleBanner() {
|
|
|
16
16
|
transform: {
|
|
17
17
|
order: 'post',
|
|
18
18
|
handler(code, id, options) {
|
|
19
|
-
if (!isViteServerSide_extraSafe(config,
|
|
19
|
+
if (!isViteServerSide_extraSafe(config, this.environment, options) &&
|
|
20
20
|
// Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
|
|
21
21
|
config.build.minify) {
|
|
22
22
|
return;
|
|
@@ -4,13 +4,12 @@ import { pluginDistPackageJsonFile } from './pluginBuild/pluginDistPackageJsonFi
|
|
|
4
4
|
import { pluginSuppressRollupWarning } from './pluginBuild/pluginSuppressRollupWarning.js';
|
|
5
5
|
import { pluginDistFileNames } from './pluginBuild/pluginDistFileNames.js';
|
|
6
6
|
import { pluginBuildEntry } from './pluginBuild/pluginBuildEntry.js';
|
|
7
|
-
import { pluginBuildConfig
|
|
7
|
+
import { pluginBuildConfig } from './pluginBuild/pluginBuildConfig.js';
|
|
8
8
|
import { pluginModuleBanner } from './pluginBuild/pluginModuleBanner.js';
|
|
9
9
|
function pluginBuild() {
|
|
10
10
|
return [
|
|
11
11
|
...pluginBuildConfig(),
|
|
12
12
|
...pluginBuildApp(),
|
|
13
|
-
...pluginAutoFullBuild(),
|
|
14
13
|
...pluginBuildEntry(),
|
|
15
14
|
pluginDistPackageJsonFile(),
|
|
16
15
|
pluginSuppressRollupWarning(),
|
|
@@ -36,7 +36,7 @@ function pluginEnvVars() {
|
|
|
36
36
|
if (!code.includes('import.meta.env.'))
|
|
37
37
|
return;
|
|
38
38
|
const isBuild = config.command === 'build';
|
|
39
|
-
const isClientSide = !isViteServerSide_extraSafe(config,
|
|
39
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
40
40
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
41
41
|
// Find & check
|
|
42
42
|
const replacements = Object.entries(envsAll)
|
|
@@ -45,7 +45,7 @@ function pluginExtractAssets() {
|
|
|
45
45
|
}
|
|
46
46
|
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
47
47
|
assert(includeAssetsImportedByServer);
|
|
48
|
-
assert(!isViteServerSide_extraSafe(config,
|
|
48
|
+
assert(!isViteServerSide_extraSafe(config, this.environment, options));
|
|
49
49
|
const importStatements = await getImportStatements(src);
|
|
50
50
|
const moduleNames = getImportedModules(importStatements);
|
|
51
51
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -62,7 +62,7 @@ function pluginExtractAssets() {
|
|
|
62
62
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
63
63
|
enforce: 'pre',
|
|
64
64
|
async resolveId(source, importer, options) {
|
|
65
|
-
if (isViteServerSide_extraSafe(config,
|
|
65
|
+
if (isViteServerSide_extraSafe(config, this.environment, options)) {
|
|
66
66
|
// When building for the server, there should never be a `?extractAssets` query
|
|
67
67
|
assert(!extractAssetsRE.test(source));
|
|
68
68
|
assert(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -139,7 +139,7 @@ function pluginExtractAssets() {
|
|
|
139
139
|
async configResolved(config_) {
|
|
140
140
|
config = config_;
|
|
141
141
|
vikeConfig = await getVikeConfigInternal();
|
|
142
|
-
isFixEnabled = handleAssetsManifest_isFixEnabled(
|
|
142
|
+
isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
143
143
|
if (!isFixEnabled) {
|
|
144
144
|
// https://github.com/vikejs/vike/issues/1060
|
|
145
145
|
assertUsage(!config.plugins.find((p) => p.name === 'vite-tsconfig-paths'), 'vite-tsconfig-paths not supported, remove it and use vite.config.js#resolve.alias instead');
|
|
@@ -16,7 +16,7 @@ function pluginExtractExportNames() {
|
|
|
16
16
|
enforce: 'post',
|
|
17
17
|
async transform(src, id, options) {
|
|
18
18
|
id = normalizeId(id);
|
|
19
|
-
const isClientSide = !isViteServerSide_extraSafe(config,
|
|
19
|
+
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
20
20
|
if (extractExportNamesRE.test(id)) {
|
|
21
21
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
22
22
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
@@ -29,7 +29,7 @@ function pluginFileEnv() {
|
|
|
29
29
|
const importers = Array.from(moduleInfo.importers)
|
|
30
30
|
.map((m) => m.id)
|
|
31
31
|
.filter((id) => id !== null);
|
|
32
|
-
assertFileEnv(id, isViteServerSide_extraSafe(config,
|
|
32
|
+
assertFileEnv(id, isViteServerSide_extraSafe(config, this.environment, options), importers,
|
|
33
33
|
// In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
|
|
34
34
|
true);
|
|
35
35
|
},
|
|
@@ -41,7 +41,7 @@ function pluginFileEnv() {
|
|
|
41
41
|
return;
|
|
42
42
|
if (skip(id))
|
|
43
43
|
return;
|
|
44
|
-
const isServerSide = isViteServerSide_extraSafe(config,
|
|
44
|
+
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
45
45
|
if (!isWrongEnv(id, isServerSide))
|
|
46
46
|
return;
|
|
47
47
|
const { importers } = this.getModuleInfo(id);
|
|
@@ -33,7 +33,7 @@ function pluginReplaceConstants() {
|
|
|
33
33
|
const constantsMap = [];
|
|
34
34
|
constantsMap.push({
|
|
35
35
|
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
36
|
-
replacement: !isViteServerSide_extraSafe(config,
|
|
36
|
+
replacement: !isViteServerSide_extraSafe(config, this.environment, options),
|
|
37
37
|
});
|
|
38
38
|
constantsMap.forEach(({ constants, replacement }) => {
|
|
39
39
|
if (!constants.some((c) => code.includes(c)))
|