vike 0.4.236-commit-08fbc10 → 0.4.236-commit-cd565e9
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 +111 -26
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +3 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +3 -1
- package/dist/cjs/node/runtime/utils.js +3 -0
- 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/pluginBuildConfig.js +0 -3
- package/dist/cjs/node/vite/plugins/pluginCommon.js +1 -0
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +10 -8
- package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
- 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/getVirtualFilePageConfigsEager.js +4 -0
- 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/shared/createGlobalContextShared.js +5 -1
- 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/isRunnableDevEnvironment.js +9 -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 +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +41 -14
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +2 -2
- package/dist/esm/client/runtime-client-routing/utils.d.ts +1 -0
- package/dist/esm/client/runtime-client-routing/utils.js +1 -0
- 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 +34 -54
- package/dist/esm/node/runtime/globalContext.js +112 -27
- 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.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 +3 -0
- package/dist/esm/node/runtime/utils.js +3 -0
- 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/pluginBuildConfig.d.ts +0 -2
- package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -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 +10 -8
- 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/getVirtualFilePageConfigsEager.js +4 -0
- 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/shared/createGlobalContextShared.d.ts +3 -3
- package/dist/esm/shared/createGlobalContextShared.js +5 -1
- 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/isRunnableDevEnvironment.d.ts +3 -0
- package/dist/esm/utils/isRunnableDevEnvironment.js +7 -0
- package/package.json +11 -2
|
@@ -7,10 +7,10 @@ const createGlobalContextShared_js_1 = require("../../shared/createGlobalContext
|
|
|
7
7
|
const getJsonSerializedInHtml_js_1 = require("./getJsonSerializedInHtml.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('createGetGlobalContextClient.ts', (() => {
|
|
10
|
-
const { promise:
|
|
10
|
+
const { promise: globalContextInitialPromise, resolve: globalContextInitialPromiseResolve } = (0, utils_js_1.genPromise)();
|
|
11
11
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
globalContextInitialPromise,
|
|
13
|
+
globalContextInitialPromiseResolve,
|
|
14
14
|
};
|
|
15
15
|
})());
|
|
16
16
|
function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGlobalContext) {
|
|
@@ -21,18 +21,22 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
|
|
|
21
21
|
return getGlobalContext;
|
|
22
22
|
async function getGlobalContext() {
|
|
23
23
|
// Cache
|
|
24
|
-
if (globalObject.
|
|
24
|
+
if (globalObject.virtualFileExports &&
|
|
25
25
|
// Don't break HMR
|
|
26
|
-
globalObject.
|
|
27
|
-
|
|
26
|
+
globalObject.virtualFileExports === virtualFileExports) {
|
|
27
|
+
const globalContext = await globalObject.globalContextPromise;
|
|
28
|
+
return globalContext;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
globalObject.virtualFileExports = virtualFileExports;
|
|
28
32
|
}
|
|
29
33
|
// Create
|
|
30
|
-
const
|
|
34
|
+
const globalContextPromise = (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, undefined, async (globalContext) => {
|
|
31
35
|
const globalContextAddendum = {
|
|
32
36
|
/**
|
|
33
37
|
* Whether the environment is client-side or server-side / pre-rendering.
|
|
34
38
|
*
|
|
35
|
-
* We recommend using `
|
|
39
|
+
* We recommend using `({}).SSR` instead, see https://vike.dev/globalContext
|
|
36
40
|
*/
|
|
37
41
|
isClientSide: true,
|
|
38
42
|
};
|
|
@@ -40,18 +44,24 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
|
|
|
40
44
|
(0, utils_js_1.objectAssign)(globalContextAddendum, await addGlobalContext?.(globalContext));
|
|
41
45
|
return globalContextAddendum;
|
|
42
46
|
});
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
globalObject.globalContextPromise = globalContextPromise;
|
|
48
|
+
const globalContext = await globalContextPromise;
|
|
49
|
+
(0, utils_js_1.assert)(globalObject.globalContext === globalContext);
|
|
50
|
+
globalObject.globalContextInitialPromiseResolve();
|
|
45
51
|
// Return
|
|
46
52
|
return globalContext;
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
55
|
async function getGlobalContext() {
|
|
56
|
+
await globalObject.globalContextInitialPromise;
|
|
50
57
|
const globalContext = await globalObject.globalContextPromise;
|
|
58
|
+
(0, utils_js_1.assert)(globalContext);
|
|
59
|
+
(0, utils_js_1.checkType)(globalContext);
|
|
51
60
|
return globalContext;
|
|
52
61
|
}
|
|
53
62
|
function getGlobalContextSync() {
|
|
54
63
|
const { globalContext } = globalObject;
|
|
55
64
|
(0, utils_js_1.assertUsage)(globalContext, createGlobalContextShared_js_1.getGlobalContextSyncErrMsg);
|
|
65
|
+
(0, utils_js_1.checkType)(globalContext);
|
|
56
66
|
return globalContext;
|
|
57
67
|
}
|
|
@@ -20,3 +20,4 @@ __exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
|
20
20
|
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
21
21
|
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
22
22
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
23
|
+
__exportStar(require("../../utils/checkType.js"), exports);
|
|
@@ -21,6 +21,12 @@ exports.setGlobalContext_buildEntry = setGlobalContext_buildEntry;
|
|
|
21
21
|
exports.clearGlobalContext = clearGlobalContext;
|
|
22
22
|
exports.assertBuildInfo = assertBuildInfo;
|
|
23
23
|
exports.updateUserFiles = updateUserFiles;
|
|
24
|
+
// TODO/now: use isProductionEnvironment() instead of globalObject.isProduction
|
|
25
|
+
// TODO/now: rename:
|
|
26
|
+
// - isProduction => isProductionEnvironment
|
|
27
|
+
// - setIsProduction => setIsProductionEnvironment
|
|
28
|
+
// - setGlobalContext_isProduction => setGlobalContext_isProductionEnvironment
|
|
29
|
+
// - sProductionEnvironment => sDevEnv
|
|
24
30
|
// The core logic revolves around:
|
|
25
31
|
// - virtualFileExports is the main requirement
|
|
26
32
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
@@ -48,6 +54,7 @@ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts',
|
|
|
48
54
|
const globalObjectTyped = globalObject;
|
|
49
55
|
const vikeConfigErrorRecoverMsg = picocolors_1.default.bold(picocolors_1.default.green('Vike config loaded'));
|
|
50
56
|
exports.vikeConfigErrorRecoverMsg = vikeConfigErrorRecoverMsg;
|
|
57
|
+
(0, utils_js_1.assertIsNotBrowser)();
|
|
51
58
|
async function getGlobalContextServerInternal() {
|
|
52
59
|
// getGlobalContextServerInternal() should always be called after initGlobalContext()
|
|
53
60
|
(0, utils_js_1.assert)(globalObject.isInitialized);
|
|
@@ -134,10 +141,12 @@ async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
|
134
141
|
(0, utils_js_1.assert)(globalObject.viteConfig);
|
|
135
142
|
globalObject.viteDevServer = viteDevServer;
|
|
136
143
|
globalObject.viteDevServerPromiseResolve(viteDevServer);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
144
|
+
if (isRunnable(viteDevServer)) {
|
|
145
|
+
const { success } = await updateUserFiles();
|
|
146
|
+
if (!success)
|
|
147
|
+
return;
|
|
148
|
+
assertGlobalContextIsDefined();
|
|
149
|
+
}
|
|
141
150
|
}
|
|
142
151
|
function setGlobalContext_viteConfig(viteConfig, viteConfigRuntime) {
|
|
143
152
|
if (globalObject.viteConfig)
|
|
@@ -154,6 +163,7 @@ function setGlobalContext_isPrerendering() {
|
|
|
154
163
|
globalObject.isPrerendering = true;
|
|
155
164
|
setIsProduction(true);
|
|
156
165
|
}
|
|
166
|
+
// TODO/now: `rename tolerateContraditction tolerateContradiction`
|
|
157
167
|
function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
|
|
158
168
|
if (debug.isActivated)
|
|
159
169
|
debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
|
|
@@ -205,7 +215,13 @@ async function initGlobalContext() {
|
|
|
205
215
|
const { isProduction } = globalObject;
|
|
206
216
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
207
217
|
if (!isProduction) {
|
|
208
|
-
|
|
218
|
+
if (isProcessSharedWithVite()) {
|
|
219
|
+
await globalObject.viteDevServerPromise;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
(0, utils_js_1.assert)(isNonRunnableDev());
|
|
223
|
+
await updateUserFiles();
|
|
224
|
+
}
|
|
209
225
|
(0, utils_js_1.assert)(globalObject.waitForUserFilesUpdate);
|
|
210
226
|
await globalObject.waitForUserFilesUpdate;
|
|
211
227
|
}
|
|
@@ -262,7 +278,7 @@ async function loadBuildEntry(outDir) {
|
|
|
262
278
|
assertBuildEntry(buildEntry);
|
|
263
279
|
globalObject.assetsManifest = buildEntry.assetsManifest;
|
|
264
280
|
globalObject.buildInfo = buildEntry.buildInfo;
|
|
265
|
-
await
|
|
281
|
+
await createGlobalContext(buildEntry.virtualFileExports);
|
|
266
282
|
}
|
|
267
283
|
// This is the production entry, see:
|
|
268
284
|
// https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
|
|
@@ -307,6 +323,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
|
|
|
307
323
|
(0, utils_js_1.assertUsage)(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
|
|
308
324
|
}
|
|
309
325
|
async function updateUserFiles() {
|
|
326
|
+
debug('updateUserFiles()');
|
|
310
327
|
(0, utils_js_1.assert)(!globalObject.isProduction);
|
|
311
328
|
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
312
329
|
globalObject.waitForUserFilesUpdate = promise;
|
|
@@ -339,16 +356,46 @@ async function updateUserFiles() {
|
|
|
339
356
|
// Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
|
|
340
357
|
viteDevServer !== globalObject.viteDevServer;
|
|
341
358
|
const { viteDevServer } = globalObject;
|
|
342
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
343
359
|
let hasError = false;
|
|
344
360
|
let virtualFileExports;
|
|
345
361
|
let err;
|
|
346
|
-
|
|
347
|
-
|
|
362
|
+
if (viteDevServer) {
|
|
363
|
+
(0, utils_js_1.assert)(isRunnable(viteDevServer));
|
|
364
|
+
/* We don't use runner.import() yet, because as of vite@7.0.6 (July 2025) runner.import() unexpectedly invalidates the module graph, which is a unexpected behavior that doesn't happen with ssrLoadModule()
|
|
365
|
+
// Vite 6
|
|
366
|
+
try {
|
|
367
|
+
virtualFileExports = await (viteDevServer.environments.ssr as RunnableDevEnvironment).runner.import(
|
|
368
|
+
'virtual:vike:entry:server',
|
|
369
|
+
)
|
|
370
|
+
} catch (err_) {
|
|
371
|
+
hasError = true
|
|
372
|
+
err = err_
|
|
373
|
+
}
|
|
374
|
+
*/
|
|
375
|
+
// Vite 5
|
|
376
|
+
try {
|
|
377
|
+
virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileEntry_js_1.virtualFileIdEntryServer);
|
|
378
|
+
}
|
|
379
|
+
catch (err_) {
|
|
380
|
+
hasError = true;
|
|
381
|
+
err = err_;
|
|
382
|
+
}
|
|
348
383
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
384
|
+
else {
|
|
385
|
+
try {
|
|
386
|
+
/* We use __VIKE__DYNAMIC_IMPORT instead of directly using import() to workaround what seems to be a Vite HMR bug:
|
|
387
|
+
```js
|
|
388
|
+
assert(false)
|
|
389
|
+
// This line breaks the HMR of regular (runnable) apps, even though (as per the assert() above) it's never run. It seems to be a Vite bug: handleHotUpdate() receives an empty `modules` list.
|
|
390
|
+
import('virtual:vike:entry:server')
|
|
391
|
+
```
|
|
392
|
+
*/
|
|
393
|
+
virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
|
|
394
|
+
}
|
|
395
|
+
catch (err_) {
|
|
396
|
+
hasError = true;
|
|
397
|
+
err = err_;
|
|
398
|
+
}
|
|
352
399
|
}
|
|
353
400
|
if (isOutdated())
|
|
354
401
|
return { success: false };
|
|
@@ -359,7 +406,7 @@ async function updateUserFiles() {
|
|
|
359
406
|
return { success: false };
|
|
360
407
|
}
|
|
361
408
|
try {
|
|
362
|
-
await
|
|
409
|
+
await createGlobalContext(virtualFileExports);
|
|
363
410
|
}
|
|
364
411
|
catch (err_) {
|
|
365
412
|
hasError = true;
|
|
@@ -371,17 +418,17 @@ async function updateUserFiles() {
|
|
|
371
418
|
return onError(err);
|
|
372
419
|
return onSuccess();
|
|
373
420
|
}
|
|
374
|
-
async function
|
|
375
|
-
debug('
|
|
421
|
+
async function createGlobalContext(virtualFileExports) {
|
|
422
|
+
debug('createGlobalContext()');
|
|
376
423
|
(0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
|
|
377
|
-
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp);
|
|
424
|
+
const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
|
|
378
425
|
(0, assertV1Design_js_1.assertV1Design)(
|
|
379
426
|
// pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
|
|
380
427
|
globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
|
|
381
428
|
assertGlobalContextIsDefined();
|
|
382
429
|
(0, utils_js_1.onSetupRuntime)();
|
|
383
|
-
debug('
|
|
384
|
-
// Never actually used, only used for TypeScript `ReturnType<typeof
|
|
430
|
+
debug('createGlobalContext() - done');
|
|
431
|
+
// Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
|
|
385
432
|
return globalContext;
|
|
386
433
|
}
|
|
387
434
|
async function addGlobalContextTmp(globalContext) {
|
|
@@ -400,23 +447,18 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
400
447
|
_pageRoutes: pageRoutes,
|
|
401
448
|
_onBeforeRouteHook: onBeforeRouteHook,
|
|
402
449
|
};
|
|
403
|
-
const { viteDevServer, viteConfig,
|
|
450
|
+
const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
|
|
404
451
|
(0, utils_js_1.assert)(typeof isProduction === 'boolean');
|
|
405
452
|
if (!isProduction) {
|
|
406
|
-
(0, utils_js_1.assert)(viteDevServer);
|
|
407
453
|
(0, utils_js_1.assert)(globalContext); // main common requirement
|
|
408
|
-
(0, utils_js_1.assert)(viteConfig);
|
|
409
|
-
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
410
454
|
(0, utils_js_1.assert)(!isPrerendering);
|
|
411
455
|
return {
|
|
412
456
|
...globalContextBase,
|
|
413
|
-
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
414
457
|
_isProduction: false,
|
|
415
458
|
_isPrerendering: false,
|
|
416
459
|
assetsManifest: null,
|
|
417
460
|
_viteDevServer: viteDevServer,
|
|
418
461
|
viteConfig,
|
|
419
|
-
viteConfigRuntime,
|
|
420
462
|
};
|
|
421
463
|
}
|
|
422
464
|
else {
|
|
@@ -427,11 +469,9 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
427
469
|
(0, utils_js_1.assert)(assetsManifest);
|
|
428
470
|
const globalContextBase2 = {
|
|
429
471
|
...globalContextBase,
|
|
430
|
-
...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
|
|
431
472
|
_isProduction: true,
|
|
432
473
|
assetsManifest,
|
|
433
474
|
_viteDevServer: null,
|
|
434
|
-
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
435
475
|
_usesClientRouter: buildInfo.usesClientRouter,
|
|
436
476
|
};
|
|
437
477
|
if (isPrerendering) {
|
|
@@ -451,6 +491,27 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
|
|
|
451
491
|
}
|
|
452
492
|
}
|
|
453
493
|
}
|
|
494
|
+
async function addGlobalContextAsync(globalContext) {
|
|
495
|
+
debug('addGlobalContextAsync()');
|
|
496
|
+
let { viteConfigRuntime, buildInfo } = globalObject;
|
|
497
|
+
if (!viteConfigRuntime) {
|
|
498
|
+
if (buildInfo) {
|
|
499
|
+
viteConfigRuntime = buildInfo.viteConfigRuntime;
|
|
500
|
+
}
|
|
501
|
+
else {
|
|
502
|
+
(0, utils_js_1.assert)(!isProcessSharedWithVite()); // process shared with Vite => globalObject.viteConfigRuntime should be set
|
|
503
|
+
(0, utils_js_1.assert)(!globalObject.isProduction); // production => globalObject.buildInfo.viteConfigRuntime should be set
|
|
504
|
+
(0, utils_js_1.assert)(isNonRunnableDev());
|
|
505
|
+
const rpc = (0, utils_js_1.getViteRPC)();
|
|
506
|
+
viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
(0, utils_js_1.assert)(viteConfigRuntime);
|
|
510
|
+
return {
|
|
511
|
+
viteConfigRuntime,
|
|
512
|
+
...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
454
515
|
function clearGlobalContext() {
|
|
455
516
|
debug('clearGlobalContext()');
|
|
456
517
|
(0, utils_js_1.objectReplace)(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
|
|
@@ -459,6 +520,7 @@ function getInitialGlobalObject() {
|
|
|
459
520
|
debug('getInitialGlobalObject()');
|
|
460
521
|
const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
|
|
461
522
|
return {
|
|
523
|
+
isProduction: isNonRunnableDev() ? false : undefined,
|
|
462
524
|
viteDevServerPromise,
|
|
463
525
|
viteDevServerPromiseResolve,
|
|
464
526
|
};
|
|
@@ -469,3 +531,26 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
|
469
531
|
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
470
532
|
return (0, resolveBase_js_1.resolveBase)(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
471
533
|
}
|
|
534
|
+
function isProcessSharedWithVite() {
|
|
535
|
+
const yes = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE ?? false;
|
|
536
|
+
if (yes)
|
|
537
|
+
(0, utils_js_1.assert)(!isNonRunnableDev());
|
|
538
|
+
return yes;
|
|
539
|
+
}
|
|
540
|
+
function isRunnable(viteDevServer) {
|
|
541
|
+
const yes =
|
|
542
|
+
// Vite 5
|
|
543
|
+
!viteDevServer.environments ||
|
|
544
|
+
// Vite 6 or above
|
|
545
|
+
(0, utils_js_1.isRunnableDevEnvironment)(viteDevServer.environments.ssr);
|
|
546
|
+
if (yes)
|
|
547
|
+
(0, utils_js_1.assert)(!isNonRunnableDev());
|
|
548
|
+
return yes;
|
|
549
|
+
}
|
|
550
|
+
function isNonRunnableDev() {
|
|
551
|
+
if (typeof __VIKE__IS_NON_RUNNABLE_DEV === 'undefined')
|
|
552
|
+
return null;
|
|
553
|
+
const yes = __VIKE__IS_NON_RUNNABLE_DEV;
|
|
554
|
+
(0, utils_js_1.assert)(typeof yes === 'boolean');
|
|
555
|
+
return yes;
|
|
556
|
+
}
|
|
@@ -16,7 +16,9 @@ async function getViteDevScript(pageContext) {
|
|
|
16
16
|
const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
|
|
17
17
|
const fakeHtmlEnd = '</head><body></body></html>';
|
|
18
18
|
let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
|
|
19
|
-
fakeHtml =
|
|
19
|
+
fakeHtml = viteDevServer
|
|
20
|
+
? await viteDevServer.transformIndexHtml('/', fakeHtml)
|
|
21
|
+
: await (0, utils_js_1.getViteRPC)().transformIndexHtmlRPC(fakeHtml);
|
|
20
22
|
(0, utils_js_1.assertUsage)(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${picocolors_1.default.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
|
|
21
23
|
(0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
|
|
22
24
|
(0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
|
|
@@ -17,7 +17,9 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
17
17
|
const { _isProduction: isProduction } = globalContext;
|
|
18
18
|
const isDev = !isProduction;
|
|
19
19
|
const { assetUrls, clientEntriesSrc } = isDev
|
|
20
|
-
?
|
|
20
|
+
? !globalContext._viteDevServer
|
|
21
|
+
? await (0, utils_js_1.getViteRPC)().retrievePageAssetsDevRPC(clientDependencies, clientEntries)
|
|
22
|
+
: await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
|
|
21
23
|
: retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
|
|
22
24
|
let pageAssets = [];
|
|
23
25
|
(0, utils_js_1.unique)([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
@@ -77,3 +77,6 @@ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
|
77
77
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
78
78
|
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
79
79
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
80
|
+
__exportStar(require("../../utils/getViteRPC.js"), exports);
|
|
81
|
+
__exportStar(require("../../utils/isRunnableDevEnvironment.js"), exports);
|
|
82
|
+
__exportStar(require("../../utils/assertIsNotBrowser.js"), exports);
|
|
@@ -29,6 +29,7 @@ const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.j
|
|
|
29
29
|
const pluginWorkaroundCssModuleHmr_js_1 = require("./plugins/pluginWorkaroundCssModuleHmr.js");
|
|
30
30
|
const pluginWorkaroundVite6HmrRegression_js_1 = require("./plugins/pluginWorkaroundVite6HmrRegression.js");
|
|
31
31
|
const pluginReplaceConstants_js_1 = require("./plugins/pluginReplaceConstants.js");
|
|
32
|
+
const pluginNonRunnableDev_js_1 = require("./plugins/pluginNonRunnableDev.js");
|
|
32
33
|
// We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
|
|
33
34
|
(0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
|
|
34
35
|
// Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
|
|
@@ -48,6 +49,7 @@ function plugin(vikeVitePluginOptions = {}) {
|
|
|
48
49
|
(0, pluginWorkaroundCssModuleHmr_js_1.pluginWorkaroundCssModuleHmr)(),
|
|
49
50
|
(0, pluginWorkaroundVite6HmrRegression_js_1.pluginWorkaroundVite6HmrRegression)(),
|
|
50
51
|
(0, pluginReplaceConstants_js_1.pluginReplaceConstants)(),
|
|
52
|
+
(0, pluginNonRunnableDev_js_1.pluginNonRunnableDev)(),
|
|
51
53
|
];
|
|
52
54
|
Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
|
|
53
55
|
return plugins;
|
|
@@ -14,13 +14,13 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
14
14
|
const node_fs_2 = require("node:fs");
|
|
15
15
|
const utils_js_1 = require("../../utils.js");
|
|
16
16
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
17
|
-
const pluginBuildConfig_js_1 = require("./pluginBuildConfig.js");
|
|
18
17
|
const getAssetsDir_js_1 = require("../../shared/getAssetsDir.js");
|
|
19
18
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
19
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
21
20
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
22
21
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
23
22
|
const pluginBuildEntry_js_1 = require("./pluginBuildEntry.js");
|
|
23
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
24
24
|
(0, utils_js_1.assertIsSingleModuleInstance)('build/handleAssetsManifest.ts');
|
|
25
25
|
let assetsJsonFilePath;
|
|
26
26
|
// true => use workaround config.build.ssrEmitAssets
|
|
@@ -31,9 +31,8 @@ function handleAssetsManifest_isFixEnabled(config) {
|
|
|
31
31
|
}
|
|
32
32
|
/** https://github.com/vikejs/vike/issues/1339 */
|
|
33
33
|
async function fixServerAssets(config) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const serverManifest = await readManifestFile(outDirs.outDirServer);
|
|
34
|
+
const clientManifest = await readManifestFile(config, true);
|
|
35
|
+
const serverManifest = await readManifestFile(config, false);
|
|
37
36
|
const { clientManifestMod, serverManifestMod, filesToMove, filesToRemove } = addServerAssets(clientManifest, serverManifest);
|
|
38
37
|
await copyAssets(filesToMove, filesToRemove, config);
|
|
39
38
|
return { clientManifestMod, serverManifestMod };
|
|
@@ -270,8 +269,8 @@ function removeEmptyDirectories(dirPath) {
|
|
|
270
269
|
node_fs_1.default.rmdirSync(dirPath);
|
|
271
270
|
}
|
|
272
271
|
}
|
|
273
|
-
async function readManifestFile(
|
|
274
|
-
const manifestFilePath =
|
|
272
|
+
async function readManifestFile(config, client) {
|
|
273
|
+
const manifestFilePath = getManifestFilePath(config, client);
|
|
275
274
|
const manifestFileContent = await promises_1.default.readFile(manifestFilePath, 'utf-8');
|
|
276
275
|
(0, utils_js_1.assert)(manifestFileContent);
|
|
277
276
|
const manifest = JSON.parse(manifestFileContent);
|
|
@@ -292,7 +291,7 @@ async function handleAssetsManifest_getBuildConfig(config) {
|
|
|
292
291
|
ssrEmitAssets: isFixEnabled ? true : undefined,
|
|
293
292
|
// Required if `ssrEmitAssets: true`, see https://github.com/vitejs/vite/pull/11430#issuecomment-1454800934
|
|
294
293
|
cssMinify: isFixEnabled ? 'esbuild' : undefined,
|
|
295
|
-
manifest:
|
|
294
|
+
manifest: true,
|
|
296
295
|
copyPublicDir: vikeConfig.config.vite6BuilderApp
|
|
297
296
|
? // Already set by vike:build:pluginBuildApp
|
|
298
297
|
undefined
|
|
@@ -305,7 +304,7 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
305
304
|
(0, utils_js_1.assert)(!assetsJsonFilePath);
|
|
306
305
|
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config, viteEnv);
|
|
307
306
|
assetsJsonFilePath = node_path_1.default.posix.join(outDirs.outDirRoot, 'assets.json');
|
|
308
|
-
await writeAssetsManifestFile(
|
|
307
|
+
await writeAssetsManifestFile(assetsJsonFilePath, config);
|
|
309
308
|
}
|
|
310
309
|
if ((0, isViteServerBuild_js_1.isViteServerBuild)(config, viteEnv)) {
|
|
311
310
|
const outDir = options.dir;
|
|
@@ -319,10 +318,10 @@ async function handleAssetsManifest(config, viteEnv, options, bundle) {
|
|
|
319
318
|
(0, utils_js_1.assert)(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
|
|
320
319
|
}
|
|
321
320
|
}
|
|
322
|
-
async function writeAssetsManifestFile(
|
|
321
|
+
async function writeAssetsManifestFile(assetsJsonFilePath, config) {
|
|
323
322
|
const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
|
|
324
|
-
const clientManifestFilePath =
|
|
325
|
-
const serverManifestFilePath =
|
|
323
|
+
const clientManifestFilePath = getManifestFilePath(config, true);
|
|
324
|
+
const serverManifestFilePath = getManifestFilePath(config, false);
|
|
326
325
|
if (!isFixEnabled) {
|
|
327
326
|
await promises_1.default.copyFile(clientManifestFilePath, assetsJsonFilePath);
|
|
328
327
|
}
|
|
@@ -333,3 +332,12 @@ async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
|
|
|
333
332
|
await promises_1.default.rm(clientManifestFilePath);
|
|
334
333
|
await promises_1.default.rm(serverManifestFilePath);
|
|
335
334
|
}
|
|
335
|
+
function getManifestFilePath(config, client) {
|
|
336
|
+
const outDirs = (0, getOutDirs_js_1.getOutDirs)(config);
|
|
337
|
+
const outDir = client ? outDirs.outDirClient : outDirs.outDirServer;
|
|
338
|
+
const env = client ? config.environments.client : config.environments.ssr;
|
|
339
|
+
(0, utils_js_1.assert)(env);
|
|
340
|
+
const manifestFilePathRelative = (0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(env.build.manifest);
|
|
341
|
+
const manifestFilePath = node_path_1.default.posix.join(outDir, manifestFilePathRelative);
|
|
342
|
+
return manifestFilePath;
|
|
343
|
+
}
|
|
@@ -11,12 +11,12 @@ const context_js_1 = require("../../../prerender/context.js");
|
|
|
11
11
|
const isViteCliCall_js_1 = require("../../shared/isViteCliCall.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
const logErrorHint_js_1 = require("../../../runtime/renderPage/logErrorHint.js");
|
|
14
|
-
const pluginBuildConfig_js_1 = require("./pluginBuildConfig.js");
|
|
15
14
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
16
15
|
const context_js_2 = require("../../../api/context.js");
|
|
17
16
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
17
|
const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
19
18
|
const runPrerenderEntry_js_1 = require("../../../prerender/runPrerenderEntry.js");
|
|
19
|
+
const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePathRelative.js");
|
|
20
20
|
(0, utils_js_1.assertIsSingleModuleInstance)('build/pluginAutoFullBuild.ts');
|
|
21
21
|
let forceExit = false;
|
|
22
22
|
function pluginAutoFullBuild() {
|
|
@@ -87,7 +87,7 @@ async function triggerFullBuild(config, viteEnv, bundle) {
|
|
|
87
87
|
// - The legacy plugin triggers its own Rollup build for the client-side.
|
|
88
88
|
// - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
|
|
89
89
|
// - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
|
|
90
|
-
if (!bundle[
|
|
90
|
+
if (!bundle[(0, getManifestFilePathRelative_js_1.getManifestFilePathRelative)(config.build.manifest)])
|
|
91
91
|
return;
|
|
92
92
|
const configInline = getFullBuildInlineConfig(config);
|
|
93
93
|
if (!isBuilderApp) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.manifestTempFile = void 0;
|
|
4
3
|
exports.pluginBuildConfig = pluginBuildConfig;
|
|
5
4
|
exports.assertRollupInput = assertRollupInput;
|
|
6
5
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
@@ -16,8 +15,6 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
|
|
|
16
15
|
const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
|
|
17
16
|
const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
|
|
18
17
|
const getPageAssets_js_1 = require("../../../runtime/renderPage/getPageAssets.js");
|
|
19
|
-
const manifestTempFile = '_temp_manifest.json';
|
|
20
|
-
exports.manifestTempFile = manifestTempFile;
|
|
21
18
|
function pluginBuildConfig() {
|
|
22
19
|
let config;
|
|
23
20
|
return [
|
|
@@ -16,6 +16,7 @@ const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInter
|
|
|
16
16
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
17
17
|
const context_js_2 = require("../../prerender/context.js");
|
|
18
18
|
const pluginName = 'vike:pluginCommon';
|
|
19
|
+
globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
|
|
19
20
|
function pluginCommon(vikeVitePluginOptions) {
|
|
20
21
|
return [
|
|
21
22
|
{
|
|
@@ -14,21 +14,23 @@ async function determineOptimizeDeps(config) {
|
|
|
14
14
|
const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
|
|
15
15
|
config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
|
|
16
16
|
config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
// Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
|
|
18
|
+
// - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
|
|
19
|
+
includeServer.push('react/jsx-dev-runtime');
|
|
20
|
+
for (const envName in config.environments) {
|
|
21
|
+
const env = config.environments[envName];
|
|
22
|
+
if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
|
|
23
|
+
env.optimizeDeps.include = add(env.optimizeDeps.include, includeServer);
|
|
24
|
+
env.optimizeDeps.entries = add(env.optimizeDeps.entries, entriesServer);
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
if (debug.isActivated)
|
|
25
28
|
debug('optimizeDeps', {
|
|
26
29
|
'config.optimizeDeps.entries': config.optimizeDeps.entries,
|
|
27
30
|
'config.optimizeDeps.include': config.optimizeDeps.include,
|
|
28
31
|
'config.optimizeDeps.exclude': config.optimizeDeps.exclude,
|
|
29
|
-
|
|
32
|
+
// @ts-ignore Vite doesn't seem to support ssr.optimizeDeps.entries (vite@7.0.6, July 2025)
|
|
30
33
|
'config.ssr.optimizeDeps.entries': config.ssr.optimizeDeps.entries,
|
|
31
|
-
//*/
|
|
32
34
|
'config.ssr.optimizeDeps.include': config.ssr.optimizeDeps.include,
|
|
33
35
|
'config.ssr.optimizeDeps.exclude': config.ssr.optimizeDeps.exclude,
|
|
34
36
|
});
|
|
@@ -12,7 +12,7 @@ const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
|
12
12
|
const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
|
|
13
13
|
const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
|
|
14
14
|
// TO-DO/eventually:
|
|
15
|
-
// - Make
|
|
15
|
+
// - Make ({}) work inside +config.js
|
|
16
16
|
// - 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
|
|
17
17
|
// - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
|
|
18
18
|
const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
|
|
@@ -39,7 +39,7 @@ function pluginEnvVars() {
|
|
|
39
39
|
(0, utils_js_1.assertPosixPath)(config.root);
|
|
40
40
|
if (!id.startsWith(config.root))
|
|
41
41
|
return;
|
|
42
|
-
if (!code.includes('
|
|
42
|
+
if (!code.includes('({}).'))
|
|
43
43
|
return;
|
|
44
44
|
const isBuild = config.command === 'build';
|
|
45
45
|
const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
|
|
@@ -52,7 +52,7 @@ function pluginEnvVars() {
|
|
|
52
52
|
return !envPrefix.some((prefix) => key.startsWith(prefix));
|
|
53
53
|
})
|
|
54
54
|
.map(([envName, envVal]) => {
|
|
55
|
-
const envStatement = `
|
|
55
|
+
const envStatement = `({}).${envName}`;
|
|
56
56
|
const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
|
|
57
57
|
// Security check
|
|
58
58
|
{
|
|
@@ -81,12 +81,12 @@ function injectHmr(code, isClientSide, isProduction) {
|
|
|
81
81
|
}
|
|
82
82
|
if (isClientSide) {
|
|
83
83
|
code += '\n';
|
|
84
|
-
code += `if (
|
|
84
|
+
code += `if ((undefined)) (undefined).accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
87
|
// Ensure Vite considers the module as `isSelfAccepting`. (Needed because Vite's module graph erroneously conflates the Vite server-side modules with their client-side counterparts.)
|
|
88
88
|
code += '\n';
|
|
89
|
-
code += 'if(false){
|
|
89
|
+
code += 'if(false){(undefined).accept(()=>{})};';
|
|
90
90
|
}
|
|
91
91
|
return code;
|
|
92
92
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pluginNonRunnableDev = pluginNonRunnableDev;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const resolveClientEntriesDev_js_1 = require("../shared/resolveClientEntriesDev.js");
|
|
6
|
+
const retrieveAssetsDev_js_1 = require("../../runtime/renderPage/getPageAssets/retrieveAssetsDev.js");
|
|
7
|
+
const getViteConfigRuntime_js_1 = require("../shared/getViteConfigRuntime.js");
|
|
8
|
+
const getMagicString_js_1 = require("../shared/getMagicString.js");
|
|
9
|
+
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
10
|
+
function getViteRpcFunctions(viteDevServer) {
|
|
11
|
+
return {
|
|
12
|
+
async transformIndexHtmlRPC(html) {
|
|
13
|
+
return await viteDevServer.transformIndexHtml('/', html);
|
|
14
|
+
},
|
|
15
|
+
// TODO/now: dedupe retrievePageAssetsDevRPC and retrievePageAssetsDev()
|
|
16
|
+
async retrievePageAssetsDevRPC(clientDependencies, clientEntries) {
|
|
17
|
+
const clientEntriesSrc = clientEntries.map((clientEntry) => (0, resolveClientEntriesDev_js_1.resolveClientEntriesDev)(clientEntry, viteDevServer));
|
|
18
|
+
const assetUrls = await (0, retrieveAssetsDev_js_1.retrieveAssetsDev)(clientDependencies, viteDevServer);
|
|
19
|
+
return { clientEntriesSrc, assetUrls };
|
|
20
|
+
},
|
|
21
|
+
async getViteConfigRuntimeRPC() {
|
|
22
|
+
return (0, getViteConfigRuntime_js_1.getViteConfigRuntime)(viteDevServer.config);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function pluginNonRunnableDev() {
|
|
27
|
+
const runtimeGlobalContextFilePath = (0, utils_js_1.requireResolveVikeDistFile)('dist/esm/node/runtime/globalContext.js');
|
|
28
|
+
let config;
|
|
29
|
+
return {
|
|
30
|
+
name: 'vike:pluginNonRunnableDev',
|
|
31
|
+
configureServer(viteDevServer) {
|
|
32
|
+
(0, utils_js_1.createViteRPC)(viteDevServer, getViteRpcFunctions);
|
|
33
|
+
},
|
|
34
|
+
configResolved(config_) {
|
|
35
|
+
config = config_;
|
|
36
|
+
},
|
|
37
|
+
transform(code, id) {
|
|
38
|
+
if (!config._isDev)
|
|
39
|
+
return;
|
|
40
|
+
if (id !== runtimeGlobalContextFilePath)
|
|
41
|
+
return;
|
|
42
|
+
const isNonRunnableDev = !(0, utils_js_1.isRunnableDevEnvironment)(this.environment);
|
|
43
|
+
const { magicString, getMagicStringResult } = (0, getMagicString_js_1.getMagicString)(code, id);
|
|
44
|
+
if (isNonRunnableDev) {
|
|
45
|
+
magicString.replaceAll('__VIKE__DYNAMIC_IMPORT', 'import');
|
|
46
|
+
}
|
|
47
|
+
magicString.replaceAll('__VIKE__IS_NON_RUNNABLE_DEV', JSON.stringify(isNonRunnableDev));
|
|
48
|
+
return getMagicStringResult();
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|