vike 0.4.237-commit-fd8294f → 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 +2 -2
- package/dist/cjs/node/api/prepareViteApiCall.js +0 -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 -18
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild.js +0 -2
- 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/pluginPreview.js +1 -11
- 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 -13
- 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 +2 -2
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -2
- package/dist/esm/node/api/prepareViteApiCall.js +0 -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.js +5 -19
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild.js +0 -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/pluginPreview.js +3 -13
- 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 +2 -4
- package/dist/esm/node/vite/shared/getOutDirs.js +3 -14
- 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
- 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
|
@@ -8,11 +8,11 @@ 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);
|
|
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
|
};
|
|
@@ -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
|
+
}
|
|
@@ -9,13 +9,11 @@ import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
|
9
9
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
10
10
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
11
11
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
12
|
-
import {
|
|
13
|
-
import { resolveOutDir_configEnvironment } from '../../shared/getOutDirs.js';
|
|
12
|
+
import { isViteServerSide_viteEnvOptional } from '../../shared/isViteServerSide.js';
|
|
14
13
|
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
|
|
15
14
|
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
16
15
|
function pluginBuildConfig() {
|
|
17
16
|
let config;
|
|
18
|
-
let configUnresolved;
|
|
19
17
|
return [
|
|
20
18
|
{
|
|
21
19
|
name: 'vike:build:pluginBuildConfig',
|
|
@@ -34,23 +32,11 @@ function pluginBuildConfig() {
|
|
|
34
32
|
handleAssetsManifest_assertUsageCssCodeSplit(config);
|
|
35
33
|
},
|
|
36
34
|
},
|
|
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
35
|
config: {
|
|
49
36
|
order: 'post',
|
|
50
|
-
async handler(
|
|
51
|
-
configUnresolved = config;
|
|
37
|
+
async handler() {
|
|
52
38
|
onSetupBuild();
|
|
53
|
-
const build = await handleAssetsManifest_getBuildConfig(
|
|
39
|
+
const build = await handleAssetsManifest_getBuildConfig();
|
|
54
40
|
return { build };
|
|
55
41
|
},
|
|
56
42
|
},
|
|
@@ -66,7 +52,7 @@ async function getEntries(config) {
|
|
|
66
52
|
// TO-DO/next-major-release: remove
|
|
67
53
|
const pageFileEntries = await getPageFileEntries(config, resolveIncludeAssetsImportedByServer(vikeConfig.config));
|
|
68
54
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
69
|
-
if (
|
|
55
|
+
if (isViteServerSide_viteEnvOptional(config)) {
|
|
70
56
|
const pageEntries = getPageEntries(pageConfigs);
|
|
71
57
|
const entries = {
|
|
72
58
|
...pageFileEntries,
|
|
@@ -139,7 +125,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
139
125
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
140
126
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
141
127
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
142
|
-
const isForClientSide = !
|
|
128
|
+
const isForClientSide = !isViteServerSide_viteEnvOptional(config);
|
|
143
129
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
144
130
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
145
131
|
fileTypes.push('.page.server');
|
|
@@ -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;
|
|
@@ -3,7 +3,6 @@ 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
7
|
import { pluginBuildConfig } from './pluginBuild/pluginBuildConfig.js';
|
|
9
8
|
import { pluginModuleBanner } from './pluginBuild/pluginModuleBanner.js';
|
|
@@ -11,7 +10,6 @@ function pluginBuild() {
|
|
|
11
10
|
return [
|
|
12
11
|
...pluginBuildConfig(),
|
|
13
12
|
...pluginBuildApp(),
|
|
14
|
-
...pluginAutoFullBuild(),
|
|
15
13
|
...pluginBuildEntry(),
|
|
16
14
|
pluginDistPackageJsonFile(),
|
|
17
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);
|
|
@@ -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();
|
|
@@ -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)))
|
package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js
CHANGED
|
@@ -13,7 +13,7 @@ async function generateVirtualFileGlobalEntryWithOldDesign(id, options, config,
|
|
|
13
13
|
const idParsed = parseVirtualFileId(id);
|
|
14
14
|
assert(idParsed && idParsed.type === 'global-entry');
|
|
15
15
|
const { isForClientSide, isClientRouting } = idParsed;
|
|
16
|
-
assert(isForClientSide === !isViteServerSide_extraSafe(config,
|
|
16
|
+
assert(isForClientSide === !isViteServerSide_extraSafe(config, env, options));
|
|
17
17
|
const code = await getCode(config, isForClientSide, isClientRouting, isDev, id);
|
|
18
18
|
return code;
|
|
19
19
|
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { generateVirtualFilePageEntry };
|
|
2
|
-
|
|
3
|
-
declare function generateVirtualFilePageEntry(id: string, isDev: boolean, config: ResolvedConfig): Promise<string>;
|
|
2
|
+
declare function generateVirtualFilePageEntry(id: string, isDev: boolean): Promise<string>;
|
|
@@ -8,7 +8,7 @@ import { serializeConfigValues } from '../../../../shared/page-configs/serialize
|
|
|
8
8
|
import { handleAssetsManifest_isFixEnabled } from '../pluginBuild/handleAssetsManifest.js';
|
|
9
9
|
import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
10
10
|
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
11
|
-
async function generateVirtualFilePageEntry(id, isDev
|
|
11
|
+
async function generateVirtualFilePageEntry(id, isDev) {
|
|
12
12
|
const result = parseVirtualFileId(id);
|
|
13
13
|
assert(result && result.type === 'page-entry');
|
|
14
14
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -32,11 +32,11 @@ async function generateVirtualFilePageEntry(id, isDev, config) {
|
|
|
32
32
|
throw getProjectError('Outdated request');
|
|
33
33
|
//*/
|
|
34
34
|
}
|
|
35
|
-
const code = getCode(pageConfig, isForClientSide, pageId, resolveIncludeAssetsImportedByServer(vikeConfig.config),
|
|
35
|
+
const code = getCode(pageConfig, isForClientSide, pageId, resolveIncludeAssetsImportedByServer(vikeConfig.config), isDev);
|
|
36
36
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
37
37
|
return code;
|
|
38
38
|
}
|
|
39
|
-
function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer,
|
|
39
|
+
function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
40
40
|
const lines = [];
|
|
41
41
|
const importStatements = [];
|
|
42
42
|
const filesEnv = new Map();
|
|
@@ -44,7 +44,7 @@ function getCode(pageConfig, isForClientSide, pageId, includeAssetsImportedBySer
|
|
|
44
44
|
lines.push('export const configValuesSerialized = {');
|
|
45
45
|
lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
|
|
46
46
|
lines.push('};');
|
|
47
|
-
if (!handleAssetsManifest_isFixEnabled(
|
|
47
|
+
if (!handleAssetsManifest_isFixEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
48
48
|
importStatements.push(`import '${extractAssetsAddQuery(generateVirtualFileId({ type: 'page-entry', pageId, isForClientSide: false }))}'`);
|
|
49
49
|
}
|
|
50
50
|
const code = [...importStatements, ...lines].join('\n');
|
|
@@ -46,7 +46,7 @@ function pluginVirtualFiles() {
|
|
|
46
46
|
const idParsed = parseVirtualFileId(id);
|
|
47
47
|
if (idParsed) {
|
|
48
48
|
if (idParsed.type === 'page-entry') {
|
|
49
|
-
const code = await generateVirtualFilePageEntry(id, isDev
|
|
49
|
+
const code = await generateVirtualFilePageEntry(id, isDev);
|
|
50
50
|
return code;
|
|
51
51
|
}
|
|
52
52
|
if (idParsed.type === 'global-entry') {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { getOutDirs };
|
|
2
2
|
export { resolveOutDir };
|
|
3
|
-
export { resolveOutDir_configEnvironment };
|
|
4
3
|
export type { OutDirs };
|
|
5
|
-
import type { UserConfig, ResolvedConfig
|
|
6
|
-
import { ViteEnv } from './isViteServerSide.js';
|
|
4
|
+
import type { UserConfig, ResolvedConfig } from 'vite';
|
|
5
|
+
import { type ViteEnv } from './isViteServerSide.js';
|
|
7
6
|
type OutDirs = {
|
|
8
7
|
/** Absolute path to `outDir` */
|
|
9
8
|
outDirRoot: string;
|
|
@@ -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_viteEnvOptional } from './isViteServerSide.js';
|
|
7
6
|
const debug = createDebugger('vike:outDir');
|
|
8
7
|
function getOutDirs(configGlobal, viteEnv) {
|
|
9
8
|
debug('getOutDirs()', new Error().stack);
|
|
@@ -15,21 +14,11 @@ 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
|
-
debug('resolveOutDir()'
|
|
27
|
-
debug('isServerSide', isServerSide);
|
|
19
|
+
debug('resolveOutDir()');
|
|
28
20
|
const outDir = getOutDirFromViteUserConfig(config) || 'dist';
|
|
29
21
|
debug('outDir', outDir);
|
|
30
|
-
/* outDir may already be resolved when using Telefunc + Vike (because both Telefunc and Vike use this logic)
|
|
31
|
-
assert(isOutDirRoot(outDir))
|
|
32
|
-
*/
|
|
33
22
|
const { outDirClient, outDirServer } = getOutDirsAll(outDir);
|
|
34
23
|
if (isServerSide) {
|
|
35
24
|
debug('outDirServer', 'outDirServer');
|
|
@@ -114,7 +103,7 @@ function assertOutDirResolved(outDir, configGlobal, viteEnv) {
|
|
|
114
103
|
assert('/client'.length === '/server'.length);
|
|
115
104
|
const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
|
|
116
105
|
const wrongUsage = `You've set Vite's config.build.outDir to ${pc.cyan(outDir)} but you should set it to ${pc.cyan(outDirCorrected)} instead.`;
|
|
117
|
-
const isServerSide =
|
|
106
|
+
const isServerSide = isViteServerSide_viteEnvOptional(configGlobal, viteEnv);
|
|
118
107
|
if (isServerSide) {
|
|
119
108
|
assertUsage(outDir.endsWith('/server'), wrongUsage);
|
|
120
109
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { isViteServerSide };
|
|
2
2
|
export { isViteClientSide };
|
|
3
|
-
export {
|
|
3
|
+
export { isViteServerSide_viteEnvOptional };
|
|
4
4
|
export { isViteServerSide_onlySsrEnv };
|
|
5
5
|
export { isViteServerSide_extraSafe };
|
|
6
6
|
export type { ViteEnv };
|
|
@@ -10,9 +10,9 @@ type ViteEnv = {
|
|
|
10
10
|
config: EnvironmentOptions | Environment['config'];
|
|
11
11
|
};
|
|
12
12
|
declare function isViteServerSide(configGlobal: ResolvedConfig | UserConfig, viteEnv: ViteEnv): boolean;
|
|
13
|
-
declare function
|
|
13
|
+
declare function isViteServerSide_viteEnvOptional(configGlobal: ResolvedConfig | UserConfig, viteEnv?: ViteEnv | undefined): boolean;
|
|
14
14
|
declare function isViteClientSide(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
|
|
15
15
|
declare function isViteServerSide_onlySsrEnv(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
|
|
16
|
-
declare function isViteServerSide_extraSafe(config: ResolvedConfig, options: {
|
|
16
|
+
declare function isViteServerSide_extraSafe(config: ResolvedConfig, viteEnv: ViteEnv, options: {
|
|
17
17
|
ssr?: boolean;
|
|
18
|
-
} | undefined
|
|
18
|
+
} | undefined): boolean;
|