vike 0.4.237-commit-2d6f480 → 0.4.237-commit-cc7f0f6
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/runtime/globalContext.js +7 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +7 -7
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +120 -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/shared/createGlobalContextShared.js +9 -5
- 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/runtime/globalContext.js +7 -2
- 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.js +117 -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/shared/createGlobalContextShared.d.ts +1 -0
- package/dist/esm/shared/createGlobalContextShared.js +10 -6
- 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
|
@@ -10,7 +10,7 @@ const vite_1 = require("vite");
|
|
|
10
10
|
*/
|
|
11
11
|
async function build(options = {}) {
|
|
12
12
|
const { viteConfigFromUserEnhanced } = await (0, prepareViteApiCall_js_1.prepareViteApiCall)(options, 'build');
|
|
13
|
-
// Pass it to
|
|
13
|
+
// Pass it to vike:build:pluginBuildApp
|
|
14
14
|
if (viteConfigFromUserEnhanced)
|
|
15
15
|
viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
|
|
16
16
|
const builder = await (0, vite_1.createBuilder)(viteConfigFromUserEnhanced);
|
|
@@ -35,7 +35,7 @@ async function runPrerenderFromAutoRun(viteConfig) {
|
|
|
35
35
|
await (0, runPrerender_js_1.runPrerender)({ viteConfig }, 'auto-run');
|
|
36
36
|
}
|
|
37
37
|
catch (err) {
|
|
38
|
-
// Avoid Rollup prefixing the error with [vike:build:
|
|
38
|
+
// Avoid Rollup prefixing the error with [vike:build:pluginBuildApp], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
39
39
|
console.error(err);
|
|
40
40
|
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
41
41
|
process.exit(1);
|
|
@@ -420,13 +420,18 @@ async function updateUserFiles() {
|
|
|
420
420
|
async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
421
421
|
debug('createGlobalContext()');
|
|
422
422
|
(0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
|
|
423
|
-
const
|
|
423
|
+
const globalContextPromise = (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExportsGlobalEntry, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
424
|
+
debug('createGlobalContext() - done [sync]');
|
|
425
|
+
// We define an early globalContext version synchronously, so that getGlobalContextSync() can be called early.
|
|
426
|
+
// - Required by vike-vercel
|
|
427
|
+
(0, utils_js_1.assert)(globalObject.globalContext);
|
|
428
|
+
const globalContext = await globalContextPromise;
|
|
424
429
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
425
430
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
426
431
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
427
432
|
assertGlobalContextIsDefined();
|
|
428
433
|
(0, utils_js_1.onSetupRuntime)();
|
|
429
|
-
debug('createGlobalContext() - done');
|
|
434
|
+
debug('createGlobalContext() - done [async]');
|
|
430
435
|
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
431
436
|
return globalContext;
|
|
432
437
|
}
|
|
@@ -26,7 +26,7 @@ const globalObject = (0, utils_js_1.getGlobalObject)('build/handleAssetsManifest
|
|
|
26
26
|
});
|
|
27
27
|
// true => use workaround config.build.ssrEmitAssets
|
|
28
28
|
// false => use workaround extractAssets plugin
|
|
29
|
-
function handleAssetsManifest_isFixEnabled(
|
|
29
|
+
function handleAssetsManifest_isFixEnabled() {
|
|
30
30
|
// Allow user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
|
|
31
31
|
return (0, resolveVikeConfigInternal_js_1.isV1Design)();
|
|
32
32
|
}
|
|
@@ -217,13 +217,13 @@ function getHash(src) {
|
|
|
217
217
|
}
|
|
218
218
|
// https://github.com/vikejs/vike/issues/1993
|
|
219
219
|
function handleAssetsManifest_assertUsageCssCodeSplit(config) {
|
|
220
|
-
if (!handleAssetsManifest_isFixEnabled(
|
|
220
|
+
if (!handleAssetsManifest_isFixEnabled())
|
|
221
221
|
return;
|
|
222
222
|
(0, utils_js_1.assertWarning)(config.build.cssCodeSplit, `${picocolors_1.default.cyan('build.cssCodeSplit')} shouldn't be set to ${picocolors_1.default.cyan('false')} (https://github.com/vikejs/vike/issues/1993)`, { onlyOnce: true });
|
|
223
223
|
}
|
|
224
224
|
const targets = [];
|
|
225
225
|
function handleAssetsManifest_assertUsageCssTarget(config, env) {
|
|
226
|
-
if (!handleAssetsManifest_isFixEnabled(
|
|
226
|
+
if (!handleAssetsManifest_isFixEnabled())
|
|
227
227
|
return;
|
|
228
228
|
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide)(config, env);
|
|
229
229
|
(0, utils_js_1.assert)(typeof isServerSide === 'boolean');
|
|
@@ -284,8 +284,8 @@ async function writeManifestFile(manifest, manifestFilePath) {
|
|
|
284
284
|
const manifestFileContent = JSON.stringify(manifest, null, 2);
|
|
285
285
|
await promises_1.default.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
|
|
286
286
|
}
|
|
287
|
-
async function handleAssetsManifest_getBuildConfig(
|
|
288
|
-
const isFixEnabled = handleAssetsManifest_isFixEnabled(
|
|
287
|
+
async function handleAssetsManifest_getBuildConfig() {
|
|
288
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
289
289
|
return {
|
|
290
290
|
// https://github.com/vikejs/vike/issues/1339
|
|
291
291
|
ssrEmitAssets: isFixEnabled ? true : undefined,
|
|
@@ -293,7 +293,7 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
293
293
|
cssMinify: isFixEnabled ? 'esbuild' : undefined,
|
|
294
294
|
manifest: true,
|
|
295
295
|
/* Already set by vike:build:pluginBuildApp
|
|
296
|
-
copyPublicDir: !
|
|
296
|
+
copyPublicDir: !isViteServerSide_viteEnvOptional(config),
|
|
297
297
|
*/
|
|
298
298
|
};
|
|
299
299
|
}
|
|
@@ -318,7 +318,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
async function writeAssetsManifestFile(assetsJsonFilePath, config) {
|
|
321
|
-
const isFixEnabled = handleAssetsManifest_isFixEnabled(
|
|
321
|
+
const isFixEnabled = handleAssetsManifest_isFixEnabled();
|
|
322
322
|
const clientManifestFilePath = getManifestFilePath(config, true);
|
|
323
323
|
const serverManifestFilePath = getManifestFilePath(config, false);
|
|
324
324
|
if (!isFixEnabled) {
|
|
@@ -1,11 +1,27 @@
|
|
|
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.pluginBuildApp = pluginBuildApp;
|
|
4
7
|
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
5
8
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
6
9
|
const utils_js_1 = require("../../utils.js");
|
|
7
|
-
const
|
|
10
|
+
const context_js_1 = require("../../../prerender/context.js");
|
|
11
|
+
const isViteCliCall_js_1 = require("../../shared/isViteCliCall.js");
|
|
12
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
+
const logErrorHint_js_1 = require("../../../runtime/renderPage/logErrorHint.js");
|
|
14
|
+
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
15
|
+
const context_js_2 = require("../../../api/context.js");
|
|
16
|
+
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
17
|
+
const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
|
|
18
|
+
const runPrerenderEntry_js_2 = require("../../../prerender/runPrerenderEntry.js");
|
|
19
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
20
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('build/pluginBuildApp.ts', {
|
|
21
|
+
forceExit: false,
|
|
22
|
+
});
|
|
8
23
|
function pluginBuildApp() {
|
|
24
|
+
let config;
|
|
9
25
|
return [
|
|
10
26
|
{
|
|
11
27
|
name: 'vike:build:pluginBuildApp:pre',
|
|
@@ -22,7 +38,7 @@ function pluginBuildApp() {
|
|
|
22
38
|
(0, utils_js_1.assert)(builder.environments.ssr);
|
|
23
39
|
await builder.build(builder.environments.client);
|
|
24
40
|
await builder.build(builder.environments.ssr);
|
|
25
|
-
if (
|
|
41
|
+
if (isPrerenderForceExit()) {
|
|
26
42
|
(0, runPrerenderEntry_js_1.runPrerender_forceExit)();
|
|
27
43
|
(0, utils_js_1.assert)(false);
|
|
28
44
|
}
|
|
@@ -57,5 +73,107 @@ function pluginBuildApp() {
|
|
|
57
73
|
};
|
|
58
74
|
},
|
|
59
75
|
},
|
|
76
|
+
{
|
|
77
|
+
name: 'vike:build:pluginBuildApp:autoFullBuild:pre',
|
|
78
|
+
apply: 'build',
|
|
79
|
+
enforce: 'pre',
|
|
80
|
+
async configResolved(config_) {
|
|
81
|
+
config = config_;
|
|
82
|
+
await abortViteBuildSsr();
|
|
83
|
+
},
|
|
84
|
+
// TO-DO/eventually: stop using this writeBundle() hack and, instead, use the buildApp() implementation above.
|
|
85
|
+
// - Could it cause issues if a tool uses the writeBundle() hack together with getVikeConfig() ?
|
|
86
|
+
writeBundle: {
|
|
87
|
+
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
88
|
+
sequential: true,
|
|
89
|
+
order: 'pre',
|
|
90
|
+
*/
|
|
91
|
+
async handler(options, bundle) {
|
|
92
|
+
try {
|
|
93
|
+
await (0, handleAssetsManifest_js_1.handleAssetsManifest)(config, this.environment, options, bundle);
|
|
94
|
+
await triggerPrerendering(config, this.environment, bundle);
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
// We use try-catch also because:
|
|
98
|
+
// - 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.)
|
|
99
|
+
// - Avoid Rollup prefixing the error with [vike:build:pluginBuildApp], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
100
|
+
console.error(err);
|
|
101
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: 'vike:build:pluginBuildApp:autoFullBuild:post',
|
|
109
|
+
apply: 'build',
|
|
110
|
+
enforce: 'post',
|
|
111
|
+
closeBundle: {
|
|
112
|
+
sequential: true,
|
|
113
|
+
order: 'post',
|
|
114
|
+
handler() {
|
|
115
|
+
(0, utils_js_1.onSetupBuild)();
|
|
116
|
+
(0, handleAssetsManifest_js_1.handleAssetsManifest_assertUsageCssTarget)(config, this.environment);
|
|
117
|
+
/* Let vike:build:pluginBuildApp force exit
|
|
118
|
+
runPrerender_forceExit()
|
|
119
|
+
*/
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
60
123
|
];
|
|
61
124
|
}
|
|
125
|
+
async function triggerPrerendering(config, viteEnv, bundle) {
|
|
126
|
+
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
127
|
+
if (!(0, isViteServerSide_js_1.isViteServerSide_onlySsrEnv)(config, viteEnv))
|
|
128
|
+
return;
|
|
129
|
+
if (isDisabled(vikeConfig))
|
|
130
|
+
return;
|
|
131
|
+
// Workaround for @vitejs/plugin-legacy
|
|
132
|
+
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
133
|
+
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
134
|
+
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
135
|
+
if (!bundle[(0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(config.build.manifest)])
|
|
136
|
+
return;
|
|
137
|
+
if (!(0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig))
|
|
138
|
+
return;
|
|
139
|
+
const configInline = getFullBuildInlineConfig(config);
|
|
140
|
+
const res = await (0, runPrerenderEntry_js_2.runPrerenderFromAutoRun)(configInline);
|
|
141
|
+
globalObject.forceExit = res.forceExit;
|
|
142
|
+
(0, utils_js_1.assert)((0, context_js_1.wasPrerenderRun)());
|
|
143
|
+
}
|
|
144
|
+
async function abortViteBuildSsr() {
|
|
145
|
+
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
146
|
+
if (vikeConfig.config.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
|
|
147
|
+
(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 });
|
|
148
|
+
process.exit(0);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function isDisabled(vikeConfig) {
|
|
152
|
+
const { disableAutoFullBuild } = vikeConfig.config;
|
|
153
|
+
if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
|
|
154
|
+
const isUserUsingViteApi = !(0, isViteCliCall_js_1.isViteCliCall)() && !(0, context_js_2.isVikeCliOrApi)();
|
|
155
|
+
return isUserUsingViteApi;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return disableAutoFullBuild;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function isPrerenderForceExit() {
|
|
162
|
+
return globalObject.forceExit;
|
|
163
|
+
}
|
|
164
|
+
function getFullBuildInlineConfig(config) {
|
|
165
|
+
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
166
|
+
if (config._viteConfigFromUserEnhanced) {
|
|
167
|
+
return config._viteConfigFromUserEnhanced;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return {
|
|
171
|
+
...configFromCli,
|
|
172
|
+
configFile: configFromCli?.configFile || config.configFile,
|
|
173
|
+
root: config.root,
|
|
174
|
+
build: {
|
|
175
|
+
...configFromCli?.build,
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.pluginBuildConfig = pluginBuildConfig;
|
|
7
4
|
exports.assertRollupInput = assertRollupInput;
|
|
8
5
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
9
|
-
exports.pluginAutoFullBuild = pluginAutoFullBuild;
|
|
10
|
-
exports.isPrerenderForceExit = isPrerenderForceExit;
|
|
11
6
|
const utils_js_1 = require("../../utils.js");
|
|
12
7
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
13
8
|
const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
|
|
@@ -19,16 +14,6 @@ const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/ge
|
|
|
19
14
|
const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
|
|
20
15
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
21
16
|
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
|
-
});
|
|
32
17
|
function pluginBuildConfig() {
|
|
33
18
|
let config;
|
|
34
19
|
return [
|
|
@@ -51,9 +36,9 @@ function pluginBuildConfig() {
|
|
|
51
36
|
},
|
|
52
37
|
config: {
|
|
53
38
|
order: 'post',
|
|
54
|
-
async handler(
|
|
39
|
+
async handler() {
|
|
55
40
|
(0, utils_js_1.onSetupBuild)();
|
|
56
|
-
const build = await (0, handleAssetsManifest_js_1.handleAssetsManifest_getBuildConfig)(
|
|
41
|
+
const build = await (0, handleAssetsManifest_js_1.handleAssetsManifest_getBuildConfig)();
|
|
57
42
|
return { build };
|
|
58
43
|
},
|
|
59
44
|
},
|
|
@@ -69,7 +54,7 @@ async function getEntries(config) {
|
|
|
69
54
|
// TO-DO/next-major-release: remove
|
|
70
55
|
const pageFileEntries = await getPageFileEntries(config, (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config));
|
|
71
56
|
(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');
|
|
72
|
-
if ((0, isViteServerSide_js_1.
|
|
57
|
+
if ((0, isViteServerSide_js_1.isViteServerSide_viteEnvOptional)(config)) {
|
|
73
58
|
const pageEntries = getPageEntries(pageConfigs);
|
|
74
59
|
const entries = {
|
|
75
60
|
...pageFileEntries,
|
|
@@ -142,7 +127,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
142
127
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
143
128
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
144
129
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
145
|
-
const isForClientSide = !(0, isViteServerSide_js_1.
|
|
130
|
+
const isForClientSide = !(0, isViteServerSide_js_1.isViteServerSide_viteEnvOptional)(config);
|
|
146
131
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
147
132
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
148
133
|
fileTypes.push('.page.server');
|
|
@@ -233,108 +218,3 @@ function assertRollupInput(config) {
|
|
|
233
218
|
const htmlInput = htmlInputs[0];
|
|
234
219
|
(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`);
|
|
235
220
|
}
|
|
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
|
-
}
|
|
@@ -18,7 +18,7 @@ function pluginModuleBanner() {
|
|
|
18
18
|
transform: {
|
|
19
19
|
order: 'post',
|
|
20
20
|
handler(code, id, options) {
|
|
21
|
-
if (!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
21
|
+
if (!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options) &&
|
|
22
22
|
// Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
|
|
23
23
|
config.build.minify) {
|
|
24
24
|
return;
|
|
@@ -12,7 +12,6 @@ function pluginBuild() {
|
|
|
12
12
|
return [
|
|
13
13
|
...(0, pluginBuildConfig_js_1.pluginBuildConfig)(),
|
|
14
14
|
...(0, pluginBuildApp_js_1.pluginBuildApp)(),
|
|
15
|
-
...(0, pluginBuildConfig_js_1.pluginAutoFullBuild)(),
|
|
16
15
|
...(0, pluginBuildEntry_js_1.pluginBuildEntry)(),
|
|
17
16
|
(0, pluginDistPackageJsonFile_js_1.pluginDistPackageJsonFile)(),
|
|
18
17
|
(0, pluginSuppressRollupWarning_js_1.pluginSuppressRollupWarning)(),
|
|
@@ -38,7 +38,7 @@ function pluginEnvVars() {
|
|
|
38
38
|
if (!code.includes('({}).'))
|
|
39
39
|
return;
|
|
40
40
|
const isBuild = config.command === 'build';
|
|
41
|
-
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
41
|
+
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
42
42
|
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
43
43
|
// Find & check
|
|
44
44
|
const replacements = Object.entries(envsAll)
|
|
@@ -47,7 +47,7 @@ function pluginExtractAssets() {
|
|
|
47
47
|
}
|
|
48
48
|
const includeAssetsImportedByServer = (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config);
|
|
49
49
|
(0, utils_js_1.assert)(includeAssetsImportedByServer);
|
|
50
|
-
(0, utils_js_1.assert)(!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
50
|
+
(0, utils_js_1.assert)(!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options));
|
|
51
51
|
const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
|
|
52
52
|
const moduleNames = getImportedModules(importStatements);
|
|
53
53
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
@@ -64,7 +64,7 @@ function pluginExtractAssets() {
|
|
|
64
64
|
// - Vite's `vite:resolve` plugin; https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
65
65
|
enforce: 'pre',
|
|
66
66
|
async resolveId(source, importer, options) {
|
|
67
|
-
if ((0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
67
|
+
if ((0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options)) {
|
|
68
68
|
// When building for the server, there should never be a `?extractAssets` query
|
|
69
69
|
(0, utils_js_1.assert)(!extractAssetsRE.test(source));
|
|
70
70
|
(0, utils_js_1.assert)(importer === undefined || !extractAssetsRE.test(importer));
|
|
@@ -141,7 +141,7 @@ function pluginExtractAssets() {
|
|
|
141
141
|
async configResolved(config_) {
|
|
142
142
|
config = config_;
|
|
143
143
|
vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
144
|
-
isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(
|
|
144
|
+
isFixEnabled = (0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)();
|
|
145
145
|
if (!isFixEnabled) {
|
|
146
146
|
// https://github.com/vikejs/vike/issues/1060
|
|
147
147
|
(0, utils_js_1.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');
|
|
@@ -19,7 +19,7 @@ function pluginExtractExportNames() {
|
|
|
19
19
|
enforce: 'post',
|
|
20
20
|
async transform(src, id, options) {
|
|
21
21
|
id = (0, normalizeId_js_1.normalizeId)(id);
|
|
22
|
-
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
22
|
+
const isClientSide = !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
23
23
|
if (extractExportNamesRE.test(id)) {
|
|
24
24
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
25
25
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
@@ -34,7 +34,7 @@ function pluginFileEnv() {
|
|
|
34
34
|
const importers = Array.from(moduleInfo.importers)
|
|
35
35
|
.map((m) => m.id)
|
|
36
36
|
.filter((id) => id !== null);
|
|
37
|
-
assertFileEnv(id, (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
37
|
+
assertFileEnv(id, (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options), importers,
|
|
38
38
|
// 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).
|
|
39
39
|
true);
|
|
40
40
|
},
|
|
@@ -46,7 +46,7 @@ function pluginFileEnv() {
|
|
|
46
46
|
return;
|
|
47
47
|
if (skip(id))
|
|
48
48
|
return;
|
|
49
|
-
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
49
|
+
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options);
|
|
50
50
|
if (!isWrongEnv(id, isServerSide))
|
|
51
51
|
return;
|
|
52
52
|
const { importers } = this.getModuleInfo(id);
|
|
@@ -35,7 +35,7 @@ function pluginReplaceConstants() {
|
|
|
35
35
|
const constantsMap = [];
|
|
36
36
|
constantsMap.push({
|
|
37
37
|
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
38
|
-
replacement: !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
38
|
+
replacement: !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options),
|
|
39
39
|
});
|
|
40
40
|
constantsMap.forEach(({ constants, replacement }) => {
|
|
41
41
|
if (!constants.some((c) => code.includes(c)))
|
package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js
CHANGED
|
@@ -18,7 +18,7 @@ async function generateVirtualFileGlobalEntryWithOldDesign(id, options, config,
|
|
|
18
18
|
const idParsed = (0, virtualFileId_js_1.parseVirtualFileId)(id);
|
|
19
19
|
(0, utils_js_1.assert)(idParsed && idParsed.type === 'global-entry');
|
|
20
20
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
21
|
-
(0, utils_js_1.assert)(isForClientSide === !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config,
|
|
21
|
+
(0, utils_js_1.assert)(isForClientSide === !(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, env, options));
|
|
22
22
|
const code = await getCode(config, isForClientSide, isClientRouting, isDev, id);
|
|
23
23
|
return code;
|
|
24
24
|
}
|
|
@@ -10,7 +10,7 @@ const serializeConfigValues_js_1 = require("../../../../shared/page-configs/seri
|
|
|
10
10
|
const handleAssetsManifest_js_1 = require("../pluginBuild/handleAssetsManifest.js");
|
|
11
11
|
const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
12
12
|
const retrievePageAssetsProd_js_1 = require("../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js");
|
|
13
|
-
async function generateVirtualFilePageEntry(id, isDev
|
|
13
|
+
async function generateVirtualFilePageEntry(id, isDev) {
|
|
14
14
|
const result = (0, virtualFileId_js_1.parseVirtualFileId)(id);
|
|
15
15
|
(0, utils_js_1.assert)(result && result.type === 'page-entry');
|
|
16
16
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -34,11 +34,11 @@ async function generateVirtualFilePageEntry(id, isDev, config) {
|
|
|
34
34
|
throw (0, utils_js_1.getProjectError)('Outdated request');
|
|
35
35
|
//*/
|
|
36
36
|
}
|
|
37
|
-
const code = getCode(pageConfig, isForClientSide, pageId, (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config),
|
|
37
|
+
const code = getCode(pageConfig, isForClientSide, pageId, (0, retrievePageAssetsProd_js_1.resolveIncludeAssetsImportedByServer)(vikeConfig.config), isDev);
|
|
38
38
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
39
39
|
return code;
|
|
40
40
|
}
|
|
41
|
-
function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer,
|
|
41
|
+
function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
42
42
|
const lines = [];
|
|
43
43
|
const importStatements = [];
|
|
44
44
|
const filesEnv = new Map();
|
|
@@ -46,7 +46,7 @@ function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedBySer
|
|
|
46
46
|
lines.push('export const configValuesSerialized = {');
|
|
47
47
|
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
|
|
48
48
|
lines.push('};');
|
|
49
|
-
if (!(0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(
|
|
49
|
+
if (!(0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
50
50
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFileId_js_1.generateVirtualFileId)({ type: 'page-entry', pageId, isForClientSide: false }))}'`);
|
|
51
51
|
}
|
|
52
52
|
const code = [...importStatements, ...lines].join('\n');
|
|
@@ -51,7 +51,7 @@ function pluginVirtualFiles() {
|
|
|
51
51
|
const idParsed = (0, virtualFileId_js_1.parseVirtualFileId)(id);
|
|
52
52
|
if (idParsed) {
|
|
53
53
|
if (idParsed.type === 'page-entry') {
|
|
54
|
-
const code = await (0, generateVirtualFilePageEntry_js_1.generateVirtualFilePageEntry)(id, isDev
|
|
54
|
+
const code = await (0, generateVirtualFilePageEntry_js_1.generateVirtualFilePageEntry)(id, isDev);
|
|
55
55
|
return code;
|
|
56
56
|
}
|
|
57
57
|
if (idParsed.type === 'global-entry') {
|
|
@@ -21,13 +21,9 @@ function getOutDirs(configGlobal, viteEnv) {
|
|
|
21
21
|
}
|
|
22
22
|
/** Appends `client/` or `server/` to `config.build.outDir` */
|
|
23
23
|
function resolveOutDir(config, isServerSide) {
|
|
24
|
-
debug('resolveOutDir()'
|
|
25
|
-
debug('isServerSide', isServerSide);
|
|
24
|
+
debug('resolveOutDir()');
|
|
26
25
|
const outDir = getOutDirFromViteUserConfig(config) || 'dist';
|
|
27
26
|
debug('outDir', outDir);
|
|
28
|
-
/* outDir may already be resolved when using Telefunc + Vike (because both Telefunc and Vike use this logic)
|
|
29
|
-
assert(isOutDirRoot(outDir))
|
|
30
|
-
*/
|
|
31
27
|
const { outDirClient, outDirServer } = getOutDirsAll(outDir);
|
|
32
28
|
if (isServerSide) {
|
|
33
29
|
debug('outDirServer', 'outDirServer');
|
|
@@ -112,7 +108,7 @@ function assertOutDirResolved(outDir, configGlobal, viteEnv) {
|
|
|
112
108
|
(0, utils_js_1.assert)('/client'.length === '/server'.length);
|
|
113
109
|
const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
|
|
114
110
|
const wrongUsage = `You've set Vite's config.build.outDir to ${picocolors_1.default.cyan(outDir)} but you should set it to ${picocolors_1.default.cyan(outDirCorrected)} instead.`;
|
|
115
|
-
const isServerSide = (0, isViteServerSide_js_1.
|
|
111
|
+
const isServerSide = (0, isViteServerSide_js_1.isViteServerSide_viteEnvOptional)(configGlobal, viteEnv);
|
|
116
112
|
if (isServerSide) {
|
|
117
113
|
(0, utils_js_1.assertUsage)(outDir.endsWith('/server'), wrongUsage);
|
|
118
114
|
}
|