vike 0.4.267-commit-b005535 → 0.4.267-commit-7884d91
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/client/runtime-client-routing/createPageContextClient.d.ts +4 -0
- package/dist/client/runtime-client-routing/getGlobalContextClientInternal.d.ts +4 -0
- package/dist/client/runtime-client-routing/getPageContextFromHooks.d.ts +22 -2
- package/dist/client/runtime-client-routing/getPageContextFromHooks.js +4 -5
- package/dist/client/runtime-client-routing/renderPageClient.d.ts +472 -9
- package/dist/client/runtime-client-routing/renderPageClient.js +11 -5
- package/dist/client/runtime-client-routing/streamedValues.d.ts +5 -0
- package/dist/client/runtime-client-routing/streamedValues.js +23 -0
- package/dist/client/runtime-server-routing/createPageContextClient.d.ts +4 -0
- package/dist/client/runtime-server-routing/entry.js +1 -1
- package/dist/client/runtime-server-routing/getGlobalContextClientInternal.d.ts +4 -0
- package/dist/client/shared/getGlobalContextClientInternalShared.d.ts +4 -0
- package/dist/client/shared/getJsonSerializedInHtml.d.ts +2 -2
- package/dist/client/shared/getJsonSerializedInHtml.js +9 -6
- package/dist/client/shared/streamedValues/asyncIterable.d.ts +4 -0
- package/dist/client/shared/streamedValues/asyncIterable.js +26 -0
- package/dist/client/shared/streamedValues/lines.d.ts +11 -0
- package/dist/client/shared/streamedValues/lines.js +19 -0
- package/dist/client/shared/streamedValues/promise.d.ts +4 -0
- package/dist/client/shared/streamedValues/promise.js +19 -0
- package/dist/client/shared/streamedValues/readableStream.d.ts +4 -0
- package/dist/client/shared/streamedValues/readableStream.js +44 -0
- package/dist/client/shared/streamedValues/registry.d.ts +21 -0
- package/dist/client/shared/streamedValues/registry.js +40 -0
- package/dist/client/shared/streamedValues.d.ts +7 -0
- package/dist/client/shared/streamedValues.js +82 -0
- package/dist/node/api/resolveViteConfigUser.js +2 -2
- package/dist/node/prerender/runPrerender.d.ts +12 -4
- package/dist/node/prerender/runPrerender.js +60 -15
- package/dist/node/vite/assertEnvVite.js +1 -1
- package/dist/node/vite/index.js +2 -0
- package/dist/node/vite/plugins/build/handleAssetsManifest.js +6 -2
- package/dist/node/vite/plugins/build/pluginBuildApp.js +25 -26
- package/dist/node/vite/plugins/build/pluginBuildConfig.d.ts +2 -2
- package/dist/node/vite/plugins/build/pluginBuildConfig.js +24 -16
- package/dist/node/vite/plugins/build/pluginDistFileNames.js +70 -50
- package/dist/node/vite/plugins/build/pluginEnvironmentEntries.d.ts +6 -0
- package/dist/node/vite/plugins/build/pluginEnvironmentEntries.js +71 -0
- package/dist/node/vite/plugins/build/pluginSuppressRollupWarning.js +19 -17
- package/dist/node/vite/plugins/pluginCommon.js +9 -6
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +1 -1
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +6 -4
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -1
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +29 -12
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +3 -2
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +7 -7
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +7 -5
- package/dist/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +4 -10
- package/dist/node/vite/plugins/pluginVirtualFiles.js +20 -0
- package/dist/node/vite/shared/addSsrMiddleware.js +13 -1
- package/dist/node/vite/shared/getAssetsDir.d.ts +3 -2
- package/dist/node/vite/shared/getAssetsDir.js +3 -3
- package/dist/node/vite/shared/isViteCli.d.ts +3 -3
- package/dist/node/vite/shared/isViteCli.js +80 -84
- package/dist/node/vite/shared/isViteServerSide.js +2 -7
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.d.ts +1 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal/metaBuiltIn.js +8 -6
- package/dist/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -1
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +82 -11
- package/dist/server/runtime/globalContext.d.ts +20 -0
- package/dist/server/runtime/renderPageServer/analyzePage.js +3 -3
- package/dist/server/runtime/renderPageServer/createHttpResponse.d.ts +20 -7
- package/dist/server/runtime/renderPageServer/createHttpResponse.js +34 -15
- package/dist/server/runtime/renderPageServer/createPageContextServer.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/execHookOnError.js +1 -1
- package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.d.ts +9 -0
- package/dist/server/runtime/renderPageServer/execHookOnRenderHtml.js +17 -5
- package/dist/server/runtime/renderPageServer/getHttpResponseBody.d.ts +2 -2
- package/dist/server/runtime/renderPageServer/getHttpResponseBody.js +17 -2
- package/dist/server/runtime/renderPageServer/getPageContextJson.d.ts +8 -0
- package/dist/server/runtime/renderPageServer/getPageContextJson.js +47 -0
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.d.ts +2 -0
- package/dist/server/runtime/renderPageServer/handleErrorWithoutErrorPage.js +1 -1
- package/dist/server/runtime/renderPageServer/headersResponse.d.ts +11 -2
- package/dist/server/runtime/renderPageServer/headersResponse.js +20 -1
- package/dist/server/runtime/renderPageServer/html/injectAssets/getHtmlTags.js +5 -4
- package/dist/server/runtime/renderPageServer/html/injectAssets.d.ts +3 -2
- package/dist/server/runtime/renderPageServer/html/injectAssets.js +7 -1
- package/dist/server/runtime/renderPageServer/html/renderHtml.js +4 -2
- package/dist/server/runtime/renderPageServer/html/serializeContext.d.ts +5 -1
- package/dist/server/runtime/renderPageServer/html/serializeContext.js +12 -9
- package/dist/server/runtime/renderPageServer/html/stream.d.ts +13 -6
- package/dist/server/runtime/renderPageServer/html/stream.js +121 -31
- package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.d.ts +30 -0
- package/dist/server/runtime/renderPageServer/html/streamedValuesHtml.js +92 -0
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/loadPageConfigsLazyServerSide.js +5 -1
- package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.d.ts +15 -0
- package/dist/server/runtime/renderPageServer/loadPageContextEnvironments.js +61 -0
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.d.ts +314 -1
- package/dist/server/runtime/renderPageServer/renderPageServerAfterRoute.js +21 -12
- package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/asyncIterable.js +12 -0
- package/dist/server/runtime/renderPageServer/streamedValues/lines.d.ts +10 -0
- package/dist/server/runtime/renderPageServer/streamedValues/lines.js +49 -0
- package/dist/server/runtime/renderPageServer/streamedValues/promise.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/promise.js +14 -0
- package/dist/server/runtime/renderPageServer/streamedValues/pump.d.ts +10 -0
- package/dist/server/runtime/renderPageServer/streamedValues/pump.js +67 -0
- package/dist/server/runtime/renderPageServer/streamedValues/readableStream.d.ts +4 -0
- package/dist/server/runtime/renderPageServer/streamedValues/readableStream.js +12 -0
- package/dist/server/runtime/renderPageServer/streamedValues/registry.d.ts +28 -0
- package/dist/server/runtime/renderPageServer/streamedValues/registry.js +33 -0
- package/dist/server/runtime/renderPageServer.d.ts +4 -0
- package/dist/server/runtime/renderPageServer.js +17 -8
- package/dist/shared-server-client/createGlobalContextShared.d.ts +8 -0
- package/dist/shared-server-client/createGlobalContextShared.js +2 -1
- package/dist/shared-server-client/getPageContextPublicShared.js +0 -2
- package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.d.ts +8 -0
- package/dist/shared-server-client/getPageFiles/parseVirtualFileExportsGlobalEntry.js +17 -7
- package/dist/shared-server-client/hooks/execHook.d.ts +1 -1
- package/dist/shared-server-client/hooks/execHook.js +2 -2
- package/dist/shared-server-client/route/abort.d.ts +1 -1
- package/dist/shared-server-client/route/abort.js +4 -2
- package/dist/shared-server-client/streamedValues.d.ts +22 -0
- package/dist/shared-server-client/streamedValues.js +24 -0
- package/dist/shared-server-node/vike-environments.d.ts +4 -0
- package/dist/shared-server-node/vike-environments.js +10 -0
- package/dist/shared-server-node/virtualFileId.d.ts +7 -5
- package/dist/shared-server-node/virtualFileId.js +42 -42
- package/dist/types/Config.d.ts +1 -1
- package/dist/types/PageConfig.d.ts +13 -5
- package/dist/types/PageContext.d.ts +18 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assertViteVersion.d.ts +1 -3
- package/dist/utils/assertViteVersion.js +6 -9
- package/dist/utils/deepEqual.d.ts +2 -1
- package/dist/utils/deepEqual.js +21 -6
- package/dist/utils/getContentTypeFromUrl.d.ts +2 -0
- package/dist/utils/getContentTypeFromUrl.js +39 -0
- package/dist/utils/injectRollupInputs.d.ts +2 -2
- package/dist/utils/injectRollupInputs.js +2 -2
- package/dist/utils/isDev.js +2 -7
- package/dist/utils/parseUrl-extras.js +4 -0
- package/package.json +6 -6
- package/dist/shared-server-client/addIs404ToPageProps.d.ts +0 -2
- package/dist/shared-server-client/addIs404ToPageProps.js +0 -17
|
@@ -5,14 +5,12 @@ import { assert, assertWarning } from '../../../../utils/assert.js';
|
|
|
5
5
|
import { onSetupBuild } from '../../../../utils/assertSetup.js';
|
|
6
6
|
import { getGlobalObject } from '../../../../utils/getGlobalObject.js';
|
|
7
7
|
import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/context.js';
|
|
8
|
-
import { isViteCli,
|
|
8
|
+
import { isViteCli, getViteCliArgs } from '../../shared/isViteCli.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
11
11
|
import { isVikeCliOrApi } from '../../../../shared-server-node/api-context.js';
|
|
12
12
|
import { handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget } from './handleAssetsManifest.js';
|
|
13
|
-
import { isViteServerSide_onlySsrEnv } from '../../shared/isViteServerSide.js';
|
|
14
13
|
import { runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
|
|
15
|
-
import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
|
|
16
14
|
import { logErrorServer } from '../../../../server/runtime/logErrorServer.js';
|
|
17
15
|
import '../../assertEnvVite.js';
|
|
18
16
|
const globalObject = getGlobalObject('build/pluginBuildApp.ts', {
|
|
@@ -20,7 +18,6 @@ const globalObject = getGlobalObject('build/pluginBuildApp.ts', {
|
|
|
20
18
|
});
|
|
21
19
|
function pluginBuildApp() {
|
|
22
20
|
let config;
|
|
23
|
-
let alreadyBuilt = false;
|
|
24
21
|
return [
|
|
25
22
|
{
|
|
26
23
|
name: 'vike:build:pluginBuildApp:pre',
|
|
@@ -33,18 +30,15 @@ function pluginBuildApp() {
|
|
|
33
30
|
builder: {
|
|
34
31
|
// Can be overridden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
35
32
|
async buildApp(builder) {
|
|
36
|
-
if (alreadyBuilt)
|
|
37
|
-
return;
|
|
38
|
-
alreadyBuilt = true;
|
|
39
33
|
assert(builder.environments.client);
|
|
40
34
|
assert(builder.environments.ssr);
|
|
35
|
+
// The additional environments (e.g. `rsc`)
|
|
36
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
37
|
+
for (const name of additionalEnvironmentNames) {
|
|
38
|
+
await builder.build(builder.environments[name]);
|
|
39
|
+
}
|
|
41
40
|
await builder.build(builder.environments.client);
|
|
42
41
|
await builder.build(builder.environments.ssr);
|
|
43
|
-
if (isPrerenderForceExit()) {
|
|
44
|
-
await builder.buildApp();
|
|
45
|
-
runPrerender_forceExit();
|
|
46
|
-
assert(false);
|
|
47
|
-
}
|
|
48
42
|
},
|
|
49
43
|
},
|
|
50
44
|
};
|
|
@@ -88,8 +82,14 @@ function pluginBuildApp() {
|
|
|
88
82
|
await abortViteBuildSsr();
|
|
89
83
|
},
|
|
90
84
|
},
|
|
91
|
-
//
|
|
92
|
-
// -
|
|
85
|
+
// Pre-render after all builds, e.g. after @vitejs/plugin-rsc moved its `rsc` build back into dist/server/
|
|
86
|
+
// - Before the `order: 'post'` buildApp() hooks of non-`enforce: 'pre'` plugins, e.g. vite-plugin-vercel copies dist/client/
|
|
87
|
+
buildApp: {
|
|
88
|
+
order: 'post',
|
|
89
|
+
async handler(builder) {
|
|
90
|
+
await triggerPrerendering(builder.config);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
93
|
writeBundle: {
|
|
94
94
|
/* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
|
|
95
95
|
sequential: true,
|
|
@@ -99,7 +99,6 @@ function pluginBuildApp() {
|
|
|
99
99
|
try {
|
|
100
100
|
handleAssetsManifest_assertUsageCssTarget(config, this.environment);
|
|
101
101
|
await handleAssetsManifest(config, this.environment, options, bundle);
|
|
102
|
-
await triggerPrerendering(config, this.environment, bundle);
|
|
103
102
|
}
|
|
104
103
|
catch (err) {
|
|
105
104
|
// We use try-catch also because:
|
|
@@ -115,6 +114,14 @@ function pluginBuildApp() {
|
|
|
115
114
|
name: 'vike:build:pluginBuildApp:autoFullBuild:post',
|
|
116
115
|
apply: 'build',
|
|
117
116
|
enforce: 'post',
|
|
117
|
+
// After the buildApp() hooks of other plugins, e.g. vite-plugin-vercel
|
|
118
|
+
buildApp: {
|
|
119
|
+
order: 'post',
|
|
120
|
+
async handler() {
|
|
121
|
+
if (isPrerenderForceExit())
|
|
122
|
+
runPrerender_forceExit();
|
|
123
|
+
},
|
|
124
|
+
},
|
|
118
125
|
closeBundle: {
|
|
119
126
|
sequential: true,
|
|
120
127
|
order: 'post',
|
|
@@ -125,18 +132,10 @@ function pluginBuildApp() {
|
|
|
125
132
|
},
|
|
126
133
|
];
|
|
127
134
|
}
|
|
128
|
-
async function triggerPrerendering(config
|
|
135
|
+
async function triggerPrerendering(config) {
|
|
129
136
|
const vikeConfig = await getVikeConfigInternal();
|
|
130
|
-
if (!isViteServerSide_onlySsrEnv(config, viteEnv))
|
|
131
|
-
return;
|
|
132
137
|
if (isDisabled(vikeConfig))
|
|
133
138
|
return;
|
|
134
|
-
// Workaround for @vitejs/plugin-legacy
|
|
135
|
-
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
136
|
-
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
137
|
-
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
138
|
-
if (!bundle[getManifestFilePathRelative(config.build.manifest)])
|
|
139
|
-
return;
|
|
140
139
|
if (!(await isPrerenderAutoRunEnabled(vikeConfig)))
|
|
141
140
|
return;
|
|
142
141
|
const configInline = getFullBuildInlineConfig(config);
|
|
@@ -146,7 +145,7 @@ async function triggerPrerendering(config, viteEnv, bundle) {
|
|
|
146
145
|
}
|
|
147
146
|
async function abortViteBuildSsr() {
|
|
148
147
|
const vikeConfig = await getVikeConfigInternal();
|
|
149
|
-
if (vikeConfig.config.disableAutoFullBuild !== true && isViteCli() &&
|
|
148
|
+
if (vikeConfig.config.disableAutoFullBuild !== true && isViteCli() && getViteCliArgs()?.build.ssr) {
|
|
150
149
|
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 });
|
|
151
150
|
process.exit(0);
|
|
152
151
|
}
|
|
@@ -165,7 +164,7 @@ function isPrerenderForceExit() {
|
|
|
165
164
|
return globalObject.forceExit;
|
|
166
165
|
}
|
|
167
166
|
function getFullBuildInlineConfig(config) {
|
|
168
|
-
const configFromCli = !isViteCli() ? null :
|
|
167
|
+
const configFromCli = !isViteCli() ? null : getViteCliArgs();
|
|
169
168
|
if (config._viteConfigUser) {
|
|
170
169
|
return config._viteConfigUser;
|
|
171
170
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
import type { ResolvedConfig, Plugin } from 'vite';
|
|
4
|
+
import type { ResolvedConfig, Plugin, Rollup } from 'vite';
|
|
5
5
|
import type { PageConfigBuildTime } from '../../../../types/PageConfig.js';
|
|
6
6
|
import type { FilePath } from '../../../../types/FilePath.js';
|
|
7
7
|
import '../../assertEnvVite.js';
|
|
@@ -15,4 +15,4 @@ declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config
|
|
|
15
15
|
hasServerRouting: boolean;
|
|
16
16
|
clientEntries: Record<string, ClientEntry>;
|
|
17
17
|
};
|
|
18
|
-
declare function assertRollupInput(
|
|
18
|
+
declare function assertRollupInput(input: Rollup.InputOption | undefined): void;
|
|
@@ -16,7 +16,7 @@ import { extractAssetsAddQuery } from '../../../../shared-server-node/extractAss
|
|
|
16
16
|
import { prependEntriesDir } from '../../../../shared-server-node/prependEntriesDir.js';
|
|
17
17
|
import { getFilePathResolved, getFilePathUnresolved } from '../../shared/getFilePath.js';
|
|
18
18
|
import { getConfigValueBuildTime } from '../../../../shared-server-client/page-configs/getConfigValueBuildTime.js';
|
|
19
|
-
import {
|
|
19
|
+
import { isViteServerSide_configEnvironment } from '../../shared/isViteServerSide.js';
|
|
20
20
|
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, handleAssetsManifest_alignCssTarget, } from './handleAssetsManifest.js';
|
|
21
21
|
import { resolveIncludeAssetsImportedByServer } from '../../../../server/runtime/renderPageServer/getPageAssets/retrievePageAssetsProd.js';
|
|
22
22
|
import '../../assertEnvVite.js';
|
|
@@ -31,10 +31,18 @@ function pluginBuildConfig() {
|
|
|
31
31
|
async handler(config) {
|
|
32
32
|
handleAssetsManifest_alignCssTarget(config);
|
|
33
33
|
onSetupBuild();
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
35
|
+
const entriesClient = await getEntries(config, false);
|
|
36
|
+
const entriesServer = await getEntries(config, true);
|
|
37
|
+
for (const [envName, envConfig] of Object.entries(config.environments)) {
|
|
38
|
+
// Additional environments (e.g. `rsc`) only get Vike's `entry-environment.mjs`, see pluginEnvironmentEntries.ts
|
|
39
|
+
if (additionalEnvironmentNames.includes(envName))
|
|
40
|
+
continue;
|
|
41
|
+
const entries = isViteServerSide_configEnvironment(envName, envConfig) ? entriesServer : entriesClient;
|
|
42
|
+
assert(Object.keys(entries).length > 0);
|
|
43
|
+
assertRollupInput(envConfig.build.rollupOptions.input);
|
|
44
|
+
envConfig.build.rollupOptions.input = injectRollupInputs(entries, envConfig.build.rollupOptions.input);
|
|
45
|
+
}
|
|
38
46
|
addLogHook();
|
|
39
47
|
handleAssetsManifest_assertUsageCssCodeSplit(config);
|
|
40
48
|
},
|
|
@@ -55,13 +63,13 @@ function pluginBuildConfig() {
|
|
|
55
63
|
},
|
|
56
64
|
];
|
|
57
65
|
}
|
|
58
|
-
async function getEntries(config) {
|
|
66
|
+
async function getEntries(config, isServerSide) {
|
|
59
67
|
const vikeConfig = await getVikeConfigInternal();
|
|
60
68
|
const { _pageConfigs: pageConfigs } = vikeConfig;
|
|
61
69
|
// TO-DO/next-major-release: remove
|
|
62
|
-
const pageFileEntries = await getPageFileEntries(config, resolveIncludeAssetsImportedByServer(vikeConfig.config));
|
|
70
|
+
const pageFileEntries = await getPageFileEntries(config, resolveIncludeAssetsImportedByServer(vikeConfig.config), isServerSide);
|
|
63
71
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
64
|
-
if (
|
|
72
|
+
if (isServerSide) {
|
|
65
73
|
const pageEntries = getPageEntries(pageConfigs);
|
|
66
74
|
const entries = {
|
|
67
75
|
...pageFileEntries,
|
|
@@ -94,7 +102,7 @@ async function getEntries(config) {
|
|
|
94
102
|
function getPageEntries(pageConfigs) {
|
|
95
103
|
const pageEntries = {};
|
|
96
104
|
pageConfigs.forEach((pageConfig) => {
|
|
97
|
-
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig,
|
|
105
|
+
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, 'server');
|
|
98
106
|
pageEntries[entryName] = entryTarget;
|
|
99
107
|
});
|
|
100
108
|
return pageEntries;
|
|
@@ -114,7 +122,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
114
122
|
}
|
|
115
123
|
{
|
|
116
124
|
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
117
|
-
const { entryName, entryTarget, entryFilePath } = getEntryFromPageConfig(pageConfig,
|
|
125
|
+
const { entryName, entryTarget, entryFilePath } = getEntryFromPageConfig(pageConfig, 'client');
|
|
118
126
|
clientEntries[entryName] = { entryTarget, entryFilePath };
|
|
119
127
|
}
|
|
120
128
|
{
|
|
@@ -133,8 +141,8 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
133
141
|
}
|
|
134
142
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
135
143
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
136
|
-
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
137
|
-
const isForClientSide = !
|
|
144
|
+
async function getPageFileEntries(config, includeAssetsImportedByServer, isServerSide) {
|
|
145
|
+
const isForClientSide = !isServerSide;
|
|
138
146
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
139
147
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
140
148
|
fileTypes.push('.page.server');
|
|
@@ -177,9 +185,9 @@ function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
|
177
185
|
entryName = prependEntriesDir(entryName);
|
|
178
186
|
return { entryName, entryTarget, entryFilePath: filePath };
|
|
179
187
|
}
|
|
180
|
-
function getEntryFromPageConfig(pageConfig,
|
|
188
|
+
function getEntryFromPageConfig(pageConfig, environmentName) {
|
|
181
189
|
let { pageId } = pageConfig;
|
|
182
|
-
const entryTarget = generateVirtualFileId({ type: 'page-entry', pageId,
|
|
190
|
+
const entryTarget = generateVirtualFileId({ type: 'page-entry', pageId, environmentName });
|
|
183
191
|
let entryName = pageId;
|
|
184
192
|
// Avoid:
|
|
185
193
|
// ```
|
|
@@ -220,8 +228,8 @@ function addLogHook() {
|
|
|
220
228
|
}
|
|
221
229
|
});
|
|
222
230
|
}
|
|
223
|
-
function assertRollupInput(
|
|
224
|
-
const userInputs = normalizeRollupInput(
|
|
231
|
+
function assertRollupInput(input) {
|
|
232
|
+
const userInputs = normalizeRollupInput(input);
|
|
225
233
|
const htmlInputs = Object.values(userInputs).filter((entry) => entry.endsWith('.html') || entry.endsWith('.htm'));
|
|
226
234
|
const htmlInput = htmlInputs[0];
|
|
227
235
|
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`);
|
|
@@ -12,6 +12,8 @@ import { getAssetsDir } from '../../shared/getAssetsDir.js';
|
|
|
12
12
|
import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js';
|
|
13
13
|
import '../../assertEnvVite.js';
|
|
14
14
|
import { isVite8OrAbove } from '../../shared/isVite8OrAbove.js';
|
|
15
|
+
import { isViteServerSide_configEnvironment } from '../../shared/isViteServerSide.js';
|
|
16
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
15
17
|
function pluginDistFileNames() {
|
|
16
18
|
return [
|
|
17
19
|
{
|
|
@@ -19,42 +21,65 @@ function pluginDistFileNames() {
|
|
|
19
21
|
apply: 'build',
|
|
20
22
|
enforce: 'post',
|
|
21
23
|
configResolved: {
|
|
22
|
-
handler(config) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
|
|
34
|
-
rollupOutput.assetFileNames.isTheOneSetByVike = true;
|
|
35
|
-
assert(rollupOutput.assetFileNames.isTheOneSetByVike);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
// If a user needs this:
|
|
39
|
-
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
40
|
-
// - It's needed for getHash() of handleAssetsManifest()
|
|
41
|
-
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
42
|
-
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
43
|
-
assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
|
|
44
|
-
}
|
|
24
|
+
async handler(config) {
|
|
25
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
26
|
+
Object.entries(config.environments).forEach(([envName, envConfig]) => {
|
|
27
|
+
// Vike doesn't own the builds of additional environments (e.g. `rsc`): it only emits `entry-environment.mjs` there
|
|
28
|
+
if (additionalEnvironmentNames.includes(envName))
|
|
29
|
+
return;
|
|
30
|
+
const { build } = envConfig;
|
|
31
|
+
copyRollupOutputs(build);
|
|
32
|
+
const isServerSide = isViteServerSide_configEnvironment(envName, envConfig);
|
|
33
|
+
setFileNames(config, build, isServerSide, envName);
|
|
34
|
+
disableCSSBundling(config, build);
|
|
45
35
|
});
|
|
46
|
-
disableCSSBundling(config);
|
|
47
36
|
},
|
|
48
37
|
},
|
|
49
38
|
},
|
|
50
39
|
];
|
|
51
40
|
}
|
|
41
|
+
function setFileNames(config, build, isServerSide, envName) {
|
|
42
|
+
const rollupOutputs = getRollupOutputs(build);
|
|
43
|
+
// We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
|
|
44
|
+
rollupOutputs.forEach((rollupOutput) => {
|
|
45
|
+
// Server environments other than `ssr` keep their own entry file names, e.g. @vitejs/plugin-rsc imports its `rsc` entry as `index.js`
|
|
46
|
+
if (!('entryFileNames' in rollupOutput) && (!isServerSide || envName === 'ssr')) {
|
|
47
|
+
rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, build, isServerSide);
|
|
48
|
+
}
|
|
49
|
+
if (!('chunkFileNames' in rollupOutput)) {
|
|
50
|
+
rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, build, isServerSide);
|
|
51
|
+
}
|
|
52
|
+
if (!('assetFileNames' in rollupOutput)) {
|
|
53
|
+
rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config, build);
|
|
54
|
+
rollupOutput.assetFileNames.isTheOneSetByVike = true;
|
|
55
|
+
assert(rollupOutput.assetFileNames.isTheOneSetByVike);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// If a user needs this:
|
|
59
|
+
// - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
|
|
60
|
+
// - It's needed for getHash() of handleAssetsManifest()
|
|
61
|
+
// - Asset URLs should always contain a hash: it's paramount for caching assets.
|
|
62
|
+
// - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
|
|
63
|
+
assertUsage(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Vike sets entryFileNames/chunkFileNames/assetFileNames on an output object only if the user didn't set them. But the user's output object can be:
|
|
68
|
+
// - The same object for several environments.
|
|
69
|
+
// - Reused across Vite's config resolutions, e.g. an inline config such as VITE_CONFIG.
|
|
70
|
+
// Without a copy, the file names Vike sets for one environment look user-set to the next environment, which then keeps the wrong environment's file names.
|
|
71
|
+
function copyRollupOutputs(build) {
|
|
72
|
+
const { output } = build.rollupOptions;
|
|
73
|
+
if (!output)
|
|
74
|
+
return;
|
|
75
|
+
build.rollupOptions.output = isArray(output) ? output.map((o) => ({ ...o })) : { ...output };
|
|
76
|
+
}
|
|
52
77
|
function getIdHash(id) {
|
|
53
78
|
return crypto.createHash('md5').update(id).digest('hex').slice(0, 8);
|
|
54
79
|
}
|
|
55
|
-
function getAssetFileName(assetInfo, config) {
|
|
80
|
+
function getAssetFileName(assetInfo, config, build) {
|
|
56
81
|
const userRootDir = config.root;
|
|
57
|
-
const assetsDir = getAssetsDir(
|
|
82
|
+
const assetsDir = getAssetsDir(build);
|
|
58
83
|
const dir = assetsDir + '/static';
|
|
59
84
|
let { name } = assetInfo;
|
|
60
85
|
if (!name) {
|
|
@@ -78,19 +103,19 @@ function getAssetFileName(assetInfo, config) {
|
|
|
78
103
|
name = clean(name, userRootDir);
|
|
79
104
|
return `${dir}/${name}.[hash][extname]`;
|
|
80
105
|
}
|
|
81
|
-
function getChunkFileName(_chunkInfo,
|
|
82
|
-
const isForClientSide = !
|
|
106
|
+
function getChunkFileName(_chunkInfo, build, isServerSide) {
|
|
107
|
+
const isForClientSide = !isServerSide;
|
|
83
108
|
let name = 'chunks/chunk-[hash].js';
|
|
84
109
|
if (isForClientSide) {
|
|
85
|
-
const assetsDir = getAssetsDir(
|
|
110
|
+
const assetsDir = getAssetsDir(build);
|
|
86
111
|
name = `${assetsDir}/${name}`;
|
|
87
112
|
}
|
|
88
113
|
return name;
|
|
89
114
|
}
|
|
90
|
-
function getEntryFileName(chunkInfo, config,
|
|
115
|
+
function getEntryFileName(chunkInfo, config, build, isServerSide) {
|
|
91
116
|
const userRootDir = config.root;
|
|
92
|
-
const assetsDir = getAssetsDir(
|
|
93
|
-
const isForClientSide = !
|
|
117
|
+
const assetsDir = getAssetsDir(build);
|
|
118
|
+
const isForClientSide = !isServerSide;
|
|
94
119
|
let { name } = chunkInfo;
|
|
95
120
|
assertPosixPath(name);
|
|
96
121
|
name = clean(name, userRootDir, true,
|
|
@@ -100,7 +125,7 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
100
125
|
return `${assetsDir}/${name}.[hash].js`;
|
|
101
126
|
}
|
|
102
127
|
else {
|
|
103
|
-
return `${name}
|
|
128
|
+
return `${name}.mjs`;
|
|
104
129
|
}
|
|
105
130
|
}
|
|
106
131
|
function removePathSeparators(name) {
|
|
@@ -188,9 +213,9 @@ function workaroundGlob(name) {
|
|
|
188
213
|
return name;
|
|
189
214
|
}
|
|
190
215
|
// Workaround for Vite CSS duplication bug: https://github.com/vikejs/vike/issues/1815
|
|
191
|
-
function disableCSSBundling(config) {
|
|
216
|
+
function disableCSSBundling(config, build) {
|
|
192
217
|
if (isVite8OrAbove(config)) {
|
|
193
|
-
for (const output of getRolldownOutputs(
|
|
218
|
+
for (const output of getRolldownOutputs(build)) {
|
|
194
219
|
assert(output);
|
|
195
220
|
const { codeSplitting } = output;
|
|
196
221
|
// `codeSplitting: false` => single-bundle mode; respect the user's choice.
|
|
@@ -219,7 +244,7 @@ function disableCSSBundling(config) {
|
|
|
219
244
|
}
|
|
220
245
|
}
|
|
221
246
|
else {
|
|
222
|
-
for (const output of getRollupOutputs(
|
|
247
|
+
for (const output of getRollupOutputs(build)) {
|
|
223
248
|
assert(output);
|
|
224
249
|
wrapManualChunks(output, config, 'rollupOptions');
|
|
225
250
|
}
|
|
@@ -291,28 +316,23 @@ function getCssChunkName(id, config) {
|
|
|
291
316
|
return `${name}-${hash}`;
|
|
292
317
|
}
|
|
293
318
|
}
|
|
294
|
-
function getRollupOutputs(
|
|
295
|
-
var _a
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
(_a = config.build).rollupOptions ?? (_a.rollupOptions = {});
|
|
299
|
-
(_b = config.build.rollupOptions).output ?? (_b.output = {});
|
|
300
|
-
const { output } = config.build.rollupOptions;
|
|
319
|
+
function getRollupOutputs(build) {
|
|
320
|
+
var _a;
|
|
321
|
+
(_a = build.rollupOptions).output ?? (_a.output = {});
|
|
322
|
+
const { output } = build.rollupOptions;
|
|
301
323
|
if (!isArray(output)) {
|
|
302
324
|
return [output];
|
|
303
325
|
}
|
|
304
326
|
return output;
|
|
305
327
|
}
|
|
306
|
-
function getRolldownOutputs(
|
|
307
|
-
var _a
|
|
308
|
-
// @ts-expect-error is read-only
|
|
309
|
-
config.build ?? (config.build = {});
|
|
328
|
+
function getRolldownOutputs(build) {
|
|
329
|
+
var _a;
|
|
310
330
|
// @ts-ignore
|
|
311
|
-
|
|
331
|
+
build.rolldownOptions ?? (build.rolldownOptions = {});
|
|
312
332
|
// @ts-ignore
|
|
313
|
-
(
|
|
333
|
+
(_a = build.rolldownOptions).output ?? (_a.output = {});
|
|
314
334
|
// @ts-ignore
|
|
315
|
-
const { output } =
|
|
335
|
+
const { output } = build.rolldownOptions;
|
|
316
336
|
if (!isArray(output)) {
|
|
317
337
|
return [output];
|
|
318
338
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { pluginEnvironmentEntries };
|
|
2
|
+
export { getEnvironmentEntryPlaceholder };
|
|
3
|
+
import type { Plugin } from 'vite';
|
|
4
|
+
import '../../assertEnvVite.js';
|
|
5
|
+
declare function pluginEnvironmentEntries(): Plugin[];
|
|
6
|
+
declare function getEnvironmentEntryPlaceholder(environmentName: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export { pluginEnvironmentEntries };
|
|
2
|
+
export { getEnvironmentEntryPlaceholder };
|
|
3
|
+
// Vike's server environment imports the global entry of every additional environment (e.g. `rsc`), see loadPageContextEnvironments.ts
|
|
4
|
+
// - An additional environment is a separate build, so the server imports its entry by a path relative to the importing chunk, which is known only after chunking (the same marker + renderChunk() as @vitejs/plugin-rsc's import.meta.viteRsc.loadModule())
|
|
5
|
+
import { assertUsage } from '../../../../utils/assert.js';
|
|
6
|
+
import { generateVirtualFileIdAdditionalEnvironment } from '../../../../shared-server-node/virtualFileId.js';
|
|
7
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
8
|
+
import { getMagicString } from '../../shared/getMagicString.js';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import '../../assertEnvVite.js';
|
|
11
|
+
const environmentEntryFileName = 'entry-environment.mjs';
|
|
12
|
+
const environmentEntryPlaceholder = '__VIKE_ENVIRONMENT_ENTRY__';
|
|
13
|
+
const environmentEntryPlaceholderRegex = new RegExp(`(["'\`])${environmentEntryPlaceholder}:(.+?)\\1`, 'g');
|
|
14
|
+
function pluginEnvironmentEntries() {
|
|
15
|
+
return [
|
|
16
|
+
{
|
|
17
|
+
name: 'vike:build:emitEnvironmentEntry',
|
|
18
|
+
apply: 'build',
|
|
19
|
+
buildStart: {
|
|
20
|
+
async handler() {
|
|
21
|
+
const { name, config } = this.environment;
|
|
22
|
+
const { _additionalEnvironmentNames: additionalEnvironmentNames } = await getVikeConfigInternal();
|
|
23
|
+
if (!additionalEnvironmentNames.includes(name))
|
|
24
|
+
return;
|
|
25
|
+
assertUsage(config.consumer === 'server', `The Vike environment ${name} should be a server-side Vite environment`);
|
|
26
|
+
this.emitFile({
|
|
27
|
+
type: 'chunk',
|
|
28
|
+
id: generateVirtualFileIdAdditionalEnvironment(name),
|
|
29
|
+
fileName: environmentEntryFileName,
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'vike:build:linkEnvironmentEntries',
|
|
36
|
+
apply: 'build',
|
|
37
|
+
resolveId: {
|
|
38
|
+
filter: { id: new RegExp(`^${environmentEntryPlaceholder}:`) },
|
|
39
|
+
handler(id) {
|
|
40
|
+
return { id, external: true };
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
renderChunk: {
|
|
44
|
+
handler(code, chunk) {
|
|
45
|
+
return replaceEnvironmentEntryPlaceholders(code, chunk.fileName, this.environment);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
// The import specifier of the environment's entry, replaced by its relative path once the importer's location is known
|
|
52
|
+
function getEnvironmentEntryPlaceholder(environmentName) {
|
|
53
|
+
return `${environmentEntryPlaceholder}:${environmentName}`;
|
|
54
|
+
}
|
|
55
|
+
// Replace each placeholder with the path of the environment's entry, relative to the chunk
|
|
56
|
+
function replaceEnvironmentEntryPlaceholders(code, chunkFileName, environment) {
|
|
57
|
+
if (!code.includes(environmentEntryPlaceholder))
|
|
58
|
+
return;
|
|
59
|
+
const { config } = environment;
|
|
60
|
+
const chunkDir = path.dirname(path.resolve(config.root, config.build.outDir, chunkFileName));
|
|
61
|
+
const { magicString, getMagicStringResult } = getMagicString(code, chunkFileName);
|
|
62
|
+
for (const match of code.matchAll(environmentEntryPlaceholderRegex)) {
|
|
63
|
+
const outDir = config.environments[match[2]].build.outDir;
|
|
64
|
+
const environmentEntry = path.resolve(config.root, outDir, environmentEntryFileName);
|
|
65
|
+
let importPath = path.relative(chunkDir, environmentEntry).split(path.sep).join('/');
|
|
66
|
+
if (!importPath.startsWith('.'))
|
|
67
|
+
importPath = `./${importPath}`;
|
|
68
|
+
magicString.overwrite(match.index, match.index + match[0].length, JSON.stringify(importPath));
|
|
69
|
+
}
|
|
70
|
+
return getMagicStringResult();
|
|
71
|
+
}
|
|
@@ -9,23 +9,25 @@ function pluginSuppressRollupWarning() {
|
|
|
9
9
|
enforce: 'post',
|
|
10
10
|
configResolved: {
|
|
11
11
|
async handler(config) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
onWarnOriginal
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
Object.values(config.environments).forEach(({ build }) => {
|
|
13
|
+
const onWarnOriginal = build.rollupOptions.onwarn;
|
|
14
|
+
build.rollupOptions.onwarn = function (warning, warn) {
|
|
15
|
+
// Suppress
|
|
16
|
+
if (suppressUnusedImport(warning))
|
|
17
|
+
return;
|
|
18
|
+
if (suppressEmptyBundle(warning))
|
|
19
|
+
return;
|
|
20
|
+
if (suppressUseClientDirective(warning))
|
|
21
|
+
return;
|
|
22
|
+
// Pass through
|
|
23
|
+
if (onWarnOriginal) {
|
|
24
|
+
onWarnOriginal.apply(this, arguments);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
warn(warning);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
29
31
|
},
|
|
30
32
|
},
|
|
31
33
|
},
|
|
@@ -8,11 +8,11 @@ import { isObject } from '../../../utils/isObject.js';
|
|
|
8
8
|
import { assertRollupInput } from './build/pluginBuildConfig.js';
|
|
9
9
|
import pc from '@brillout/picocolors';
|
|
10
10
|
import { assertResolveAlias } from './pluginCommon/assertResolveAlias.js';
|
|
11
|
-
import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVikeConfigInternal.js';
|
|
11
|
+
import { getVikeConfigInternal, setVikeConfigContext, setViteEnvironmentNames, } from '../shared/resolveVikeConfigInternal.js';
|
|
12
12
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/resolveViteConfigUser.js';
|
|
13
13
|
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
14
14
|
import { resolvePrerenderConfigGlobal, isDistServerRemoved } from '../../prerender/resolvePrerenderConfig.js';
|
|
15
|
-
import {
|
|
15
|
+
import { assertViteVersion } from '../../../utils/assertViteVersion.js';
|
|
16
16
|
import '../assertEnvVite.js';
|
|
17
17
|
const pluginName = 'vike:pluginCommon';
|
|
18
18
|
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
@@ -24,7 +24,9 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
24
24
|
config: {
|
|
25
25
|
order: 'pre',
|
|
26
26
|
async handler(configFromUser, env) {
|
|
27
|
-
|
|
27
|
+
// `this` is `undefined` on Vite 6 or older
|
|
28
|
+
const viteVersion = this?.meta.viteVersion;
|
|
29
|
+
assertViteVersion(viteVersion);
|
|
28
30
|
const isDev = isDevCheck(env);
|
|
29
31
|
const isBuild = env.command === 'build';
|
|
30
32
|
const isPreview = env.isPreview;
|
|
@@ -38,7 +40,7 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
38
40
|
const vikeConfig = await getVikeConfigInternal();
|
|
39
41
|
return {
|
|
40
42
|
_isDev: isDev,
|
|
41
|
-
_viteVersionResolved:
|
|
43
|
+
_viteVersionResolved: viteVersion,
|
|
42
44
|
_rootResolvedEarly: rootResolvedEarly,
|
|
43
45
|
// TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
|
|
44
46
|
configVikePromise: Promise.resolve({
|
|
@@ -52,9 +54,10 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
52
54
|
{
|
|
53
55
|
name: pluginName,
|
|
54
56
|
configResolved: {
|
|
55
|
-
handler(config) {
|
|
57
|
+
async handler(config) {
|
|
56
58
|
assertViteRoot(config._rootResolvedEarly, config);
|
|
57
59
|
assertSingleInstance(config);
|
|
60
|
+
await setViteEnvironmentNames(Object.keys(config.environments));
|
|
58
61
|
},
|
|
59
62
|
},
|
|
60
63
|
},
|
|
@@ -72,7 +75,7 @@ function pluginCommon(vikeVitePluginOptions) {
|
|
|
72
75
|
overrideViteDefaultSsrExternal(config)
|
|
73
76
|
//*/
|
|
74
77
|
workaroundCI(config);
|
|
75
|
-
assertRollupInput(config);
|
|
78
|
+
assertRollupInput(config.build.rollupOptions.input);
|
|
76
79
|
assertResolveAlias(config);
|
|
77
80
|
temp_supportOldInterface(config);
|
|
78
81
|
await emitServerEntryOnlyIfNeeded(config);
|
|
@@ -191,7 +191,7 @@ async function getPageDeps(config, pageConfigs, pageConfigGlobal) {
|
|
|
191
191
|
[...pageConfigs, pageConfigGlobal].forEach((pageConfig) => {
|
|
192
192
|
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
193
193
|
const runtimeEnv = {
|
|
194
|
-
isForClientSide,
|
|
194
|
+
environmentName: isForClientSide ? 'client' : 'server',
|
|
195
195
|
isDev: true,
|
|
196
196
|
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
197
197
|
isClientRouting: true,
|
|
@@ -16,7 +16,10 @@ const filterRolldown = {
|
|
|
16
16
|
include: new RegExp(escapeRegex(VIRTUAL_FILE_ID_constantsGlobalThis)),
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
|
-
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis ||
|
|
19
|
+
const filterFunction = (id) => id === VIRTUAL_FILE_ID_constantsGlobalThis ||
|
|
20
|
+
// Vite re-resolves the resolved ID and its URL when a plugin adds the module as a watch file (@vitejs/plugin-rsc)
|
|
21
|
+
id === addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis) ||
|
|
22
|
+
id === `/@id/__x00__${VIRTUAL_FILE_ID_constantsGlobalThis}`;
|
|
20
23
|
// ===
|
|
21
24
|
function pluginReplaceConstantsGlobalThis() {
|
|
22
25
|
let config;
|
|
@@ -63,9 +66,8 @@ function pluginReplaceConstantsGlobalThis() {
|
|
|
63
66
|
resolveId: {
|
|
64
67
|
filter: filterRolldown,
|
|
65
68
|
handler(id) {
|
|
66
|
-
assert(filterFunction(id));
|
|
67
|
-
|
|
68
|
-
return addVirtualFileIdPrefix(id);
|
|
69
|
+
assert(filterFunction(id), { id });
|
|
70
|
+
return addVirtualFileIdPrefix(VIRTUAL_FILE_ID_constantsGlobalThis);
|
|
69
71
|
},
|
|
70
72
|
},
|
|
71
73
|
load: {
|