vike 0.4.236-commit-eab75f6 → 0.4.237-commit-85e89b1
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/client/runtime-client-routing/globalContext.js +2 -2
- package/dist/cjs/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/cjs/client/shared/createGetGlobalContextClient.js +5 -7
- package/dist/cjs/node/api/preview.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +4 -4
- package/dist/cjs/node/runtime/globalContext.js +21 -22
- package/dist/cjs/node/runtime/html/serializeContext.js +8 -47
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +3 -3
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +21 -6
- package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +5 -34
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +22 -9
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/cjs/node/runtime/renderPage.js +7 -6
- package/dist/cjs/node/shared/virtualFileId.js +110 -0
- package/dist/cjs/node/vite/index.js +3 -3
- package/dist/cjs/node/vite/onLoad.js +5 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +10 -10
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +20 -11
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +4 -10
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +46 -44
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +5 -12
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +5 -5
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +5 -1
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +2 -6
- package/dist/cjs/node/vite/plugins/pluginPreview.js +11 -4
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +5 -12
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +7 -9
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -12
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +14 -12
- package/dist/cjs/node/vite/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- package/dist/cjs/node/vite/shared/getMagicString.js +1 -1
- package/dist/cjs/node/vite/shared/getOutDirs.js +18 -12
- package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/cjs/node/vite/shared/isViteServerBuild.js +54 -31
- package/dist/cjs/node/vite/shared/loggerVite.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/cjs/shared/createGlobalContextShared.js +23 -10
- package/dist/cjs/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/loadPageEntry.js +25 -0
- package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +15 -16
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +12 -12
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.js +2 -2
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +4 -4
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +3 -3
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +2 -2
- package/dist/esm/client/runtime-server-routing/globalContext.js +2 -2
- package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +3 -3
- package/dist/esm/client/shared/createGetGlobalContextClient.js +5 -7
- package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
- package/dist/esm/node/api/preview.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +9 -9
- package/dist/esm/node/prerender/runPrerender.js +4 -4
- package/dist/esm/node/runtime/globalContext.d.ts +10 -10
- package/dist/esm/node/runtime/globalContext.js +21 -22
- package/dist/esm/node/runtime/html/serializeContext.d.ts +8 -3
- package/dist/esm/node/runtime/html/serializeContext.js +8 -47
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.js +3 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +22 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.d.ts +10 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +0 -6
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -33
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +25 -12
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +10 -11
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/esm/node/runtime/renderPage.d.ts +3 -2
- package/dist/esm/node/runtime/renderPage.js +7 -6
- package/dist/esm/node/shared/virtualFileId.d.ts +28 -0
- package/dist/esm/node/shared/virtualFileId.js +107 -0
- package/dist/esm/node/vite/index.js +3 -3
- package/dist/esm/node/vite/onLoad.js +5 -3
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +11 -11
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +1 -0
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +21 -12
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +4 -4
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +5 -8
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +47 -45
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +6 -10
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +4 -4
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +6 -2
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +2 -6
- package/dist/esm/node/vite/plugins/pluginPreview.js +13 -6
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +6 -10
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +7 -9
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.d.ts +6 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -12
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +14 -12
- package/dist/esm/node/vite/shared/findPageFiles.js +1 -1
- package/dist/esm/node/vite/shared/getClientEntrySrcDev.d.ts +4 -0
- package/dist/esm/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +2 -2
- package/dist/esm/node/vite/shared/getMagicString.js +1 -1
- package/dist/esm/node/vite/shared/getOutDirs.d.ts +6 -3
- package/dist/esm/node/vite/shared/getOutDirs.js +19 -13
- package/dist/esm/node/vite/shared/getViteConfigRuntime.js +1 -1
- package/dist/esm/node/vite/shared/isViteServerBuild.d.ts +14 -11
- package/dist/esm/node/vite/shared/isViteServerBuild.js +55 -31
- package/dist/esm/node/vite/shared/loggerVite.js +1 -1
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +3 -5
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +10 -21
- package/dist/esm/shared/createGlobalContextShared.d.ts +6 -6
- package/dist/esm/shared/createGlobalContextShared.js +25 -12
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.d.ts → parseVirtualFileExportsGlobalEntry.d.ts} +2 -2
- package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/execHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/loadPageEntry.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadPageEntry.js +23 -0
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +9 -9
- package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +4 -4
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +1 -1
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.d.ts → parsePageConfigsSerialized.d.ts} +2 -2
- package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +15 -16
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/PageConfig.d.ts +9 -7
- package/dist/esm/types/VikeNamespace.d.ts +13 -0
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/package.json +3 -3
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +0 -31
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -45
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -11
- package/dist/cjs/shared/page-configs/loadConfigValues.js +0 -21
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.d.ts +0 -4
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +0 -4
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.d.ts +0 -11
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +0 -28
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.d.ts +0 -9
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -43
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFileEntry.d.ts +0 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.d.ts +0 -3
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.d.ts +0 -3
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -9
- package/dist/esm/node/vite/shared/resolveClientEntriesDev.d.ts +0 -4
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadConfigValues.js +0 -19
|
@@ -55,7 +55,7 @@ function pluginAutoFullBuild() {
|
|
|
55
55
|
order: 'post',
|
|
56
56
|
async handler() {
|
|
57
57
|
onSetupBuild();
|
|
58
|
-
handleAssetsManifest_assertUsageCssTarget(config);
|
|
58
|
+
handleAssetsManifest_assertUsageCssTarget(config, this.environment);
|
|
59
59
|
const vikeConfig = await getVikeConfigInternal();
|
|
60
60
|
if (forceExit &&
|
|
61
61
|
// Let vike:build:pluginBuildApp force exit
|
|
@@ -4,17 +4,18 @@ export { analyzeClientEntries };
|
|
|
4
4
|
import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveVikeDistFile, } from '../../utils.js';
|
|
5
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
6
6
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
7
|
-
import {
|
|
7
|
+
import { generateVirtualFileId } from '../../../shared/virtualFileId.js';
|
|
8
8
|
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 {
|
|
12
|
+
import { isViteServerBuild_withoutEnv } from '../../shared/isViteServerBuild.js';
|
|
13
|
+
import { resolveOutDir_configEnvironment } from '../../shared/getOutDirs.js';
|
|
14
14
|
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
|
|
15
|
-
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets.js';
|
|
15
|
+
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
16
16
|
function pluginBuildConfig() {
|
|
17
17
|
let config;
|
|
18
|
+
let configUnresolved;
|
|
18
19
|
return [
|
|
19
20
|
{
|
|
20
21
|
name: 'vike:build:pluginBuildConfig',
|
|
@@ -33,18 +34,26 @@ function pluginBuildConfig() {
|
|
|
33
34
|
handleAssetsManifest_assertUsageCssCodeSplit(config);
|
|
34
35
|
},
|
|
35
36
|
},
|
|
36
|
-
|
|
37
|
+
configEnvironment: {
|
|
37
38
|
order: 'post',
|
|
38
|
-
async handler(
|
|
39
|
-
|
|
39
|
+
async handler(envName, configEnv) {
|
|
40
|
+
assert(configUnresolved);
|
|
40
41
|
return {
|
|
41
42
|
build: {
|
|
42
|
-
outDir:
|
|
43
|
-
...(await handleAssetsManifest_getBuildConfig(config)),
|
|
43
|
+
outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
|
|
44
44
|
},
|
|
45
45
|
};
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
|
+
config: {
|
|
49
|
+
order: 'post',
|
|
50
|
+
async handler(config) {
|
|
51
|
+
configUnresolved = config;
|
|
52
|
+
onSetupBuild();
|
|
53
|
+
const build = await handleAssetsManifest_getBuildConfig(config);
|
|
54
|
+
return { build };
|
|
55
|
+
},
|
|
56
|
+
},
|
|
48
57
|
buildStart() {
|
|
49
58
|
onSetupBuild();
|
|
50
59
|
},
|
|
@@ -57,7 +66,7 @@ async function getEntries(config) {
|
|
|
57
66
|
// TO-DO/next-major-release: remove
|
|
58
67
|
const pageFileEntries = await getPageFileEntries(config, resolveIncludeAssetsImportedByServer(vikeConfig.config));
|
|
59
68
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
60
|
-
if (
|
|
69
|
+
if (isViteServerBuild_withoutEnv(config)) {
|
|
61
70
|
const pageEntries = getPageEntries(pageConfigs);
|
|
62
71
|
const entries = {
|
|
63
72
|
...pageFileEntries,
|
|
@@ -130,7 +139,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
130
139
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
131
140
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
132
141
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
133
|
-
const isForClientSide = !
|
|
142
|
+
const isForClientSide = !isViteServerBuild_withoutEnv(config);
|
|
134
143
|
const fileTypes = isForClientSide ? ['.page', '.page.client'] : ['.page', '.page.server'];
|
|
135
144
|
if (isForClientSide && includeAssetsImportedByServer) {
|
|
136
145
|
fileTypes.push('.page.server');
|
|
@@ -174,7 +183,7 @@ function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
|
174
183
|
}
|
|
175
184
|
function getEntryFromPageConfig(pageConfig, isForClientSide) {
|
|
176
185
|
let { pageId } = pageConfig;
|
|
177
|
-
const entryTarget =
|
|
186
|
+
const entryTarget = generateVirtualFileId({ type: 'page-entry', pageId, isForClientSide });
|
|
178
187
|
let entryName = pageId;
|
|
179
188
|
// Avoid:
|
|
180
189
|
// ```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { pluginBuildEntry };
|
|
2
2
|
export { set_macro_ASSETS_MANIFEST };
|
|
3
3
|
import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
|
-
import {
|
|
4
|
+
import { virtualFileIdGlobalEntryServer } from '../../../shared/virtualFileId.js';
|
|
5
5
|
import { assert, PROJECT_VERSION, requireResolveVikeDistFile } from '../../utils.js';
|
|
6
6
|
import fs from 'node:fs/promises';
|
|
7
7
|
import path from 'node:path';
|
|
@@ -40,14 +40,14 @@ function getServerProductionEntryCode(config) {
|
|
|
40
40
|
// After the old design is removed, let's maybe simplify and move everything into a single virtual module
|
|
41
41
|
const importerCode = [
|
|
42
42
|
` import { setGlobalContext_buildEntry } from '${importPath}';`,
|
|
43
|
-
` import * as
|
|
43
|
+
` import * as virtualFileExportsGlobalEntry from '${virtualFileIdGlobalEntryServer}';`,
|
|
44
44
|
` {`,
|
|
45
45
|
// Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_buildEntry()
|
|
46
46
|
// - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
|
|
47
47
|
` const assetsManifest = ${ASSETS_MANIFEST};`,
|
|
48
48
|
` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
|
|
49
49
|
' setGlobalContext_buildEntry({',
|
|
50
|
-
`
|
|
50
|
+
` virtualFileExportsGlobalEntry,`,
|
|
51
51
|
` assetsManifest,`,
|
|
52
52
|
` buildInfo,`,
|
|
53
53
|
' });',
|
|
@@ -97,7 +97,7 @@ function getImportPath(config) {
|
|
|
97
97
|
return 'vike/__internal';
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
const { outDirServer } = getOutDirs(config);
|
|
100
|
+
const { outDirServer } = getOutDirs(config, undefined);
|
|
101
101
|
const filePathRelative = path.posix.relative(outDirServer, filePathAbsolute);
|
|
102
102
|
return filePathRelative;
|
|
103
103
|
}
|
|
@@ -18,7 +18,7 @@ function pluginDistPackageJsonFile() {
|
|
|
18
18
|
config = config_;
|
|
19
19
|
},
|
|
20
20
|
generateBundle(options, bundle) {
|
|
21
|
-
if (!isViteServerBuild(config))
|
|
21
|
+
if (!isViteServerBuild(config, this.environment))
|
|
22
22
|
return;
|
|
23
23
|
const isEsm = rollupIsEsm(options);
|
|
24
24
|
const fileName = 'package.json';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { pluginModuleBanner };
|
|
2
|
-
import MagicString from 'magic-string';
|
|
3
2
|
import { removeVirtualFileIdPrefix } from '../../utils.js';
|
|
4
|
-
import {
|
|
3
|
+
import { getMagicString } from '../../shared/getMagicString.js';
|
|
4
|
+
import { isViteServerBuild_extraSafe } from '../../shared/isViteServerBuild.js';
|
|
5
5
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
6
6
|
// But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
|
|
7
7
|
function pluginModuleBanner() {
|
|
@@ -16,7 +16,7 @@ function pluginModuleBanner() {
|
|
|
16
16
|
transform: {
|
|
17
17
|
order: 'post',
|
|
18
18
|
handler(code, id, options) {
|
|
19
|
-
if (!
|
|
19
|
+
if (!isViteServerBuild_extraSafe(config, options, this.environment) &&
|
|
20
20
|
// Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
|
|
21
21
|
config.build.minify) {
|
|
22
22
|
return;
|
|
@@ -27,15 +27,12 @@ function pluginModuleBanner() {
|
|
|
27
27
|
if (id.startsWith(config.root))
|
|
28
28
|
id = id.slice(config.root.length + 1);
|
|
29
29
|
id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
|
|
30
|
-
const magicString =
|
|
30
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
31
31
|
// Use legal comment so that esbuild doesn't remove it.
|
|
32
32
|
// - Terser still removes the comment, but I guess users use terser to minify JavaScript so I guess it's a good thing that comment is removed.
|
|
33
33
|
// - https://esbuild.github.io/api/#legal-comments
|
|
34
34
|
magicString.prepend(`/*! ${id} [vike:pluginModuleBanner] */\n`);
|
|
35
|
-
return
|
|
36
|
-
code: magicString.toString(),
|
|
37
|
-
map: magicString.generateMap({ hires: true, source: id }),
|
|
38
|
-
};
|
|
35
|
+
return getMagicStringResult();
|
|
39
36
|
},
|
|
40
37
|
},
|
|
41
38
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
3
|
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, } from '../../utils.js';
|
|
4
|
-
import { getVikeConfigInternal
|
|
4
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { analyzeClientEntries } from '../pluginBuild/pluginBuildConfig.js';
|
|
6
|
-
import {
|
|
6
|
+
import { virtualFileIdGlobalEntryClientCR, virtualFileIdGlobalEntryClientSR } from '../../../shared/virtualFileId.js';
|
|
7
7
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
8
|
+
import { getConfigValueSourcesRelevant } from '../pluginVirtualFiles/getConfigValueSourcesRelevant.js';
|
|
8
9
|
const debug = createDebugger('vike:optimizeDeps');
|
|
9
10
|
async function determineOptimizeDeps(config) {
|
|
10
11
|
const vikeConfig = await getVikeConfigInternal();
|
|
@@ -38,43 +39,36 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
38
39
|
let entriesServer = [];
|
|
39
40
|
let includeClient = [];
|
|
40
41
|
let includeServer = [];
|
|
41
|
-
const addEntry = (e,
|
|
42
|
+
const addEntry = (e, isForClientSide, definedAt) => {
|
|
42
43
|
assert(e);
|
|
43
44
|
// optimizeDeps.entries expects filesystem absolute paths
|
|
44
45
|
assert(isVirtualFileId(e) || isFilePathAbsoluteFilesystem(e));
|
|
45
|
-
if (
|
|
46
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
47
|
+
return;
|
|
48
|
+
if (isForClientSide) {
|
|
46
49
|
entriesClient.push(e);
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
else {
|
|
49
52
|
entriesServer.push(e);
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
|
-
const addInclude = (e,
|
|
55
|
+
const addInclude = (e, isForClientSide, definedAt) => {
|
|
53
56
|
assert(e);
|
|
54
57
|
// optimizeDeps.include expects npm packages
|
|
55
58
|
assert(!e.startsWith('/'));
|
|
56
59
|
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
57
60
|
assertIsImportPathNpmPackage(e);
|
|
58
|
-
if (
|
|
61
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
62
|
+
return;
|
|
63
|
+
if (isForClientSide) {
|
|
59
64
|
includeClient.push(e);
|
|
60
65
|
}
|
|
61
|
-
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
62
|
-
includeServer.push(e);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const isRelevant = (e, server, configEnv, definedAt) => {
|
|
66
|
-
if (server) {
|
|
67
|
-
if (!configEnv || !configEnv.server)
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
66
|
else {
|
|
71
|
-
|
|
72
|
-
return false;
|
|
67
|
+
includeServer.push(e);
|
|
73
68
|
}
|
|
74
|
-
return !isExcluded(e, server, definedAt);
|
|
75
69
|
};
|
|
76
|
-
const isExcluded = (e,
|
|
77
|
-
const exclude =
|
|
70
|
+
const isExcluded = (e, isForClientSide, definedAt) => {
|
|
71
|
+
const exclude = isForClientSide ? config.optimizeDeps.exclude : config.ssr.optimizeDeps.exclude;
|
|
78
72
|
if (!exclude)
|
|
79
73
|
return false;
|
|
80
74
|
if (definedAt?.importPathAbsolute) {
|
|
@@ -86,26 +80,34 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
86
80
|
};
|
|
87
81
|
// V1 design
|
|
88
82
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
83
|
+
;
|
|
84
|
+
[true, false].forEach((isForClientSide) => {
|
|
85
|
+
pageConfigs.forEach((pageConfig) => {
|
|
86
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
87
|
+
const runtimeEnv = {
|
|
88
|
+
isForClientSide,
|
|
89
|
+
isDev: true,
|
|
90
|
+
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
91
|
+
isClientRouting: true,
|
|
92
|
+
};
|
|
93
|
+
const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
|
|
94
|
+
sourcesRelevant.forEach((configValueSource) => {
|
|
95
|
+
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
96
|
+
return;
|
|
97
|
+
const { definedAt } = configValueSource;
|
|
98
|
+
if (definedAt.definedBy)
|
|
99
|
+
return;
|
|
100
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
101
|
+
addEntry(
|
|
102
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
103
|
+
definedAt.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
addInclude(
|
|
107
|
+
// optimizeDeps.include expects npm packages
|
|
108
|
+
definedAt.importPathAbsolute, isForClientSide, definedAt);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
});
|
|
@@ -117,7 +119,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
117
119
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
118
120
|
const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
119
121
|
const { filePathAbsoluteFilesystem } = entry;
|
|
120
|
-
addEntry(filePathAbsoluteFilesystem);
|
|
122
|
+
addEntry(filePathAbsoluteFilesystem, true);
|
|
121
123
|
});
|
|
122
124
|
}
|
|
123
125
|
// Add virtual files.
|
|
@@ -127,11 +129,11 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
127
129
|
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
128
130
|
{
|
|
129
131
|
const { hasClientRouting, hasServerRouting, clientEntries } = analyzeClientEntries(pageConfigs, config);
|
|
130
|
-
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
132
|
+
Object.values(clientEntries).forEach((e) => addEntry(e, true));
|
|
131
133
|
if (hasClientRouting)
|
|
132
|
-
addEntry(
|
|
134
|
+
addEntry(virtualFileIdGlobalEntryClientCR, true);
|
|
133
135
|
if (hasServerRouting)
|
|
134
|
-
addEntry(
|
|
136
|
+
addEntry(virtualFileIdGlobalEntryClientSR, true);
|
|
135
137
|
}
|
|
136
138
|
entriesClient = entriesClient;
|
|
137
139
|
entriesServer = entriesServer;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { pluginEnvVars };
|
|
2
|
-
import MagicString from 'magic-string';
|
|
3
2
|
import { loadEnv } from 'vite';
|
|
4
3
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, isArray, isNotNullish, lowerFirst, } from '../utils.js';
|
|
5
4
|
import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
6
5
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { isViteServerBuild_extraSafe } from '../shared/isViteServerBuild.js';
|
|
7
|
+
import { getMagicString } from '../shared/getMagicString.js';
|
|
9
8
|
// TO-DO/eventually:
|
|
10
9
|
// - Make import.meta.env work inside +config.js
|
|
11
10
|
// - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
|
|
@@ -37,8 +36,8 @@ function pluginEnvVars() {
|
|
|
37
36
|
if (!code.includes('import.meta.env.'))
|
|
38
37
|
return;
|
|
39
38
|
const isBuild = config.command === 'build';
|
|
40
|
-
const isClientSide = !
|
|
41
|
-
const magicString =
|
|
39
|
+
const isClientSide = !isViteServerBuild_extraSafe(config, options, this.environment);
|
|
40
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
42
41
|
// Find & check
|
|
43
42
|
const replacements = Object.entries(envsAll)
|
|
44
43
|
.filter(([key]) => {
|
|
@@ -76,14 +75,11 @@ function pluginEnvVars() {
|
|
|
76
75
|
.filter(isNotNullish);
|
|
77
76
|
// Apply
|
|
78
77
|
replacements.forEach(({ regExpStr, replacement }) => {
|
|
79
|
-
|
|
78
|
+
magicString.replaceAll(new RegExp(regExpStr, 'g'), JSON.stringify(replacement));
|
|
80
79
|
});
|
|
81
80
|
if (!magicString.hasChanged())
|
|
82
81
|
return null;
|
|
83
|
-
return
|
|
84
|
-
code: magicString.toString(),
|
|
85
|
-
map: magicString.generateMap({ hires: true, source: id }),
|
|
86
|
-
};
|
|
82
|
+
return getMagicStringResult();
|
|
87
83
|
},
|
|
88
84
|
};
|
|
89
85
|
}
|
|
@@ -15,8 +15,8 @@ import { handleAssetsManifest_isFixEnabled } from './pluginBuild/handleAssetsMan
|
|
|
15
15
|
import { getVikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
|
|
16
16
|
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
17
17
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
18
|
-
import {
|
|
19
|
-
import { resolveIncludeAssetsImportedByServer } from '../../runtime/renderPage/getPageAssets.js';
|
|
18
|
+
import { isViteServerBuild_extraSafe } from '../shared/isViteServerBuild.js';
|
|
19
|
+
import { resolveIncludeAssetsImportedByServer } from '../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
|
|
20
20
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
21
21
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
22
22
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
@@ -45,7 +45,7 @@ function pluginExtractAssets() {
|
|
|
45
45
|
}
|
|
46
46
|
const includeAssetsImportedByServer = resolveIncludeAssetsImportedByServer(vikeConfig.config);
|
|
47
47
|
assert(includeAssetsImportedByServer);
|
|
48
|
-
assert(!
|
|
48
|
+
assert(!isViteServerBuild_extraSafe(config, options, this.environment));
|
|
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 (
|
|
65
|
+
if (isViteServerBuild_extraSafe(config, options, this.environment)) {
|
|
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));
|
|
@@ -4,18 +4,19 @@ export { extractExportNamesRE };
|
|
|
4
4
|
import { assert, getFileExtension, createDebugger, getGlobalObject, assertUsage, rollupSourceMapRemove, } from '../utils.js';
|
|
5
5
|
import { getExportNames } from '../shared/parseEsModule.js';
|
|
6
6
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
7
|
-
import {
|
|
7
|
+
import { isViteServerBuild_extraSafe } from '../shared/isViteServerBuild.js';
|
|
8
8
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
9
9
|
const debug = createDebugger('vike:pluginExtractExportNames');
|
|
10
10
|
const globalObject = getGlobalObject('plugins/pluginExtractExportNames.ts', {});
|
|
11
11
|
function pluginExtractExportNames() {
|
|
12
12
|
let isDev = false;
|
|
13
|
+
let config;
|
|
13
14
|
return {
|
|
14
15
|
name: 'vike:pluginExtractExportNames',
|
|
15
16
|
enforce: 'post',
|
|
16
17
|
async transform(src, id, options) {
|
|
17
18
|
id = normalizeId(id);
|
|
18
|
-
const isClientSide = !
|
|
19
|
+
const isClientSide = !isViteServerBuild_extraSafe(config, options, this.environment);
|
|
19
20
|
if (extractExportNamesRE.test(id)) {
|
|
20
21
|
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
21
22
|
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
@@ -25,6 +26,9 @@ function pluginExtractExportNames() {
|
|
|
25
26
|
configureServer() {
|
|
26
27
|
isDev = true;
|
|
27
28
|
},
|
|
29
|
+
configResolved(config_) {
|
|
30
|
+
config = config_;
|
|
31
|
+
},
|
|
28
32
|
config() {
|
|
29
33
|
if (debug.isActivated) {
|
|
30
34
|
return { logLevel: 'silent' };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { pluginNonRunnableDev };
|
|
2
2
|
import { createViteRPC, assertIsNotProductionRuntime, requireResolveVikeDistFile, isRunnableDevEnvironment, } from '../utils.js';
|
|
3
|
-
import {
|
|
4
|
-
import { retrieveAssetsDev } from '../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js';
|
|
3
|
+
import { retrievePageAssetsDev } from '../../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
5
4
|
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
6
5
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
7
6
|
assertIsNotProductionRuntime();
|
|
@@ -10,11 +9,8 @@ function getViteRpcFunctions(viteDevServer) {
|
|
|
10
9
|
async transformIndexHtmlRPC(html) {
|
|
11
10
|
return await viteDevServer.transformIndexHtml('/', html);
|
|
12
11
|
},
|
|
13
|
-
// TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
|
|
14
12
|
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
15
|
-
|
|
16
|
-
const assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
17
|
-
return { clientEntriesSrc, assetUrls };
|
|
13
|
+
return await retrievePageAssetsDev(viteDevServer, clientDependencies, clientEntries);
|
|
18
14
|
},
|
|
19
15
|
async getViteConfigRuntimeRPC() {
|
|
20
16
|
return getViteConfigRuntime(viteDevServer.config);
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
export { pluginPreview };
|
|
2
|
-
import { assertUsage, applyPreview } from '../utils.js';
|
|
2
|
+
import { assertUsage, applyPreview, assert } 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, resolveOutDir_configEnvironment } 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;
|
|
13
14
|
let vikeConfig;
|
|
14
15
|
return {
|
|
15
16
|
name: 'vike:pluginPreview',
|
|
16
17
|
apply: applyPreview,
|
|
17
18
|
config(config) {
|
|
19
|
+
configUnresolved = config;
|
|
18
20
|
return {
|
|
19
21
|
appType: 'custom',
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
configEnvironment(envName, configEnv) {
|
|
25
|
+
assert(configUnresolved);
|
|
26
|
+
return {
|
|
20
27
|
build: {
|
|
21
|
-
outDir:
|
|
28
|
+
outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
|
|
22
29
|
},
|
|
23
30
|
};
|
|
24
31
|
},
|
|
@@ -46,7 +53,7 @@ function pluginPreview() {
|
|
|
46
53
|
},
|
|
47
54
|
};
|
|
48
55
|
function assertDist(isPrerenderingEnabledForAllPages) {
|
|
49
|
-
const { outDirRoot, outDirClient, outDirServer } = getOutDirs(config);
|
|
56
|
+
const { outDirRoot, outDirClient, outDirServer } = getOutDirs(config, undefined);
|
|
50
57
|
const dirS = [outDirRoot, outDirClient];
|
|
51
58
|
if (!isPrerenderingEnabledForAllPages)
|
|
52
59
|
dirS.push(outDirServer);
|
|
@@ -55,11 +62,11 @@ function pluginPreview() {
|
|
|
55
62
|
});
|
|
56
63
|
}
|
|
57
64
|
function addStaticAssetsMiddleware(middlewares) {
|
|
58
|
-
const { outDirClient } = getOutDirs(config);
|
|
65
|
+
const { outDirClient } = getOutDirs(config, undefined);
|
|
59
66
|
middlewares.use(sirv(outDirClient));
|
|
60
67
|
}
|
|
61
68
|
function addStatic404Middleware(middlewares) {
|
|
62
|
-
const { outDirClient } = getOutDirs(config);
|
|
69
|
+
const { outDirClient } = getOutDirs(config, undefined);
|
|
63
70
|
middlewares.use(config.base, (_, res, next) => {
|
|
64
71
|
const file = path.posix.join(outDirClient, './404.html');
|
|
65
72
|
if (fs.existsSync(file)) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
export { pluginReplaceConstants };
|
|
2
|
-
import MagicString from 'magic-string';
|
|
3
2
|
import { assert, assertPosixPath } from '../utils.js';
|
|
4
3
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { isViteServerBuild_extraSafe } from '../shared/isViteServerBuild.js';
|
|
5
|
+
import { getMagicString } from '../shared/getMagicString.js';
|
|
7
6
|
function pluginReplaceConstants() {
|
|
8
7
|
let config;
|
|
9
8
|
return {
|
|
@@ -30,24 +29,21 @@ function pluginReplaceConstants() {
|
|
|
30
29
|
// @ts-expect-error
|
|
31
30
|
if (config._skipVikeReplaceConstants?.(id))
|
|
32
31
|
return;
|
|
33
|
-
const magicString =
|
|
32
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
34
33
|
const constantsMap = [];
|
|
35
34
|
constantsMap.push({
|
|
36
35
|
constants: ['pageContext.isClientSide', 'globalContext.isClientSide', 'pageContext.globalContext.isClientSide'],
|
|
37
|
-
replacement: !
|
|
36
|
+
replacement: !isViteServerBuild_extraSafe(config, options, this.environment),
|
|
38
37
|
});
|
|
39
38
|
constantsMap.forEach(({ constants, replacement }) => {
|
|
40
39
|
if (!constants.some((c) => code.includes(c)))
|
|
41
40
|
return;
|
|
42
41
|
const regExp = getConstantRegExp(constants);
|
|
43
|
-
|
|
42
|
+
magicString.replaceAll(regExp, JSON.stringify(replacement));
|
|
44
43
|
});
|
|
45
44
|
if (!magicString.hasChanged())
|
|
46
45
|
return null;
|
|
47
|
-
return
|
|
48
|
-
code: magicString.toString(),
|
|
49
|
-
map: magicString.generateMap({ hires: true, source: id }),
|
|
50
|
-
};
|
|
46
|
+
return getMagicStringResult();
|
|
51
47
|
},
|
|
52
48
|
};
|
|
53
49
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import {
|
|
1
|
+
export { generateVirtualFileGlobalEntry };
|
|
2
|
+
import { generateVirtualFileId } from '../../../shared/virtualFileId.js';
|
|
3
3
|
import { debug } from './debug.js';
|
|
4
4
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
|
-
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
6
5
|
import { serializeConfigValues } from '../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
7
|
-
async function
|
|
6
|
+
async function generateVirtualFileGlobalEntry(isForClientSide, isDev, id, isClientRouting) {
|
|
8
7
|
const vikeConfig = await getVikeConfigInternal(true);
|
|
9
8
|
const { _pageConfigs: pageConfigs, _pageConfigGlobal: pageConfigGlobal } = vikeConfig;
|
|
10
9
|
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
@@ -35,11 +34,10 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
35
34
|
lines.push(` pageId: ${JSON.stringify(pageId)},`);
|
|
36
35
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
37
36
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
38
|
-
const virtualFileId = JSON.stringify(
|
|
39
|
-
|
|
40
|
-
lines.push(` loadConfigLazy: ${load},`);
|
|
37
|
+
const virtualFileId = JSON.stringify(generateVirtualFileId({ type: 'page-entry', pageId, isForClientSide }));
|
|
38
|
+
lines.push(` loadVirtualFilePageEntry: () => ({ moduleId: ${virtualFileId}, moduleExportsPromise: import(${virtualFileId}) }),`);
|
|
41
39
|
lines.push(` configValuesSerialized: {`);
|
|
42
|
-
lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv,
|
|
40
|
+
lines.push(...serializeConfigValues(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', true));
|
|
43
41
|
lines.push(` },`);
|
|
44
42
|
lines.push(` },`);
|
|
45
43
|
});
|
|
@@ -49,7 +47,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
49
47
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
|
|
50
48
|
const lines = [];
|
|
51
49
|
lines.push(` configValuesSerialized: {`);
|
|
52
|
-
lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv,
|
|
50
|
+
lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', null));
|
|
53
51
|
lines.push(` },`);
|
|
54
52
|
const code = lines.join('\n');
|
|
55
53
|
return code;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { generateVirtualFileGlobalEntryWithOldDesign };
|
|
2
|
+
import type { ResolvedConfig } from 'vite';
|
|
3
|
+
import type { Environment } from 'vite';
|
|
4
|
+
declare function generateVirtualFileGlobalEntryWithOldDesign(id: string, options: {
|
|
5
|
+
ssr?: boolean;
|
|
6
|
+
} | undefined, config: ResolvedConfig, env: Environment, isDev: boolean): Promise<string>;
|