vike 0.4.239-commit-050a4a3 → 0.4.239-commit-33e55d4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/prerender/runPrerender.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +9 -0
- package/dist/cjs/node/vite/onLoad.js +1 -1
- package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +13 -7
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +4 -5
- package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +9 -5
- package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +11 -5
- package/dist/cjs/node/vite/plugins/pluginFileEnv.js +43 -30
- package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +19 -7
- package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +23 -5
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +12 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/virtualFileId.js +15 -11
- 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/renderPageClientSide.d.ts +1 -1
- 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/node/prerender/runPrerender.d.ts +4 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +13 -2
- package/dist/esm/node/runtime/globalContext.js +10 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +8 -4
- package/dist/esm/node/runtime/renderPage.d.ts +4 -2
- package/dist/esm/node/vite/onLoad.js +1 -1
- package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +14 -8
- package/dist/esm/node/vite/plugins/pluginEnvVars.js +4 -5
- package/dist/esm/node/vite/plugins/pluginExtractAssets.js +9 -3
- package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +11 -5
- package/dist/esm/node/vite/plugins/pluginFileEnv.js +43 -30
- package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +20 -8
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
- package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +22 -5
- package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +13 -8
- package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/virtualFileId.d.ts +4 -0
- package/dist/esm/utils/virtualFileId.js +14 -11
- package/package.json +4 -4
|
@@ -10,6 +10,7 @@ export { initGlobalContext_getPagesAndRoutes };
|
|
|
10
10
|
export { setGlobalContext_viteDevServer };
|
|
11
11
|
export { setGlobalContext_viteConfig };
|
|
12
12
|
export { setGlobalContext_isPrerendering };
|
|
13
|
+
export { setGlobalContext_prerenderContext };
|
|
13
14
|
export { setGlobalContext_isProductionAccordingToVite };
|
|
14
15
|
export { setGlobalContext_prodBuildEntry };
|
|
15
16
|
export { clearGlobalContext };
|
|
@@ -26,6 +27,7 @@ import { type PageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
|
26
27
|
import type { ViteConfigRuntime } from '../vite/shared/getViteConfigRuntime.js';
|
|
27
28
|
import type { GlobalContext } from '../../types/PageContext.js';
|
|
28
29
|
import type { Hook } from '../../shared/hooks/getHook.js';
|
|
30
|
+
import type { PrerenderContext } from '../../types/index.js';
|
|
29
31
|
declare const vikeConfigErrorRecoverMsg: "Vike config loaded";
|
|
30
32
|
type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextServer;
|
|
31
33
|
type GlobalContextServerInternal = Awaited<ReturnType<typeof createGlobalContext>>;
|
|
@@ -98,6 +100,8 @@ declare function getGlobalContextServerInternal(): Promise<{
|
|
|
98
100
|
inject: boolean | undefined;
|
|
99
101
|
};
|
|
100
102
|
};
|
|
103
|
+
} & {
|
|
104
|
+
prerenderContext: PrerenderContext | undefined;
|
|
101
105
|
}) | (Record<string, unknown> & {
|
|
102
106
|
_globalConfigPublic: {
|
|
103
107
|
pages: {
|
|
@@ -167,6 +171,8 @@ declare function getGlobalContextServerInternal(): Promise<{
|
|
|
167
171
|
inject: boolean | undefined;
|
|
168
172
|
};
|
|
169
173
|
};
|
|
174
|
+
} & {
|
|
175
|
+
prerenderContext: PrerenderContext | undefined;
|
|
170
176
|
}) | (Record<string, unknown> & {
|
|
171
177
|
_globalConfigPublic: {
|
|
172
178
|
pages: {
|
|
@@ -236,6 +242,8 @@ declare function getGlobalContextServerInternal(): Promise<{
|
|
|
236
242
|
inject: boolean | undefined;
|
|
237
243
|
};
|
|
238
244
|
};
|
|
245
|
+
} & {
|
|
246
|
+
prerenderContext: PrerenderContext | undefined;
|
|
239
247
|
});
|
|
240
248
|
}>;
|
|
241
249
|
/**
|
|
@@ -259,6 +267,7 @@ declare function getGlobalContextSync(): GlobalContext;
|
|
|
259
267
|
declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): Promise<void>;
|
|
260
268
|
declare function setGlobalContext_viteConfig(viteConfig: ResolvedConfig, viteConfigRuntime: ViteConfigRuntime): void;
|
|
261
269
|
declare function setGlobalContext_isPrerendering(): void;
|
|
270
|
+
declare function setGlobalContext_prerenderContext(prerenderContextPublic: PrerenderContext): void;
|
|
262
271
|
declare function setGlobalContext_isProductionAccordingToVite(isProductionAccordingToVite: boolean): void;
|
|
263
272
|
declare function getViteDevServer(): ViteDevServer | null;
|
|
264
273
|
declare function getViteConfig(): ResolvedConfig | null;
|
|
@@ -275,7 +284,7 @@ declare function assertBuildInfo(buildInfo: unknown): asserts buildInfo is Build
|
|
|
275
284
|
declare function updateUserFiles(): Promise<{
|
|
276
285
|
success: boolean;
|
|
277
286
|
}>;
|
|
278
|
-
declare function createGlobalContext(virtualFileExportsGlobalEntry: unknown): Promise<{
|
|
287
|
+
declare function createGlobalContext(virtualFileExportsGlobalEntry: unknown): Promise<({
|
|
279
288
|
_globalConfigPublic: {
|
|
280
289
|
pages: {
|
|
281
290
|
[k: string]: {
|
|
@@ -363,6 +372,8 @@ declare function createGlobalContext(virtualFileExportsGlobalEntry: unknown): Pr
|
|
|
363
372
|
inject: boolean | undefined;
|
|
364
373
|
};
|
|
365
374
|
};
|
|
366
|
-
})
|
|
375
|
+
})) & {
|
|
376
|
+
prerenderContext: PrerenderContext | undefined;
|
|
377
|
+
}>;
|
|
367
378
|
declare function clearGlobalContext(): void;
|
|
368
379
|
declare function isRunnable(viteDevServer: ViteDevServer): boolean;
|
|
@@ -12,6 +12,7 @@ export { initGlobalContext_getPagesAndRoutes };
|
|
|
12
12
|
export { setGlobalContext_viteDevServer };
|
|
13
13
|
export { setGlobalContext_viteConfig };
|
|
14
14
|
export { setGlobalContext_isPrerendering };
|
|
15
|
+
export { setGlobalContext_prerenderContext };
|
|
15
16
|
export { setGlobalContext_isProductionAccordingToVite };
|
|
16
17
|
export { setGlobalContext_prodBuildEntry }; // production entry
|
|
17
18
|
export { clearGlobalContext };
|
|
@@ -27,7 +28,7 @@ export { vikeConfigErrorRecoverMsg };
|
|
|
27
28
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
28
29
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
29
30
|
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
|
|
30
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, } from './utils.js';
|
|
31
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, objectAssign, } from './utils.js';
|
|
31
32
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
32
33
|
import { virtualFileIdGlobalEntryServer } from '../shared/virtualFileId.js';
|
|
33
34
|
import pc from '@brillout/picocolors';
|
|
@@ -150,6 +151,13 @@ function assertIsNotInitializedYet() {
|
|
|
150
151
|
function setGlobalContext_isPrerendering() {
|
|
151
152
|
globalObject.isPrerendering = true;
|
|
152
153
|
}
|
|
154
|
+
function setGlobalContext_prerenderContext(prerenderContextPublic) {
|
|
155
|
+
globalObject.prerenderContextPublic = prerenderContextPublic;
|
|
156
|
+
// Ugly redundancy, which we can remove after globalContext is a proxy
|
|
157
|
+
const { globalContext } = globalObjectTyped;
|
|
158
|
+
if (globalContext)
|
|
159
|
+
globalContext.prerenderContext = prerenderContextPublic;
|
|
160
|
+
}
|
|
153
161
|
function setGlobalContext_isProductionAccordingToVite(isProductionAccordingToVite) {
|
|
154
162
|
globalObject.isProductionAccordingToVite = isProductionAccordingToVite;
|
|
155
163
|
}
|
|
@@ -401,6 +409,7 @@ async function createGlobalContext(virtualFileExportsGlobalEntry) {
|
|
|
401
409
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
402
410
|
assertGlobalContextIsDefined();
|
|
403
411
|
onSetupRuntime();
|
|
412
|
+
objectAssign(globalContext, { prerenderContext: globalObject.prerenderContextPublic });
|
|
404
413
|
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
405
414
|
return globalContext;
|
|
406
415
|
}
|
|
@@ -23,7 +23,7 @@ declare function createPageContextServerSide(pageContextInit: PageContextInit, g
|
|
|
23
23
|
url?: string;
|
|
24
24
|
headers?: Record<string, string>;
|
|
25
25
|
} & {
|
|
26
|
-
_globalContext: {
|
|
26
|
+
_globalContext: ({
|
|
27
27
|
_globalConfigPublic: {
|
|
28
28
|
pages: {
|
|
29
29
|
[k: string]: {
|
|
@@ -111,7 +111,9 @@ declare function createPageContextServerSide(pageContextInit: PageContextInit, g
|
|
|
111
111
|
inject: boolean | undefined;
|
|
112
112
|
};
|
|
113
113
|
};
|
|
114
|
-
})
|
|
114
|
+
})) & {
|
|
115
|
+
prerenderContext: import("../../prerender/runPrerender.js").PrerenderContextPublic | undefined;
|
|
116
|
+
};
|
|
115
117
|
_pageFilesAll: import("../../../shared/getPageFiles.js").PageFile[];
|
|
116
118
|
_baseServer: string;
|
|
117
119
|
_baseAssets: string;
|
|
@@ -24,7 +24,7 @@ declare function loadPageConfigsLazyServerSide(pageContext: PageContext_loadPage
|
|
|
24
24
|
url?: string;
|
|
25
25
|
headers?: Record<string, string>;
|
|
26
26
|
} & {
|
|
27
|
-
_globalContext: {
|
|
27
|
+
_globalContext: ({
|
|
28
28
|
_globalConfigPublic: {
|
|
29
29
|
pages: {
|
|
30
30
|
[k: string]: {
|
|
@@ -112,7 +112,9 @@ declare function loadPageConfigsLazyServerSide(pageContext: PageContext_loadPage
|
|
|
112
112
|
inject: boolean | undefined;
|
|
113
113
|
};
|
|
114
114
|
};
|
|
115
|
-
})
|
|
115
|
+
})) & {
|
|
116
|
+
prerenderContext: import("../../prerender/runPrerender.js").PrerenderContextPublic | undefined;
|
|
117
|
+
};
|
|
116
118
|
_pageFilesAll: import("../../../shared/getPageFiles.js").PageFile[];
|
|
117
119
|
_baseServer: string;
|
|
118
120
|
_baseAssets: string;
|
|
@@ -39,7 +39,7 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
39
39
|
url?: string;
|
|
40
40
|
headers?: Record<string, string>;
|
|
41
41
|
} & {
|
|
42
|
-
_globalContext: {
|
|
42
|
+
_globalContext: ({
|
|
43
43
|
_globalConfigPublic: {
|
|
44
44
|
pages: {
|
|
45
45
|
[k: string]: {
|
|
@@ -127,7 +127,9 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
127
127
|
inject: boolean | undefined;
|
|
128
128
|
};
|
|
129
129
|
};
|
|
130
|
-
})
|
|
130
|
+
})) & {
|
|
131
|
+
prerenderContext: import("../../prerender/runPrerender.js").PrerenderContextPublic | undefined;
|
|
132
|
+
};
|
|
131
133
|
_pageFilesAll: import("../../../shared/getPageFiles.js").PageFile[];
|
|
132
134
|
_baseServer: string;
|
|
133
135
|
_baseAssets: string;
|
|
@@ -201,7 +203,7 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
201
203
|
url?: string;
|
|
202
204
|
headers?: Record<string, string>;
|
|
203
205
|
} & {
|
|
204
|
-
_globalContext: {
|
|
206
|
+
_globalContext: ({
|
|
205
207
|
_globalConfigPublic: {
|
|
206
208
|
pages: {
|
|
207
209
|
[k: string]: {
|
|
@@ -289,7 +291,9 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
289
291
|
inject: boolean | undefined;
|
|
290
292
|
};
|
|
291
293
|
};
|
|
292
|
-
})
|
|
294
|
+
})) & {
|
|
295
|
+
prerenderContext: import("../../prerender/runPrerender.js").PrerenderContextPublic | undefined;
|
|
296
|
+
};
|
|
293
297
|
_pageFilesAll: import("../../../shared/getPageFiles.js").PageFile[];
|
|
294
298
|
_baseServer: string;
|
|
295
299
|
_baseAssets: string;
|
|
@@ -31,7 +31,7 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
|
|
|
31
31
|
/** @deprecated Set `pageContextInit.urlOriginal` instead */ url?: string;
|
|
32
32
|
/** @deprecated Set pageContextInit.headersOriginal instead */ headers?: Record<string, string>;
|
|
33
33
|
} & {
|
|
34
|
-
_globalContext: {
|
|
34
|
+
_globalContext: ({
|
|
35
35
|
_globalConfigPublic: {
|
|
36
36
|
pages: {
|
|
37
37
|
[k: string]: {
|
|
@@ -119,7 +119,9 @@ declare function getPageContextBegin(pageContextInit: PageContextInit, globalCon
|
|
|
119
119
|
inject: boolean | undefined;
|
|
120
120
|
};
|
|
121
121
|
};
|
|
122
|
-
})
|
|
122
|
+
})) & {
|
|
123
|
+
prerenderContext: import("../prerender/runPrerender.js").PrerenderContextPublic | undefined;
|
|
124
|
+
};
|
|
123
125
|
_pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
|
|
124
126
|
_baseServer: string;
|
|
125
127
|
_baseAssets: string;
|
|
@@ -13,7 +13,7 @@ function onLoad() {
|
|
|
13
13
|
// TO-DO/eventually: let's also use this.meta.viteVersion
|
|
14
14
|
// - https://github.com/vitejs/vite/pull/20088
|
|
15
15
|
// - https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
|
|
16
|
-
assertVersion('Vite', version, ['6.
|
|
16
|
+
assertVersion('Vite', version, ['6.3.0']);
|
|
17
17
|
// Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
|
|
18
18
|
assertIsNotProductionRuntime();
|
|
19
19
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { pluginModuleBanner };
|
|
2
|
-
import { removeVirtualFileIdPrefix } from '../../utils.js';
|
|
2
|
+
import { assert, removeVirtualFileIdPrefix } from '../../utils.js';
|
|
3
3
|
import { getMagicString } from '../../shared/getMagicString.js';
|
|
4
|
-
import { isViteServerSide_extraSafe } from '../../shared/isViteServerSide.js';
|
|
5
4
|
// Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
|
|
6
5
|
// 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
6
|
function pluginModuleBanner() {
|
|
@@ -10,6 +9,13 @@ function pluginModuleBanner() {
|
|
|
10
9
|
name: 'vike:build:pluginModuleBanner',
|
|
11
10
|
enforce: 'post',
|
|
12
11
|
apply: 'build',
|
|
12
|
+
applyToEnvironment(environment) {
|
|
13
|
+
const { config } = environment;
|
|
14
|
+
const { consumer } = config;
|
|
15
|
+
const { minify } = config.build;
|
|
16
|
+
assert(minify === false || minify, { minify, consumer });
|
|
17
|
+
return !minify;
|
|
18
|
+
},
|
|
13
19
|
configResolved: {
|
|
14
20
|
handler(config_) {
|
|
15
21
|
config = config_;
|
|
@@ -17,12 +23,12 @@ function pluginModuleBanner() {
|
|
|
17
23
|
},
|
|
18
24
|
transform: {
|
|
19
25
|
order: 'post',
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
+
/* Using a Rolldown hook filter doesn't make sense here — we use applyToEnvironment() to conditionally apply this plugin.
|
|
27
|
+
filter: {},
|
|
28
|
+
*/
|
|
29
|
+
handler(code, id) {
|
|
30
|
+
const { minify } = this.environment.config.build;
|
|
31
|
+
assert(minify === false, { minify });
|
|
26
32
|
if (id.startsWith('\0'))
|
|
27
33
|
id = id;
|
|
28
34
|
id = removeVirtualFileIdPrefix(id);
|
|
@@ -5,6 +5,7 @@ import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
|
5
5
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
6
6
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
7
7
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
8
|
+
import { filterRolldown, filterFunction } from './pluginReplaceConstants.js';
|
|
8
9
|
// TO-DO/eventually:
|
|
9
10
|
// - Make import.meta.env work inside +config.js
|
|
10
11
|
// - 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
|
|
@@ -28,16 +29,14 @@ function pluginEnvVars() {
|
|
|
28
29
|
},
|
|
29
30
|
},
|
|
30
31
|
transform: {
|
|
32
|
+
filter: filterRolldown,
|
|
31
33
|
handler(code, id, options) {
|
|
32
34
|
id = normalizeId(id);
|
|
33
35
|
assertPosixPath(id);
|
|
34
|
-
if (id.includes('/node_modules/'))
|
|
35
|
-
return;
|
|
36
36
|
assertPosixPath(config.root);
|
|
37
37
|
if (!id.startsWith(config.root))
|
|
38
|
-
return;
|
|
39
|
-
|
|
40
|
-
return;
|
|
38
|
+
return; // skip linked dependencies
|
|
39
|
+
assert(filterFunction(id, code));
|
|
41
40
|
const isBuild = config.command === 'build';
|
|
42
41
|
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
43
42
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// TO-DO/next-major-release: remove
|
|
1
2
|
// Remove this workaround if the other workaround config.build.ssrEmitAssets turns out to be reliable.
|
|
2
3
|
// - Remove this file then revert this commit: https://github.com/vikejs/vike/commit/805a18974f13420a78fcc30fdd676696e405c3ca
|
|
3
4
|
// Workaround to make client-side bundles include the CSS imports living in server-side-only code.
|
|
@@ -22,6 +23,12 @@ const rawRE = /(\?|&)raw(?:&|$)/;
|
|
|
22
23
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
23
24
|
const EMPTY_MODULE_ID = 'virtual:vike:empty-module';
|
|
24
25
|
const debug = createDebugger('vike:pluginExtractAssets');
|
|
26
|
+
const filterRolldown = {
|
|
27
|
+
id: {
|
|
28
|
+
include: extractAssetsRE,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
const filterFunction = (id) => extractAssetsRE.test(id);
|
|
25
32
|
function pluginExtractAssets() {
|
|
26
33
|
let config;
|
|
27
34
|
let vikeConfig;
|
|
@@ -34,11 +41,10 @@ function pluginExtractAssets() {
|
|
|
34
41
|
apply: 'build',
|
|
35
42
|
enforce: 'post',
|
|
36
43
|
transform: {
|
|
44
|
+
filter: filterRolldown,
|
|
37
45
|
async handler(src, id, options) {
|
|
38
46
|
id = normalizeId(id);
|
|
39
|
-
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
47
|
+
assert(filterFunction(id));
|
|
42
48
|
if (isFixEnabled) {
|
|
43
49
|
// I'm guessing isFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
44
50
|
assertV1Design(vikeConfig._pageConfigs, true);
|
|
@@ -8,6 +8,12 @@ import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
|
8
8
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
9
9
|
const debug = createDebugger('vike:pluginExtractExportNames');
|
|
10
10
|
const globalObject = getGlobalObject('plugins/pluginExtractExportNames.ts', {});
|
|
11
|
+
const filterRolldown = {
|
|
12
|
+
id: {
|
|
13
|
+
include: extractExportNamesRE,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
const filterFunction = (id) => extractExportNamesRE.test(id);
|
|
11
17
|
function pluginExtractExportNames() {
|
|
12
18
|
let isDev = false;
|
|
13
19
|
let config;
|
|
@@ -15,14 +21,14 @@ function pluginExtractExportNames() {
|
|
|
15
21
|
name: 'vike:pluginExtractExportNames',
|
|
16
22
|
enforce: 'post',
|
|
17
23
|
transform: {
|
|
24
|
+
filter: filterRolldown,
|
|
18
25
|
async handler(src, id, options) {
|
|
19
26
|
id = normalizeId(id);
|
|
20
27
|
const isClientSide = !isViteServerSide_extraSafe(config, this.environment, options);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
28
|
+
assert(filterFunction(id));
|
|
29
|
+
const code = await getExtractExportNamesCode(src, isClientSide, !isDev, id);
|
|
30
|
+
debug('id ' + id, ['result:\n' + code.code.trim(), 'src:\n' + src.trim()]);
|
|
31
|
+
return code;
|
|
26
32
|
},
|
|
27
33
|
},
|
|
28
34
|
configureServer: {
|
|
@@ -8,19 +8,34 @@ import { getExportNames } from '../shared/parseEsModule.js';
|
|
|
8
8
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
9
9
|
import { isV1Design } from '../shared/resolveVikeConfigInternal.js';
|
|
10
10
|
import { isViteServerSide, isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
11
|
+
const skipNodeModules = '/node_modules/'; // Only apply `.server.js` and `.client.js` to user files
|
|
12
|
+
const filterRolldown = {
|
|
13
|
+
id: {
|
|
14
|
+
include: ['client', 'server'].map((env) => `**/*${getSuffix(env)}*`),
|
|
15
|
+
exclude: [`**${skipNodeModules}**`],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filterFunction = (id) => {
|
|
19
|
+
if (id.includes(skipNodeModules))
|
|
20
|
+
return false;
|
|
21
|
+
if (!id.includes(getSuffix('client')) && !id.includes(getSuffix('server')))
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
11
25
|
function pluginFileEnv() {
|
|
12
26
|
let config;
|
|
13
27
|
let viteDevServer;
|
|
14
28
|
return {
|
|
15
29
|
name: 'vike:pluginFileEnv',
|
|
16
30
|
load: {
|
|
31
|
+
filter: filterRolldown,
|
|
17
32
|
handler(id, options) {
|
|
18
33
|
// In build, we use generateBundle() instead of the load() hook. Using load() works for dynamic imports in dev thanks to Vite's lazy transpiling, but it doesn't work in build because Rollup transpiles any dynamically imported module even if it's never actually imported.
|
|
19
34
|
if (!viteDevServer)
|
|
20
35
|
return;
|
|
21
36
|
if (!isV1Design())
|
|
22
37
|
return;
|
|
23
|
-
if (skip(id))
|
|
38
|
+
if (skip(id, config.root))
|
|
24
39
|
return;
|
|
25
40
|
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
26
41
|
if (id.endsWith('?direct'))
|
|
@@ -37,12 +52,13 @@ function pluginFileEnv() {
|
|
|
37
52
|
},
|
|
38
53
|
// In production, we have to use transform() to replace modules with a runtime error because generateBundle() doesn't work for dynamic imports. In production, dynamic imports can only be verified at runtime.
|
|
39
54
|
transform: {
|
|
55
|
+
filter: filterRolldown,
|
|
40
56
|
async handler(code, id, options) {
|
|
41
57
|
id = normalizeId(id);
|
|
42
58
|
// In dev, only using load() is enough as it also works for dynamic imports (see sibling comment).
|
|
43
59
|
if (viteDevServer)
|
|
44
60
|
return;
|
|
45
|
-
if (skip(id))
|
|
61
|
+
if (skip(id, config.root))
|
|
46
62
|
return;
|
|
47
63
|
const isServerSide = isViteServerSide_extraSafe(config, this.environment, options);
|
|
48
64
|
if (!isWrongEnv(id, isServerSide))
|
|
@@ -61,7 +77,8 @@ function pluginFileEnv() {
|
|
|
61
77
|
generateBundle: {
|
|
62
78
|
handler() {
|
|
63
79
|
Array.from(this.getModuleIds())
|
|
64
|
-
.filter(
|
|
80
|
+
.filter(filterFunction)
|
|
81
|
+
.filter((id) => !skip(id, config.root))
|
|
65
82
|
.forEach((moduleId) => {
|
|
66
83
|
const mod = this.getModuleInfo(moduleId);
|
|
67
84
|
const { importers } = mod;
|
|
@@ -124,31 +141,27 @@ function pluginFileEnv() {
|
|
|
124
141
|
}
|
|
125
142
|
return errMsg;
|
|
126
143
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
function getModulePath(moduleId) {
|
|
152
|
-
return moduleId.split('?')[0];
|
|
153
|
-
}
|
|
144
|
+
}
|
|
145
|
+
function isWrongEnv(moduleId, isServerSide) {
|
|
146
|
+
const modulePath = getModulePath(moduleId);
|
|
147
|
+
const suffixWrong = getSuffix(isServerSide ? 'client' : 'server');
|
|
148
|
+
return modulePath.includes(suffixWrong);
|
|
149
|
+
}
|
|
150
|
+
function skip(id, userRootDir) {
|
|
151
|
+
assert(filterFunction(id));
|
|
152
|
+
// TO-DO/next-major-release: remove
|
|
153
|
+
if (extractAssetsRE.test(id) || extractExportNamesRE.test(id))
|
|
154
|
+
return true;
|
|
155
|
+
if (getModulePath(id).endsWith('.css'))
|
|
156
|
+
return true;
|
|
157
|
+
// Skip linked dependencies
|
|
158
|
+
if (!id.startsWith(userRootDir))
|
|
159
|
+
return true;
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
function getSuffix(env) {
|
|
163
|
+
return `.${env}.`;
|
|
164
|
+
}
|
|
165
|
+
function getModulePath(moduleId) {
|
|
166
|
+
return moduleId.split('?')[0];
|
|
154
167
|
}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
export { pluginNonRunnableDev };
|
|
2
|
-
import { createViteRPC, assertIsNotProductionRuntime, requireResolveDistFile, isRunnableDevEnvironment, } from '../utils.js';
|
|
2
|
+
import { createViteRPC, assertIsNotProductionRuntime, requireResolveDistFile, isRunnableDevEnvironment, assert, escapeRegex, isDevCheck, } from '../utils.js';
|
|
3
3
|
import { retrievePageAssetsDev } from '../../runtime/renderPage/getPageAssets/retrievePageAssetsDev.js';
|
|
4
4
|
import { getViteConfigRuntime } from '../shared/getViteConfigRuntime.js';
|
|
5
5
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
6
6
|
assertIsNotProductionRuntime();
|
|
7
|
+
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js');
|
|
8
|
+
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js');
|
|
9
|
+
const filterRolldown = {
|
|
10
|
+
id: {
|
|
11
|
+
include: [distFileIsNonRunnableDev, distFileGlobalContext].map((filePath) => new RegExp(`^${escapeRegex(filePath)}($|${escapeRegex('?')}.*)`)),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const filterFunction = (id) => {
|
|
15
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
16
|
+
return idWithoutQuery === distFileIsNonRunnableDev || idWithoutQuery === distFileGlobalContext;
|
|
17
|
+
};
|
|
7
18
|
function getViteRpcFunctions(viteDevServer) {
|
|
8
19
|
return {
|
|
9
20
|
async transformIndexHtmlRPC(html) {
|
|
@@ -18,11 +29,10 @@ function getViteRpcFunctions(viteDevServer) {
|
|
|
18
29
|
};
|
|
19
30
|
}
|
|
20
31
|
function pluginNonRunnableDev() {
|
|
21
|
-
const distFileIsNonRunnableDev = requireResolveDistFile('dist/esm/utils/isNonRunnableDev.js');
|
|
22
|
-
const distFileGlobalContext = requireResolveDistFile('dist/esm/node/runtime/globalContext.js');
|
|
23
32
|
let config;
|
|
24
33
|
return {
|
|
25
34
|
name: 'vike:pluginNonRunnableDev',
|
|
35
|
+
apply: (_, configEnv) => isDevCheck(configEnv),
|
|
26
36
|
configureServer: {
|
|
27
37
|
handler(viteDevServer) {
|
|
28
38
|
createViteRPC(viteDevServer, getViteRpcFunctions);
|
|
@@ -34,12 +44,11 @@ function pluginNonRunnableDev() {
|
|
|
34
44
|
},
|
|
35
45
|
},
|
|
36
46
|
transform: {
|
|
47
|
+
filter: filterRolldown,
|
|
37
48
|
handler(code, id) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const idWithoutQuery = id
|
|
41
|
-
if (idWithoutQuery !== distFileIsNonRunnableDev && idWithoutQuery !== distFileGlobalContext)
|
|
42
|
-
return;
|
|
49
|
+
assert(config._isDev);
|
|
50
|
+
assert(filterFunction(id));
|
|
51
|
+
const idWithoutQuery = getIdWithoutQuery(id);
|
|
43
52
|
if (isRunnableDevEnvironment(this.environment))
|
|
44
53
|
return;
|
|
45
54
|
const { magicString, getMagicStringResult } = getMagicString(code, id);
|
|
@@ -54,3 +63,6 @@ function pluginNonRunnableDev() {
|
|
|
54
63
|
},
|
|
55
64
|
};
|
|
56
65
|
}
|
|
66
|
+
function getIdWithoutQuery(id) {
|
|
67
|
+
return id.split('?')[0];
|
|
68
|
+
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export { pluginReplaceConstants };
|
|
2
|
+
export { filterFunction };
|
|
3
|
+
export { filterRolldown };
|
|
2
4
|
import type { Plugin } from 'vite';
|
|
5
|
+
declare const filterRolldown: {
|
|
6
|
+
id: {
|
|
7
|
+
exclude: string;
|
|
8
|
+
};
|
|
9
|
+
code: {
|
|
10
|
+
include: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
declare const filterFunction: (id: string, code: string) => boolean;
|
|
3
14
|
declare function pluginReplaceConstants(): Plugin;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
export { pluginReplaceConstants };
|
|
2
|
+
export { filterFunction };
|
|
3
|
+
export { filterRolldown };
|
|
2
4
|
import { assert, assertPosixPath } from '../utils.js';
|
|
3
5
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
4
6
|
import { isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
|
|
5
7
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
8
|
+
const skipNodeModules = '/node_modules/';
|
|
9
|
+
const skipIrrelevant = 'import.meta.env.';
|
|
10
|
+
const filterRolldown = {
|
|
11
|
+
id: {
|
|
12
|
+
exclude: `**${skipNodeModules}**`,
|
|
13
|
+
},
|
|
14
|
+
code: {
|
|
15
|
+
include: skipIrrelevant,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const filterFunction = (id, code) => {
|
|
19
|
+
if (id.includes(skipNodeModules))
|
|
20
|
+
return false;
|
|
21
|
+
if (!code.includes(skipIrrelevant))
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
6
25
|
function pluginReplaceConstants() {
|
|
7
26
|
let config;
|
|
8
27
|
return {
|
|
@@ -15,16 +34,14 @@ function pluginReplaceConstants() {
|
|
|
15
34
|
},
|
|
16
35
|
},
|
|
17
36
|
transform: {
|
|
37
|
+
filter: filterRolldown,
|
|
18
38
|
handler(code, id, options) {
|
|
19
39
|
id = normalizeId(id);
|
|
20
40
|
assertPosixPath(id);
|
|
21
|
-
if (id.includes('/node_modules/'))
|
|
22
|
-
return;
|
|
23
41
|
assertPosixPath(config.root);
|
|
24
42
|
if (!id.startsWith(config.root))
|
|
25
|
-
return;
|
|
26
|
-
|
|
27
|
-
return;
|
|
43
|
+
return; // skip linked dependencies
|
|
44
|
+
assert(filterFunction(id, code));
|
|
28
45
|
const isBuild = config.command === 'build';
|
|
29
46
|
assert(isBuild);
|
|
30
47
|
// Used by vike.dev
|
|
@@ -2,7 +2,7 @@ export { pluginVirtualFiles };
|
|
|
2
2
|
import { normalizePath } from 'vite';
|
|
3
3
|
import { generateVirtualFilePageEntry } from './pluginVirtualFiles/generateVirtualFilePageEntry.js';
|
|
4
4
|
import { generateVirtualFileGlobalEntryWithOldDesign } from './pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js';
|
|
5
|
-
import { assert, assertPosixPath, isScriptFile, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, } from '../utils.js';
|
|
5
|
+
import { assert, assertPosixPath, isScriptFile, addVirtualFileIdPrefix, isVirtualFileId, removeVirtualFileIdPrefix, escapeRegex, virtualFileIdPrefix1, virtualFileIdPrefix2, } from '../utils.js';
|
|
6
6
|
import { parseVirtualFileId } from '../../shared/virtualFileId.js';
|
|
7
7
|
import { reloadVikeConfig, isV1Design, getVikeConfigInternalOptional } from '../shared/resolveVikeConfigInternal.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -12,6 +12,12 @@ import { isRunnable, updateUserFiles } from '../../runtime/globalContext.js';
|
|
|
12
12
|
import { isPlusFile } from '../shared/resolveVikeConfigInternal/crawlPlusFiles.js';
|
|
13
13
|
import { isTemporaryBuildFile } from '../shared/resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
14
14
|
import { getVikeConfigError } from '../../shared/getVikeConfigError.js';
|
|
15
|
+
const filterRolldown = {
|
|
16
|
+
id: {
|
|
17
|
+
include: new RegExp(`^(${escapeRegex(virtualFileIdPrefix1)}|${escapeRegex(virtualFileIdPrefix2)})`),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const filterFunction = (id) => isVirtualFileId(id);
|
|
15
21
|
function pluginVirtualFiles() {
|
|
16
22
|
let config;
|
|
17
23
|
return {
|
|
@@ -25,10 +31,10 @@ function pluginVirtualFiles() {
|
|
|
25
31
|
},
|
|
26
32
|
},
|
|
27
33
|
resolveId: {
|
|
34
|
+
filter: filterRolldown,
|
|
28
35
|
handler(id) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
36
|
+
assert(filterFunction(id));
|
|
37
|
+
return addVirtualFileIdPrefix(id);
|
|
32
38
|
},
|
|
33
39
|
},
|
|
34
40
|
handleHotUpdate: {
|
|
@@ -44,9 +50,9 @@ function pluginVirtualFiles() {
|
|
|
44
50
|
},
|
|
45
51
|
},
|
|
46
52
|
load: {
|
|
53
|
+
filter: filterRolldown,
|
|
47
54
|
async handler(id, options) {
|
|
48
|
-
|
|
49
|
-
return undefined;
|
|
55
|
+
assert(filterFunction(id));
|
|
50
56
|
id = removeVirtualFileIdPrefix(id);
|
|
51
57
|
const isDev = config._isDev;
|
|
52
58
|
assert(typeof isDev === 'boolean');
|
|
@@ -136,8 +142,7 @@ async function handleHotUpdate(ctx, config) {
|
|
|
136
142
|
// Vite already invalidates it, but *after* handleHotUpdate() and thus after server.ssrLoadModule()
|
|
137
143
|
ctx.modules.forEach((mod) => server.moduleGraph.invalidateModule(mod));
|
|
138
144
|
if (isRunnable(server)) {
|
|
139
|
-
|
|
140
|
-
updateUserFiles();
|
|
145
|
+
await updateUserFiles();
|
|
141
146
|
}
|
|
142
147
|
}
|
|
143
148
|
}
|