vike 0.4.236-commit-e752d12 → 0.4.236-commit-79f1ef0
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/shared/createGetGlobalContextClient.js +20 -10
- package/dist/cjs/client/shared/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +104 -20
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +3 -1
- package/dist/cjs/node/runtime/utils.js +4 -0
- package/dist/cjs/node/shared/utils.js +1 -0
- package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +10 -4
- package/dist/cjs/node/vite/index.js +2 -0
- package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -3
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -7
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +102 -58
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +51 -0
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +4 -5
- package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/cjs/node/vite/shared/getMagicString.js +18 -0
- package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +10 -0
- package/dist/cjs/node/vite/utils.js +1 -0
- package/dist/cjs/shared/createGlobalContextShared.js +5 -1
- package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +2 -0
- package/dist/cjs/utils/debug.js +1 -0
- package/dist/cjs/utils/getViteRPC.js +79 -0
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/cjs/utils/isRunnableDevEnvironment.js +9 -0
- package/dist/cjs/utils/virtualFileId.js +39 -0
- package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/history.d.ts +4 -2
- package/dist/esm/client/runtime-client-routing/history.js +13 -35
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +3 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +43 -30
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
- package/dist/esm/client/shared/createGetGlobalContextClient.js +20 -10
- package/dist/esm/client/shared/utils.d.ts +1 -0
- package/dist/esm/client/shared/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +40 -132
- package/dist/esm/node/runtime/globalContext.d.ts +32 -52
- package/dist/esm/node/runtime/globalContext.js +105 -21
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +4 -2
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +10 -33
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +4 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +20 -66
- package/dist/esm/node/runtime/renderPage.d.ts +10 -33
- package/dist/esm/node/runtime/utils.d.ts +4 -0
- package/dist/esm/node/runtime/utils.js +4 -0
- package/dist/esm/node/shared/utils.d.ts +1 -0
- package/dist/esm/node/shared/utils.js +1 -0
- package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +16 -14
- package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +11 -5
- package/dist/esm/node/vite/index.js +2 -0
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +19 -11
- package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +2 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +28 -13
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +12 -7
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +2 -2
- package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
- package/dist/esm/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +103 -59
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +3 -4
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.d.ts +26 -0
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +49 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +4 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +3 -4
- package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
- package/dist/esm/node/vite/shared/getMagicString.d.ts +9 -0
- package/dist/esm/node/vite/shared/getMagicString.js +13 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.d.ts +2 -0
- package/dist/esm/node/vite/shared/getManifestFilePathRelative.js +8 -0
- package/dist/esm/node/vite/utils.d.ts +1 -0
- package/dist/esm/node/vite/utils.js +1 -0
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +5 -1
- package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +6 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.js +2 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +1 -0
- package/dist/esm/utils/getViteRPC.d.ts +6 -0
- package/dist/esm/utils/getViteRPC.js +77 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.d.ts +7 -0
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -0
- package/dist/esm/utils/isRunnableDevEnvironment.d.ts +3 -0
- package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
- package/dist/esm/utils/virtualFileId.d.ts +6 -0
- package/dist/esm/{node/shared/virtualFiles.js → utils/virtualFileId.js} +15 -17
- package/package.json +12 -3
- package/dist/cjs/node/shared/virtualFiles.js +0 -41
- package/dist/esm/node/shared/virtualFiles.d.ts +0 -8
|
@@ -6,6 +6,34 @@ import { isPrerenderForceExit } from './pluginAutoFullBuild.js';
|
|
|
6
6
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
7
7
|
function pluginBuildApp() {
|
|
8
8
|
return [
|
|
9
|
+
{
|
|
10
|
+
name: 'vike:build:pluginBuildApp:pre',
|
|
11
|
+
apply: 'build',
|
|
12
|
+
enforce: 'pre',
|
|
13
|
+
config: {
|
|
14
|
+
order: 'pre',
|
|
15
|
+
async handler(_config) {
|
|
16
|
+
const vikeConfig = await getVikeConfigInternal();
|
|
17
|
+
if (!vikeConfig.config.vite6BuilderApp)
|
|
18
|
+
return;
|
|
19
|
+
return {
|
|
20
|
+
builder: {
|
|
21
|
+
// Can be overridden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
22
|
+
async buildApp(builder) {
|
|
23
|
+
assert(builder.environments.client);
|
|
24
|
+
assert(builder.environments.ssr);
|
|
25
|
+
await builder.build(builder.environments.client);
|
|
26
|
+
await builder.build(builder.environments.ssr);
|
|
27
|
+
if (isPrerenderForceExit()) {
|
|
28
|
+
runPrerender_forceExit();
|
|
29
|
+
assert(false);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
9
37
|
{
|
|
10
38
|
name: 'vike:build:pluginBuildApp',
|
|
11
39
|
apply: 'build',
|
|
@@ -14,19 +42,6 @@ function pluginBuildApp() {
|
|
|
14
42
|
if (!vikeConfig.config.vite6BuilderApp)
|
|
15
43
|
return;
|
|
16
44
|
return {
|
|
17
|
-
builder: {
|
|
18
|
-
// Can be overridden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
19
|
-
async buildApp(builder) {
|
|
20
|
-
assert(builder.environments.client);
|
|
21
|
-
assert(builder.environments.ssr);
|
|
22
|
-
await builder.build(builder.environments.client);
|
|
23
|
-
await builder.build(builder.environments.ssr);
|
|
24
|
-
if (isPrerenderForceExit()) {
|
|
25
|
-
runPrerender_forceExit();
|
|
26
|
-
assert(false);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
45
|
environments: {
|
|
31
46
|
ssr: {
|
|
32
47
|
consumer: 'server',
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
export { manifestTempFile };
|
|
5
4
|
import type { ResolvedConfig, Plugin } from 'vite';
|
|
6
5
|
import type { PageConfigBuildTime } from '../../../../types/PageConfig.js';
|
|
7
|
-
declare const manifestTempFile = "_temp_manifest.json";
|
|
8
6
|
declare function pluginBuildConfig(): Plugin[];
|
|
9
7
|
declare function analyzeClientEntries(pageConfigs: PageConfigBuildTime[], config: ResolvedConfig): {
|
|
10
8
|
hasClientRouting: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { pluginBuildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
export { manifestTempFile };
|
|
5
4
|
import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveVikeDistFile, } from '../../utils.js';
|
|
6
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
7
6
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
@@ -14,7 +13,6 @@ import { isViteServerBuild } from '../../shared/isViteServerBuild.js';
|
|
|
14
13
|
import { resolveOutDir } from '../../shared/getOutDirs.js';
|
|
15
14
|
import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
|
|
16
15
|
import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets.js';
|
|
17
|
-
const manifestTempFile = '_temp_manifest.json';
|
|
18
16
|
function pluginBuildConfig() {
|
|
19
17
|
let config;
|
|
20
18
|
return [
|
|
@@ -151,13 +151,8 @@ function getEntryFileName(chunkInfo, config, isEntry) {
|
|
|
151
151
|
return `${name}.${isEntry ? 'mjs' : 'js'}`;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
-
function removePathSeparators(name
|
|
154
|
+
function removePathSeparators(name) {
|
|
155
155
|
assertPosixPath(name);
|
|
156
|
-
if (name.startsWith(userRootDir)) {
|
|
157
|
-
name = name.slice(userRootDir.length);
|
|
158
|
-
if (name.startsWith('/'))
|
|
159
|
-
name = name.slice(1);
|
|
160
|
-
}
|
|
161
156
|
assert(!name.startsWith('/'), { name });
|
|
162
157
|
const entryDir = 'entries/';
|
|
163
158
|
const hasEntryDir = name.startsWith(entryDir);
|
|
@@ -171,14 +166,24 @@ function removePathSeparators(name, userRootDir) {
|
|
|
171
166
|
}
|
|
172
167
|
return name;
|
|
173
168
|
}
|
|
169
|
+
function removeUserRootDir(name, userRootDir) {
|
|
170
|
+
if (name.startsWith(userRootDir)) {
|
|
171
|
+
name = name.slice(userRootDir.length);
|
|
172
|
+
if (name.startsWith('/'))
|
|
173
|
+
name = name.slice(1);
|
|
174
|
+
}
|
|
175
|
+
assert(!name.startsWith('/'), { name });
|
|
176
|
+
return name;
|
|
177
|
+
}
|
|
174
178
|
function clean(name, userRootDir, removePathSep, fixGlob) {
|
|
179
|
+
name = removeUserRootDir(name, userRootDir);
|
|
175
180
|
name = fixExtractAssetsQuery(name);
|
|
176
181
|
if (fixGlob) {
|
|
177
182
|
name = workaroundGlob(name);
|
|
178
183
|
}
|
|
179
184
|
name = replaceNonLatinCharacters(name);
|
|
180
185
|
if (removePathSep) {
|
|
181
|
-
name = removePathSeparators(name
|
|
186
|
+
name = removePathSeparators(name);
|
|
182
187
|
}
|
|
183
188
|
name = removeLeadingUnderscoreInFilename(name);
|
|
184
189
|
name = removeUnderscoreDoublets(name);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { pluginModuleBanner };
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
|
-
import {
|
|
3
|
+
import { removeVirtualFileIdPrefix } from '../../utils.js';
|
|
4
4
|
import { isViteServerBuild_safe } 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).
|
|
@@ -23,7 +23,7 @@ function pluginModuleBanner() {
|
|
|
23
23
|
}
|
|
24
24
|
if (id.startsWith('\0'))
|
|
25
25
|
id = id;
|
|
26
|
-
id =
|
|
26
|
+
id = removeVirtualFileIdPrefix(id);
|
|
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
|
|
@@ -11,6 +11,7 @@ import { getVikeConfigInternal, setVikeConfigContext } from '../shared/resolveVi
|
|
|
11
11
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
12
12
|
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
13
13
|
const pluginName = 'vike:pluginCommon';
|
|
14
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
14
15
|
function pluginCommon(vikeVitePluginOptions) {
|
|
15
16
|
return [
|
|
16
17
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
|
-
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray,
|
|
3
|
+
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, } from '../../utils.js';
|
|
4
4
|
import { getVikeConfigInternal, isOverridden } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { analyzeClientEntries } from '../pluginBuild/pluginBuildConfig.js';
|
|
6
6
|
import { virtualFileIdEntryClientCR, virtualFileIdEntryClientSR, } from '../../../shared/virtualFiles/virtualFileEntry.js';
|
|
@@ -9,38 +9,80 @@ const debug = createDebugger('vike:optimizeDeps');
|
|
|
9
9
|
async function determineOptimizeDeps(config) {
|
|
10
10
|
const vikeConfig = await getVikeConfigInternal();
|
|
11
11
|
const { _pageConfigs: pageConfigs } = vikeConfig;
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
|
|
13
|
+
config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
|
|
14
|
+
config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
|
|
15
|
+
// Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
|
|
16
|
+
// - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
|
|
17
|
+
includeServer.push('react/jsx-dev-runtime');
|
|
18
|
+
for (const envName in config.environments) {
|
|
19
|
+
const env = config.environments[envName];
|
|
20
|
+
if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
|
|
21
|
+
env.optimizeDeps.include = add(env.optimizeDeps.include, includeServer);
|
|
22
|
+
env.optimizeDeps.entries = add(env.optimizeDeps.entries, entriesServer);
|
|
23
|
+
}
|
|
20
24
|
}
|
|
21
|
-
/* Other Vite plugins may populate optimizeDeps, e.g. Cypress: https://github.com/vikejs/vike/issues/386
|
|
22
|
-
assert(config.optimizeDeps.entries === undefined)
|
|
23
|
-
*/
|
|
24
|
-
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
25
|
-
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
26
25
|
if (debug.isActivated)
|
|
27
|
-
debug('
|
|
26
|
+
debug('optimizeDeps', {
|
|
28
27
|
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
29
28
|
'config.optimizeDeps.include': config.optimizeDeps.include,
|
|
29
|
+
'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
|
|
30
|
+
// @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
31
|
+
'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
|
|
32
|
+
'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
|
|
33
|
+
'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
|
|
30
34
|
});
|
|
31
35
|
}
|
|
32
36
|
async function getPageDeps(config, pageConfigs) {
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
-
|
|
37
|
+
let entriesClient = [];
|
|
38
|
+
let entriesServer = [];
|
|
39
|
+
let includeClient = [];
|
|
40
|
+
let includeServer = [];
|
|
41
|
+
const addEntry = (e, configEnv, definedAt) => {
|
|
36
42
|
assert(e);
|
|
37
|
-
entries
|
|
43
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
44
|
+
assert(isVirtualFileId(e) || isFilePathAbsoluteFilesystem(e));
|
|
45
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
46
|
+
entriesClient.push(e);
|
|
47
|
+
}
|
|
48
|
+
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
49
|
+
entriesServer.push(e);
|
|
50
|
+
}
|
|
38
51
|
};
|
|
39
|
-
const addInclude = (e) => {
|
|
52
|
+
const addInclude = (e, configEnv, definedAt) => {
|
|
40
53
|
assert(e);
|
|
41
|
-
//
|
|
54
|
+
// optimizeDeps.include expects npm packages
|
|
55
|
+
assert(!e.startsWith('/'));
|
|
56
|
+
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
42
57
|
assertIsImportPathNpmPackage(e);
|
|
43
|
-
|
|
58
|
+
if (isRelevant(e, false, configEnv, definedAt)) {
|
|
59
|
+
includeClient.push(e);
|
|
60
|
+
}
|
|
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
|
+
else {
|
|
71
|
+
if (configEnv && !configEnv.client)
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return !isExcluded(e, server, definedAt);
|
|
75
|
+
};
|
|
76
|
+
const isExcluded = (e, server, definedAt) => {
|
|
77
|
+
const exclude = server ? config.ssr.optimizeDeps.exclude : config.optimizeDeps.exclude;
|
|
78
|
+
if (!exclude)
|
|
79
|
+
return false;
|
|
80
|
+
if (definedAt?.importPathAbsolute) {
|
|
81
|
+
const npmPackageName = getNpmPackageName(definedAt.importPathAbsolute);
|
|
82
|
+
if (npmPackageName && exclude.includes(npmPackageName))
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return exclude.includes(e);
|
|
44
86
|
};
|
|
45
87
|
// V1 design
|
|
46
88
|
{
|
|
@@ -52,22 +94,17 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
52
94
|
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
53
95
|
return;
|
|
54
96
|
const { definedAt, configEnv } = configValueSource;
|
|
55
|
-
if (!configEnv.client)
|
|
56
|
-
return;
|
|
57
97
|
if (definedAt.definedBy)
|
|
58
98
|
return;
|
|
59
|
-
if (definedAt.importPathAbsolute) {
|
|
60
|
-
const npmPackageName = getNpmPackageName(definedAt.importPathAbsolute);
|
|
61
|
-
if (npmPackageName && config.optimizeDeps.exclude?.includes(npmPackageName))
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
99
|
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
65
|
-
|
|
66
|
-
|
|
100
|
+
addEntry(
|
|
101
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
102
|
+
definedAt.filePathAbsoluteFilesystem, configEnv, definedAt);
|
|
67
103
|
}
|
|
68
104
|
else {
|
|
69
|
-
|
|
70
|
-
|
|
105
|
+
addInclude(
|
|
106
|
+
// optimizeDeps.include expects npm packages
|
|
107
|
+
definedAt.importPathAbsolute, configEnv, definedAt);
|
|
71
108
|
}
|
|
72
109
|
});
|
|
73
110
|
});
|
|
@@ -83,32 +120,39 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
83
120
|
addEntry(filePathAbsoluteFilesystem);
|
|
84
121
|
});
|
|
85
122
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
123
|
+
// Add virtual files.
|
|
124
|
+
// - This doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
125
|
+
// - Should we make it work? E.g. by creating a temporary file at node_modules/.vike/virtualFiles.js
|
|
126
|
+
// - Or should we remove it? And make sure getPageDeps() also works for aliased import paths
|
|
127
|
+
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
128
|
+
{
|
|
129
|
+
const { hasClientRouting, hasServerRouting, clientEntries } = analyzeClientEntries(pageConfigs, config);
|
|
130
|
+
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
131
|
+
if (hasClientRouting)
|
|
132
|
+
addEntry(virtualFileIdEntryClientCR);
|
|
133
|
+
if (hasServerRouting)
|
|
134
|
+
addEntry(virtualFileIdEntryClientSR);
|
|
135
|
+
}
|
|
136
|
+
entriesClient = entriesClient;
|
|
137
|
+
entriesServer = entriesServer;
|
|
138
|
+
includeClient = includeClient;
|
|
139
|
+
includeServer = includeServer;
|
|
140
|
+
return {
|
|
141
|
+
entriesClient,
|
|
142
|
+
entriesServer,
|
|
143
|
+
includeClient,
|
|
144
|
+
includeServer,
|
|
145
|
+
};
|
|
98
146
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
assert(false);
|
|
147
|
+
function add(input, listAddendum) {
|
|
148
|
+
const list = !input ? [] : isArray(input) ? unique(input) : [input];
|
|
149
|
+
listAddendum.forEach((e) => {
|
|
150
|
+
if (!list.includes(e))
|
|
151
|
+
list.push(e);
|
|
152
|
+
});
|
|
153
|
+
return list;
|
|
107
154
|
}
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (include === undefined)
|
|
112
|
-
return [];
|
|
113
|
-
assert(false);
|
|
155
|
+
function unique(arr) {
|
|
156
|
+
const arrUnique = Array.from(new Set(arr));
|
|
157
|
+
return arr.length !== arrUnique.length ? arrUnique : arr;
|
|
114
158
|
}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
// - This approach supports import path aliases `vite.config.js#resolve.alias` https://vitejs.dev/config/#resolve-alias
|
|
7
7
|
export { pluginExtractAssets };
|
|
8
8
|
export { extractAssetsRE };
|
|
9
|
-
import { assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage, rollupSourceMapRemove, } from '../utils.js';
|
|
10
|
-
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtualFiles.js';
|
|
9
|
+
import { assert, assertPosixPath, styleFileRE, createDebugger, isScriptFile, assertUsage, rollupSourceMapRemove, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, } from '../utils.js';
|
|
11
10
|
import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
12
11
|
import { isAsset } from '../shared/isAsset.js';
|
|
13
12
|
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
@@ -124,7 +123,7 @@ function pluginExtractAssets() {
|
|
|
124
123
|
load(id) {
|
|
125
124
|
if (!isVirtualFileId(id))
|
|
126
125
|
return undefined;
|
|
127
|
-
id =
|
|
126
|
+
id = removeVirtualFileIdPrefix(id);
|
|
128
127
|
if (id === EMPTY_MODULE_ID) {
|
|
129
128
|
return '// Erased by vike:pluginExtractAssets';
|
|
130
129
|
}
|
|
@@ -151,7 +150,7 @@ function pluginExtractAssets() {
|
|
|
151
150
|
}
|
|
152
151
|
function emptyModule(file, importer) {
|
|
153
152
|
debugOperation('NUKED', file, importer);
|
|
154
|
-
return
|
|
153
|
+
return addVirtualFileIdPrefix(EMPTY_MODULE_ID);
|
|
155
154
|
}
|
|
156
155
|
function appendExtractAssetsQuery(file, importer) {
|
|
157
156
|
debugOperation('TRANSFORMED', file, importer);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { pluginNonRunnableDev };
|
|
2
|
+
import type { Plugin, ViteDevServer } from 'vite';
|
|
3
|
+
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
4
|
+
export type ViteRPC = ReturnType<typeof getViteRpcFunctions>;
|
|
5
|
+
declare function getViteRpcFunctions(viteDevServer: ViteDevServer): {
|
|
6
|
+
transformIndexHtmlRPC(html: string): Promise<string>;
|
|
7
|
+
retrievePageAssetsDevRPC(clientDependencies: ClientDependency[], clientEntries: string[]): Promise<{
|
|
8
|
+
clientEntriesSrc: string[];
|
|
9
|
+
assetUrls: string[];
|
|
10
|
+
}>;
|
|
11
|
+
getViteConfigRuntimeRPC(): Promise<{
|
|
12
|
+
root: string;
|
|
13
|
+
build: {
|
|
14
|
+
outDir: string;
|
|
15
|
+
};
|
|
16
|
+
_baseViteOriginal: string;
|
|
17
|
+
vitePluginServerEntry: {
|
|
18
|
+
inject: boolean | undefined;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
declare global {
|
|
23
|
+
var __VIKE__DYNAMIC_IMPORT: (module: string) => Promise<Record<string, unknown>>;
|
|
24
|
+
var __VIKE__IS_NON_RUNNABLE_DEV: undefined | boolean;
|
|
25
|
+
}
|
|
26
|
+
declare function pluginNonRunnableDev(): Plugin;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export { pluginNonRunnableDev };
|
|
2
|
+
import { createViteRPC, assertIsNotProductionRuntime, requireResolveVikeDistFile, isRunnableDevEnvironment, } from '../utils.js';
|
|
3
|
+
import { resolveClientEntriesDev } from '../shared/resolveClientEntriesDev.js';
|
|
4
|
+
import { retrieveAssetsDev } from '../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js';
|
|
5
|
+
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
6
|
+
import { getMagicString } from '../shared/getMagicString.js';
|
|
7
|
+
assertIsNotProductionRuntime();
|
|
8
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
9
|
+
return {
|
|
10
|
+
async transformIndexHtmlRPC(html) {
|
|
11
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
12
|
+
},
|
|
13
|
+
// TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
|
|
14
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
15
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer));
|
|
16
|
+
const assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
17
|
+
return { clientEntriesSrc, assetUrls };
|
|
18
|
+
},
|
|
19
|
+
async getViteConfigRuntimeRPC() {
|
|
20
|
+
return getViteConfigRuntime(viteDevServer.config);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function pluginNonRunnableDev() {
|
|
25
|
+
const runtimeGlobalContextFilePath = requireResolveVikeDistFile('dist/esm/node/runtime/globalContext.js');
|
|
26
|
+
let config;
|
|
27
|
+
return {
|
|
28
|
+
name: 'vike:pluginNonRunnableDev',
|
|
29
|
+
configureServer(viteDevServer) {
|
|
30
|
+
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
31
|
+
},
|
|
32
|
+
configResolved(config_) {
|
|
33
|
+
config = config_;
|
|
34
|
+
},
|
|
35
|
+
transform(code, id) {
|
|
36
|
+
if (!config._isDev)
|
|
37
|
+
return;
|
|
38
|
+
if (id !== runtimeGlobalContextFilePath)
|
|
39
|
+
return;
|
|
40
|
+
const isNonRunnableDev = !isRunnableDevEnvironment(this.environment);
|
|
41
|
+
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
42
|
+
if (isNonRunnableDev) {
|
|
43
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
44
|
+
}
|
|
45
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
|
|
46
|
+
return getMagicStringResult();
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigLazy };
|
|
2
|
+
// TODO/now: rename file to generateVirtualFileEntryPage.ts
|
|
2
3
|
import { assert, getProjectError } from '../../utils.js';
|
|
3
4
|
import { getVirtualFileIdPageConfigLazy, isVirtualFileIdPageConfigLazy, } from '../../../shared/virtualFiles/virtualFilePageConfigLazy.js';
|
|
4
5
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
@@ -19,6 +19,10 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
19
19
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
20
20
|
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv));
|
|
21
21
|
lines.push('};');
|
|
22
|
+
if (!isForClientSide && isDev) {
|
|
23
|
+
// https://vite.dev/guide/api-environment-frameworks.html
|
|
24
|
+
lines.push('if (import.meta.hot) import.meta.hot.accept();');
|
|
25
|
+
}
|
|
22
26
|
const code = [...importStatements, ...lines].join('\n');
|
|
23
27
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
24
28
|
return code;
|
|
@@ -2,8 +2,7 @@ export { pluginVirtualFiles };
|
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
3
|
import { getVirtualFilePageConfigLazy } from './pluginVirtualFiles/getVirtualFilePageConfigLazy.js';
|
|
4
4
|
import { getVirtualFileEntry } from './pluginVirtualFiles/getVirtualFileEntry.js';
|
|
5
|
-
import { assert, assertPosixPath, isScriptFile } from '../utils.js';
|
|
6
|
-
import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../shared/virtualFiles.js';
|
|
5
|
+
import { assert, assertPosixPath, isScriptFile, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, } from '../utils.js';
|
|
7
6
|
import { isVirtualFileIdPageConfigLazy } from '../../shared/virtualFiles/virtualFilePageConfigLazy.js';
|
|
8
7
|
import { isVirtualFileIdEntry } from '../../shared/virtualFiles/virtualFileEntry.js';
|
|
9
8
|
import { reloadVikeConfig, isV1Design, getVikeConfigInternalOptional } from '../shared/resolveVikeConfigInternal.js';
|
|
@@ -26,7 +25,7 @@ function pluginVirtualFiles() {
|
|
|
26
25
|
},
|
|
27
26
|
resolveId(id) {
|
|
28
27
|
if (isVirtualFileId(id)) {
|
|
29
|
-
return
|
|
28
|
+
return addVirtualFileIdPrefix(id);
|
|
30
29
|
}
|
|
31
30
|
},
|
|
32
31
|
async handleHotUpdate(ctx) {
|
|
@@ -42,7 +41,7 @@ function pluginVirtualFiles() {
|
|
|
42
41
|
async load(id, options) {
|
|
43
42
|
if (!isVirtualFileId(id))
|
|
44
43
|
return undefined;
|
|
45
|
-
id =
|
|
44
|
+
id = removeVirtualFileIdPrefix(id);
|
|
46
45
|
const isDev = config._isDev;
|
|
47
46
|
assert(typeof isDev === 'boolean');
|
|
48
47
|
if (isVirtualFileIdPageConfigLazy(id)) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { getMagicString };
|
|
2
|
+
import MagicString from 'magic-string';
|
|
3
|
+
// TODO/now use everywhere
|
|
4
|
+
function getMagicString(code, id) {
|
|
5
|
+
const magicString = new MagicString(code);
|
|
6
|
+
const getMagicStringResult = () => {
|
|
7
|
+
return {
|
|
8
|
+
code: magicString.toString(),
|
|
9
|
+
map: magicString.generateMap({ hires: true, source: id }),
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
return { magicString, getMagicStringResult };
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { getManifestFilePathRelative };
|
|
2
|
+
import { assert } from '../utils.js';
|
|
3
|
+
function getManifestFilePathRelative(manifestConfig) {
|
|
4
|
+
assert(['string', 'boolean'].includes(typeof manifestConfig));
|
|
5
|
+
assert(manifestConfig !== false);
|
|
6
|
+
const manifestFileRelative = typeof manifestConfig === 'string' ? manifestConfig : '.vite/manifest.json';
|
|
7
|
+
return manifestFileRelative;
|
|
8
|
+
}
|
|
@@ -9,10 +9,10 @@ import type { GlobalContextServerInternal } from '../node/runtime/globalContext.
|
|
|
9
9
|
import type { GlobalContextClientInternal } from '../client/runtime-client-routing/globalContext.js';
|
|
10
10
|
import { type Hook } from './hooks/getHook.js';
|
|
11
11
|
declare const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
12
|
-
declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
|
|
12
|
+
declare function createGlobalContextShared<GlobalContextAdded extends Record<string, any>, GlobalContextAddedAsync extends Record<string, any>>(virtualFileExports: unknown, globalObject: {
|
|
13
13
|
globalContext?: Record<string, unknown>;
|
|
14
14
|
onCreateGlobalContextHooks?: Hook[];
|
|
15
|
-
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>): Promise<{
|
|
15
|
+
}, addGlobalContext?: (globalContext: GlobalContextBase) => GlobalContextAdded, addGlobalContextTmp?: (globalContext: GlobalContextBase) => Promise<GlobalContextAdded>, addGlobalContextAsync?: (globalContext: GlobalContextBase) => Promise<GlobalContextAddedAsync>): Promise<{
|
|
16
16
|
/**
|
|
17
17
|
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
18
18
|
*
|
|
@@ -35,7 +35,7 @@ declare function createGlobalContextShared<GlobalContextAdded extends Record<str
|
|
|
35
35
|
pages: {
|
|
36
36
|
[k: string]: import("./page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
|
|
37
37
|
};
|
|
38
|
-
} & GlobalContextAdded>;
|
|
38
|
+
} & GlobalContextAdded & GlobalContextAddedAsync>;
|
|
39
39
|
type GlobalContextBasePublic = Pick<GlobalContextBase, 'config' | 'pages' | 'isGlobalContext'>;
|
|
40
40
|
type GlobalContextBase = ReturnType<typeof createGlobalContextBase>;
|
|
41
41
|
declare function createGlobalContextBase(virtualFileExports: unknown): {
|
|
@@ -9,7 +9,7 @@ import { getHookFromPageConfigGlobalCumulative } from './hooks/getHook.js';
|
|
|
9
9
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
10
10
|
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
|
|
11
11
|
// TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
|
|
12
|
-
addGlobalContextTmp) {
|
|
12
|
+
addGlobalContextTmp, addGlobalContextAsync) {
|
|
13
13
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
14
14
|
let isNewGlobalContext;
|
|
15
15
|
if (!globalObject.globalContext) {
|
|
@@ -31,6 +31,10 @@ addGlobalContextTmp) {
|
|
|
31
31
|
const globalContextAdded = await addGlobalContextTmp?.(globalContext);
|
|
32
32
|
objectAssign(globalContext, globalContextAdded);
|
|
33
33
|
}
|
|
34
|
+
{
|
|
35
|
+
const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
|
|
36
|
+
objectAssign(globalContext, globalContextAddedAsync);
|
|
37
|
+
}
|
|
34
38
|
const onCreateGlobalContextHooks = getHookFromPageConfigGlobalCumulative(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
|
|
35
39
|
let hooksCalled = false;
|
|
36
40
|
if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export { parseVirtualFileExports };
|
|
2
|
+
// TODO/now: rename parseVirtualFileExportsEntryGlobal
|
|
3
|
+
// TODO/now: merge or collocate following both files?
|
|
4
|
+
// ```filesystem
|
|
5
|
+
// vike/packages/vike/shared/getPageFiles/parseVirtualFileExports.ts
|
|
6
|
+
// vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
7
|
+
// ```
|
|
2
8
|
// TO-DO/next-major-release: remove old design code, and remove all assertions.
|
|
3
9
|
import { assert, hasProp, isCallable, isObject, cast, isArray } from '../utils.js';
|
|
4
10
|
import { assertExportValues } from './assert_exports_old_design.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.236-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.236-commit-79f1ef0";
|