vike 0.4.225-commit-765fb9c → 0.4.226-commit-a0035ee
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/api/preview.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +16 -6
- package/dist/cjs/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/cjs/node/prerender/runPrerender.js +6 -7
- package/dist/cjs/node/runtime/globalContext.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSetup.js +0 -3
- package/dist/cjs/utils/assertSingleInstance.js +19 -4
- package/dist/esm/node/api/preview.js +1 -1
- package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +16 -6
- package/dist/esm/node/plugin/plugins/fileEnv.js +3 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +1 -1
- package/dist/esm/node/prerender/runPrerender.js +6 -7
- package/dist/esm/node/runtime/globalContext.js +1 -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 +0 -3
- package/dist/esm/utils/assertSingleInstance.js +19 -4
- package/package.json +2 -2
|
@@ -24,7 +24,7 @@ async function preview(options = {}) {
|
|
|
24
24
|
const outDir = (0, getOutDirs_js_1.getOutDirs)(viteConfigResolved).outDirRoot;
|
|
25
25
|
const { outServerIndex } = await (0, runtime_1.importServerProductionIndex)({ outDir });
|
|
26
26
|
const outServerIndexRelative = node_path_1.default.relative(viteConfigResolved.root, outServerIndex);
|
|
27
|
-
(0, utils_js_1.assertWarning)(false, `Never run ${picocolors_1.default.cyan('$ vike preview')} in production, run ${picocolors_1.default.cyan(`$ node ${outServerIndexRelative}`)} instead.`, { onlyOnce: true });
|
|
27
|
+
(0, utils_js_1.assertWarning)(false, `Never run ${picocolors_1.default.cyan('$ vike preview')} in production, run ${picocolors_1.default.cyan(`$ node ${outServerIndexRelative}`)} instead (or Bun/Deno).`, { onlyOnce: true });
|
|
28
28
|
return {
|
|
29
29
|
viteConfig: viteConfigResolved
|
|
30
30
|
};
|
|
@@ -95,7 +95,7 @@ async function triggerFullBuild(config, vikeConfig, viteEnv, bundle) {
|
|
|
95
95
|
// The server bulid is already called by builder.buildApp()
|
|
96
96
|
}
|
|
97
97
|
if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
|
|
98
|
-
const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline
|
|
98
|
+
const res = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline);
|
|
99
99
|
forceExit = res.forceExit;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -19,6 +19,8 @@ const context_js_2 = require("../../prerender/context.js");
|
|
|
19
19
|
const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
|
|
20
20
|
const pluginName = 'vike:commonConfig';
|
|
21
21
|
function commonConfig(vikeVitePluginOptions) {
|
|
22
|
+
// We cache it => makes sure we only generate one object => we can mutate it at runPrerender()
|
|
23
|
+
let prerenderContext;
|
|
22
24
|
return [
|
|
23
25
|
{
|
|
24
26
|
name: `${pluginName}:pre`,
|
|
@@ -31,6 +33,9 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
31
33
|
const root = configFromUser.root ? (0, prepareViteApiCall_js_1.normalizeViteRoot)(configFromUser.root) : await (0, prepareViteApiCall_js_1.getViteRoot)(operation);
|
|
32
34
|
(0, utils_js_1.assert)(root);
|
|
33
35
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig2)(root, isDev, vikeVitePluginOptions);
|
|
36
|
+
const { isPrerenderingEnabled } = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
37
|
+
prerenderContext ?? (prerenderContext = { isPrerenderingEnabled, output: null, pageContexts: null });
|
|
38
|
+
(0, utils_js_1.assert)(prerenderContext.isPrerenderingEnabled === isPrerenderingEnabled);
|
|
34
39
|
return {
|
|
35
40
|
_isDev: isDev,
|
|
36
41
|
_root: root,
|
|
@@ -38,11 +43,12 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
38
43
|
_vikeConfigObject: vikeConfig,
|
|
39
44
|
_vike: {
|
|
40
45
|
pages: vikeConfig.pages,
|
|
41
|
-
config: vikeConfig.global.config
|
|
46
|
+
config: vikeConfig.global.config,
|
|
47
|
+
prerenderContext
|
|
42
48
|
},
|
|
43
49
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
44
50
|
configVikePromise: Promise.resolve({
|
|
45
|
-
prerender:
|
|
51
|
+
prerender: isPrerenderingEnabled
|
|
46
52
|
})
|
|
47
53
|
};
|
|
48
54
|
}
|
|
@@ -71,10 +77,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
71
77
|
assertEsm(config.root);
|
|
72
78
|
assertVikeCliOrApi(config);
|
|
73
79
|
temp_supportOldInterface(config);
|
|
74
|
-
|
|
75
|
-
if (config.vitePluginServerEntry?.inject &&
|
|
76
|
-
!(0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(config._vikeConfigObject).isPrerenderingEnabled)
|
|
77
|
-
config.vitePluginServerEntry.disableServerEntryEmit = true;
|
|
80
|
+
emitServerEntryOnlyIfNeeded(config);
|
|
78
81
|
}
|
|
79
82
|
},
|
|
80
83
|
config: {
|
|
@@ -200,3 +203,10 @@ function getVikeConfigPublic(config) {
|
|
|
200
203
|
(0, utils_js_1.assert)(vikeConfig);
|
|
201
204
|
return vikeConfig;
|
|
202
205
|
}
|
|
206
|
+
// Only emit dist/server/entry.mjs if necessary
|
|
207
|
+
function emitServerEntryOnlyIfNeeded(config) {
|
|
208
|
+
if (config.vitePluginServerEntry?.inject &&
|
|
209
|
+
!(0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(config._vikeConfigObject).isPrerenderingEnabled) {
|
|
210
|
+
config.vitePluginServerEntry.disableServerEntryEmit = true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -12,6 +12,7 @@ const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
|
12
12
|
const rollupSourceMap_js_1 = require("../shared/rollupSourceMap.js");
|
|
13
13
|
const parseEsModule_js_1 = require("../shared/parseEsModule.js");
|
|
14
14
|
const normalizeId_js_1 = require("../shared/normalizeId.js");
|
|
15
|
+
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
15
16
|
function fileEnv() {
|
|
16
17
|
let config;
|
|
17
18
|
let viteDevServer;
|
|
@@ -21,6 +22,8 @@ function fileEnv() {
|
|
|
21
22
|
// 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.
|
|
22
23
|
if (!viteDevServer)
|
|
23
24
|
return;
|
|
25
|
+
if (!(0, getVikeConfig_js_1.isV1Design)(config))
|
|
26
|
+
return;
|
|
24
27
|
if (skip(id))
|
|
25
28
|
return;
|
|
26
29
|
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
@@ -88,11 +88,9 @@ async function runPrerenderFromCLIPrerenderCommand() {
|
|
|
88
88
|
runPrerender_forceExit();
|
|
89
89
|
(0, utils_js_1.assert)(false);
|
|
90
90
|
}
|
|
91
|
-
async function runPrerenderFromAutoRun(viteConfig
|
|
92
|
-
let prerenderContextPublic;
|
|
91
|
+
async function runPrerenderFromAutoRun(viteConfig) {
|
|
93
92
|
try {
|
|
94
|
-
|
|
95
|
-
prerenderContextPublic = ret.prerenderContextPublic;
|
|
93
|
+
await runPrerender({ viteConfig });
|
|
96
94
|
}
|
|
97
95
|
catch (err) {
|
|
98
96
|
// Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
@@ -100,8 +98,6 @@ async function runPrerenderFromAutoRun(viteConfig, config) {
|
|
|
100
98
|
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
101
99
|
process.exit(1);
|
|
102
100
|
}
|
|
103
|
-
const vike = (0, commonConfig_js_1.getVikeConfigPublic)(config);
|
|
104
|
-
vike.prerenderContext = prerenderContextPublic;
|
|
105
101
|
const forceExit = (0, context_js_2.isVikeCli)() || (0, isViteCliCall_js_1.isViteCliCall)();
|
|
106
102
|
return { forceExit };
|
|
107
103
|
}
|
|
@@ -118,6 +114,8 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
118
114
|
await disableReactStreaming();
|
|
119
115
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'build', 'production');
|
|
120
116
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig);
|
|
117
|
+
const vike = (0, commonConfig_js_1.getVikeConfigPublic)(viteConfig);
|
|
118
|
+
(0, utils_js_1.assert)(vike.prerenderContext.isPrerenderingEnabled);
|
|
121
119
|
const { outDirClient } = (0, getOutDirs_js_1.getOutDirs)(viteConfig);
|
|
122
120
|
const { root } = viteConfig;
|
|
123
121
|
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
@@ -161,7 +159,8 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
161
159
|
}
|
|
162
160
|
await warnMissingPages(prerenderContext.prerenderedPageContexts, globalContext, doNotPrerenderList, partial);
|
|
163
161
|
const prerenderContextPublic = makePublic(prerenderContext);
|
|
164
|
-
|
|
162
|
+
(0, utils_js_1.objectAssign)(vike.prerenderContext, prerenderContextPublic);
|
|
163
|
+
return { viteConfig };
|
|
165
164
|
}
|
|
166
165
|
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext) {
|
|
167
166
|
// V1 design
|
|
@@ -67,6 +67,7 @@ function getGlobalContextSync() {
|
|
|
67
67
|
}
|
|
68
68
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
69
69
|
async function getGlobalContextAsync(isProduction) {
|
|
70
|
+
debug('getGlobalContextAsync()');
|
|
70
71
|
(0, utils_js_1.assertUsage)(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${picocolors_1.default.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${picocolors_1.default.cyan('true')} or ${picocolors_1.default.cyan('false')}`}`);
|
|
71
72
|
setIsProduction(isProduction);
|
|
72
73
|
if (!globalObject.globalContext)
|
|
@@ -72,9 +72,6 @@ function onSetupPrerender() {
|
|
|
72
72
|
// Called by ../node/api/preview.ts
|
|
73
73
|
function onSetupPreview() {
|
|
74
74
|
markSetup_isPreview();
|
|
75
|
-
if (getNodeEnv())
|
|
76
|
-
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
77
|
-
setNodeEnvProduction();
|
|
78
75
|
}
|
|
79
76
|
function isTest() {
|
|
80
77
|
return (0, isVitest_js_1.isVitest)() || isNodeEnv('test');
|
|
@@ -16,13 +16,24 @@ const PROJECT_VERSION_js_1 = require("./PROJECT_VERSION.js");
|
|
|
16
16
|
/* Use original assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
17
17
|
import { assertWarning } from './assert.js'
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let globalObject;
|
|
20
|
+
// getGlobalObjectSafe() can be called before this line
|
|
21
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
22
|
+
function genGlobalConfig() {
|
|
23
|
+
return (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
|
|
24
|
+
instances: [],
|
|
25
|
+
alreadyLogged: new Set()
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// We need getGlobalObjectSafe() because globalObject is `undefined` when exported functions are called before globalObject is initialized
|
|
29
|
+
function getGlobalObjectSafe() {
|
|
30
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
31
|
+
return globalObject;
|
|
32
|
+
}
|
|
23
33
|
const clientRuntimesClonflict = 'Client runtime of both Server Routing and Client Routing loaded https://vike.dev/client-runtimes-conflict';
|
|
24
34
|
const clientNotSingleInstance = 'Client runtime loaded twice https://vike.dev/client-runtime-duplicated';
|
|
25
35
|
function assertSingleInstance() {
|
|
36
|
+
const globalObject = getGlobalObjectSafe();
|
|
26
37
|
{
|
|
27
38
|
const versions = (0, unique_js_1.unique)(globalObject.instances);
|
|
28
39
|
assertWarning(versions.length <= 1,
|
|
@@ -39,6 +50,7 @@ function assertSingleInstance() {
|
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
53
|
+
const globalObject = getGlobalObjectSafe();
|
|
42
54
|
assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
|
|
43
55
|
onlyOnce: true,
|
|
44
56
|
showStackTrace: true
|
|
@@ -53,6 +65,7 @@ function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
|
53
65
|
assertSingleInstance();
|
|
54
66
|
}
|
|
55
67
|
function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
68
|
+
const globalObject = getGlobalObjectSafe();
|
|
56
69
|
assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
|
|
57
70
|
onlyOnce: true,
|
|
58
71
|
showStackTrace: true
|
|
@@ -68,10 +81,12 @@ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
|
68
81
|
}
|
|
69
82
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
70
83
|
function assertSingleInstance_onAssertModuleLoad() {
|
|
84
|
+
const globalObject = getGlobalObjectSafe();
|
|
71
85
|
globalObject.instances.push(PROJECT_VERSION_js_1.PROJECT_VERSION);
|
|
72
86
|
assertSingleInstance();
|
|
73
87
|
}
|
|
74
88
|
function assertWarning(condition, errorMessage, { onlyOnce, showStackTrace }) {
|
|
89
|
+
const globalObject = getGlobalObjectSafe();
|
|
75
90
|
if (condition) {
|
|
76
91
|
return;
|
|
77
92
|
}
|
|
@@ -19,7 +19,7 @@ async function preview(options = {}) {
|
|
|
19
19
|
const outDir = getOutDirs(viteConfigResolved).outDirRoot;
|
|
20
20
|
const { outServerIndex } = await importServerProductionIndex({ outDir });
|
|
21
21
|
const outServerIndexRelative = path.relative(viteConfigResolved.root, outServerIndex);
|
|
22
|
-
assertWarning(false, `Never run ${pc.cyan('$ vike preview')} in production, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead.`, { onlyOnce: true });
|
|
22
|
+
assertWarning(false, `Never run ${pc.cyan('$ vike preview')} in production, run ${pc.cyan(`$ node ${outServerIndexRelative}`)} instead (or Bun/Deno).`, { onlyOnce: true });
|
|
23
23
|
return {
|
|
24
24
|
viteConfig: viteConfigResolved
|
|
25
25
|
};
|
|
@@ -90,7 +90,7 @@ async function triggerFullBuild(config, vikeConfig, viteEnv, bundle) {
|
|
|
90
90
|
// The server bulid is already called by builder.buildApp()
|
|
91
91
|
}
|
|
92
92
|
if (isPrerenderAutoRunEnabled(vikeConfig)) {
|
|
93
|
-
const res = await runPrerenderFromAutoRun(configInline
|
|
93
|
+
const res = await runPrerenderFromAutoRun(configInline);
|
|
94
94
|
forceExit = res.forceExit;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -20,8 +20,13 @@ declare module 'vite' {
|
|
|
20
20
|
type VikeConfigPublic = {
|
|
21
21
|
config: VikeConfigObject['global']['config'];
|
|
22
22
|
pages: VikeConfigObject['pages'];
|
|
23
|
-
prerenderContext
|
|
23
|
+
prerenderContext: PrerenderContext;
|
|
24
24
|
};
|
|
25
|
+
type PrerenderContext = {
|
|
26
|
+
isPrerenderingEnabled: boolean;
|
|
27
|
+
} & ({
|
|
28
|
+
[K in keyof PrerenderContextPublic]: null;
|
|
29
|
+
} | PrerenderContextPublic);
|
|
25
30
|
declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
|
|
26
31
|
/**
|
|
27
32
|
* Get all the information Vike knows about the app in your Vite plugin.
|
|
@@ -14,6 +14,8 @@ import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
|
14
14
|
import { resolvePrerenderConfigGlobal } from '../../prerender/resolvePrerenderConfig.js';
|
|
15
15
|
const pluginName = 'vike:commonConfig';
|
|
16
16
|
function commonConfig(vikeVitePluginOptions) {
|
|
17
|
+
// We cache it => makes sure we only generate one object => we can mutate it at runPrerender()
|
|
18
|
+
let prerenderContext;
|
|
17
19
|
return [
|
|
18
20
|
{
|
|
19
21
|
name: `${pluginName}:pre`,
|
|
@@ -26,6 +28,9 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
26
28
|
const root = configFromUser.root ? normalizeViteRoot(configFromUser.root) : await getViteRoot(operation);
|
|
27
29
|
assert(root);
|
|
28
30
|
const vikeConfig = await getVikeConfig2(root, isDev, vikeVitePluginOptions);
|
|
31
|
+
const { isPrerenderingEnabled } = resolvePrerenderConfigGlobal(vikeConfig);
|
|
32
|
+
prerenderContext ?? (prerenderContext = { isPrerenderingEnabled, output: null, pageContexts: null });
|
|
33
|
+
assert(prerenderContext.isPrerenderingEnabled === isPrerenderingEnabled);
|
|
29
34
|
return {
|
|
30
35
|
_isDev: isDev,
|
|
31
36
|
_root: root,
|
|
@@ -33,11 +38,12 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
33
38
|
_vikeConfigObject: vikeConfig,
|
|
34
39
|
_vike: {
|
|
35
40
|
pages: vikeConfig.pages,
|
|
36
|
-
config: vikeConfig.global.config
|
|
41
|
+
config: vikeConfig.global.config,
|
|
42
|
+
prerenderContext
|
|
37
43
|
},
|
|
38
44
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
39
45
|
configVikePromise: Promise.resolve({
|
|
40
|
-
prerender:
|
|
46
|
+
prerender: isPrerenderingEnabled
|
|
41
47
|
})
|
|
42
48
|
};
|
|
43
49
|
}
|
|
@@ -66,10 +72,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
66
72
|
assertEsm(config.root);
|
|
67
73
|
assertVikeCliOrApi(config);
|
|
68
74
|
temp_supportOldInterface(config);
|
|
69
|
-
|
|
70
|
-
if (config.vitePluginServerEntry?.inject &&
|
|
71
|
-
!resolvePrerenderConfigGlobal(config._vikeConfigObject).isPrerenderingEnabled)
|
|
72
|
-
config.vitePluginServerEntry.disableServerEntryEmit = true;
|
|
75
|
+
emitServerEntryOnlyIfNeeded(config);
|
|
73
76
|
}
|
|
74
77
|
},
|
|
75
78
|
config: {
|
|
@@ -195,3 +198,10 @@ function getVikeConfigPublic(config) {
|
|
|
195
198
|
assert(vikeConfig);
|
|
196
199
|
return vikeConfig;
|
|
197
200
|
}
|
|
201
|
+
// Only emit dist/server/entry.mjs if necessary
|
|
202
|
+
function emitServerEntryOnlyIfNeeded(config) {
|
|
203
|
+
if (config.vitePluginServerEntry?.inject &&
|
|
204
|
+
!resolvePrerenderConfigGlobal(config._vikeConfigObject).isPrerenderingEnabled) {
|
|
205
|
+
config.vitePluginServerEntry.disableServerEntryEmit = true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -7,6 +7,7 @@ import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
|
|
|
7
7
|
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
8
8
|
import { getExportNames } from '../shared/parseEsModule.js';
|
|
9
9
|
import { normalizeId } from '../shared/normalizeId.js';
|
|
10
|
+
import { isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
10
11
|
function fileEnv() {
|
|
11
12
|
let config;
|
|
12
13
|
let viteDevServer;
|
|
@@ -16,6 +17,8 @@ function fileEnv() {
|
|
|
16
17
|
// 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.
|
|
17
18
|
if (!viteDevServer)
|
|
18
19
|
return;
|
|
20
|
+
if (!isV1Design(config))
|
|
21
|
+
return;
|
|
19
22
|
if (skip(id))
|
|
20
23
|
return;
|
|
21
24
|
// For `.vue` files: https://github.com/vikejs/vike/issues/1912#issuecomment-2394981475
|
|
@@ -46,7 +46,7 @@ declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<{
|
|
|
46
46
|
viteConfig: ResolvedConfig;
|
|
47
47
|
}>;
|
|
48
48
|
declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
|
|
49
|
-
declare function runPrerenderFromAutoRun(viteConfig: InlineConfig | undefined
|
|
49
|
+
declare function runPrerenderFromAutoRun(viteConfig: InlineConfig | undefined): Promise<{
|
|
50
50
|
forceExit: boolean;
|
|
51
51
|
}>;
|
|
52
52
|
declare function runPrerender_forceExit(): void;
|
|
@@ -50,11 +50,9 @@ async function runPrerenderFromCLIPrerenderCommand() {
|
|
|
50
50
|
runPrerender_forceExit();
|
|
51
51
|
assert(false);
|
|
52
52
|
}
|
|
53
|
-
async function runPrerenderFromAutoRun(viteConfig
|
|
54
|
-
let prerenderContextPublic;
|
|
53
|
+
async function runPrerenderFromAutoRun(viteConfig) {
|
|
55
54
|
try {
|
|
56
|
-
|
|
57
|
-
prerenderContextPublic = ret.prerenderContextPublic;
|
|
55
|
+
await runPrerender({ viteConfig });
|
|
58
56
|
}
|
|
59
57
|
catch (err) {
|
|
60
58
|
// Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
|
|
@@ -62,8 +60,6 @@ async function runPrerenderFromAutoRun(viteConfig, config) {
|
|
|
62
60
|
logErrorHint(err);
|
|
63
61
|
process.exit(1);
|
|
64
62
|
}
|
|
65
|
-
const vike = getVikeConfigPublic(config);
|
|
66
|
-
vike.prerenderContext = prerenderContextPublic;
|
|
67
63
|
const forceExit = isVikeCli() || isViteCliCall();
|
|
68
64
|
return { forceExit };
|
|
69
65
|
}
|
|
@@ -80,6 +76,8 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
80
76
|
await disableReactStreaming();
|
|
81
77
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'build', 'production');
|
|
82
78
|
const vikeConfig = await getVikeConfig(viteConfig);
|
|
79
|
+
const vike = getVikeConfigPublic(viteConfig);
|
|
80
|
+
assert(vike.prerenderContext.isPrerenderingEnabled);
|
|
83
81
|
const { outDirClient } = getOutDirs(viteConfig);
|
|
84
82
|
const { root } = viteConfig;
|
|
85
83
|
const prerenderConfigGlobal = resolvePrerenderConfigGlobal(vikeConfig);
|
|
@@ -123,7 +121,8 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
123
121
|
}
|
|
124
122
|
await warnMissingPages(prerenderContext.prerenderedPageContexts, globalContext, doNotPrerenderList, partial);
|
|
125
123
|
const prerenderContextPublic = makePublic(prerenderContext);
|
|
126
|
-
|
|
124
|
+
objectAssign(vike.prerenderContext, prerenderContextPublic);
|
|
125
|
+
return { viteConfig };
|
|
127
126
|
}
|
|
128
127
|
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext) {
|
|
129
128
|
// V1 design
|
|
@@ -64,6 +64,7 @@ function getGlobalContextSync() {
|
|
|
64
64
|
}
|
|
65
65
|
/** @experimental https://vike.dev/getGlobalContext */
|
|
66
66
|
async function getGlobalContextAsync(isProduction) {
|
|
67
|
+
debug('getGlobalContextAsync()');
|
|
67
68
|
assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
|
|
68
69
|
setIsProduction(isProduction);
|
|
69
70
|
if (!globalObject.globalContext)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.226-commit-a0035ee";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.226-commit-a0035ee';
|
|
@@ -67,9 +67,6 @@ function onSetupPrerender() {
|
|
|
67
67
|
// Called by ../node/api/preview.ts
|
|
68
68
|
function onSetupPreview() {
|
|
69
69
|
markSetup_isPreview();
|
|
70
|
-
if (getNodeEnv())
|
|
71
|
-
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
72
|
-
setNodeEnvProduction();
|
|
73
70
|
}
|
|
74
71
|
function isTest() {
|
|
75
72
|
return isVitest() || isNodeEnv('test');
|
|
@@ -11,13 +11,24 @@ import { PROJECT_VERSION } from './PROJECT_VERSION.js';
|
|
|
11
11
|
/* Use original assertWarning() after all CJS is removed from node_modules/vike/dist/
|
|
12
12
|
import { assertWarning } from './assert.js'
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
let globalObject;
|
|
15
|
+
// getGlobalObjectSafe() can be called before this line
|
|
16
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
17
|
+
function genGlobalConfig() {
|
|
18
|
+
return getGlobalObject('utils/assertSingleInstance.ts', {
|
|
19
|
+
instances: [],
|
|
20
|
+
alreadyLogged: new Set()
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
// We need getGlobalObjectSafe() because globalObject is `undefined` when exported functions are called before globalObject is initialized
|
|
24
|
+
function getGlobalObjectSafe() {
|
|
25
|
+
globalObject ?? (globalObject = genGlobalConfig());
|
|
26
|
+
return globalObject;
|
|
27
|
+
}
|
|
18
28
|
const clientRuntimesClonflict = 'Client runtime of both Server Routing and Client Routing loaded https://vike.dev/client-runtimes-conflict';
|
|
19
29
|
const clientNotSingleInstance = 'Client runtime loaded twice https://vike.dev/client-runtime-duplicated';
|
|
20
30
|
function assertSingleInstance() {
|
|
31
|
+
const globalObject = getGlobalObjectSafe();
|
|
21
32
|
{
|
|
22
33
|
const versions = unique(globalObject.instances);
|
|
23
34
|
assertWarning(versions.length <= 1,
|
|
@@ -34,6 +45,7 @@ function assertSingleInstance() {
|
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
48
|
+
const globalObject = getGlobalObjectSafe();
|
|
37
49
|
assertWarning(globalObject.isClientRouting !== true, clientRuntimesClonflict, {
|
|
38
50
|
onlyOnce: true,
|
|
39
51
|
showStackTrace: true
|
|
@@ -48,6 +60,7 @@ function assertSingleInstance_onClientEntryServerRouting(isProduction) {
|
|
|
48
60
|
assertSingleInstance();
|
|
49
61
|
}
|
|
50
62
|
function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
63
|
+
const globalObject = getGlobalObjectSafe();
|
|
51
64
|
assertWarning(globalObject.isClientRouting !== false, clientRuntimesClonflict, {
|
|
52
65
|
onlyOnce: true,
|
|
53
66
|
showStackTrace: true
|
|
@@ -63,10 +76,12 @@ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
|
|
|
63
76
|
}
|
|
64
77
|
// Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
|
|
65
78
|
function assertSingleInstance_onAssertModuleLoad() {
|
|
79
|
+
const globalObject = getGlobalObjectSafe();
|
|
66
80
|
globalObject.instances.push(PROJECT_VERSION);
|
|
67
81
|
assertSingleInstance();
|
|
68
82
|
}
|
|
69
83
|
function assertWarning(condition, errorMessage, { onlyOnce, showStackTrace }) {
|
|
84
|
+
const globalObject = getGlobalObjectSafe();
|
|
70
85
|
if (condition) {
|
|
71
86
|
return;
|
|
72
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.226-commit-a0035ee",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"@brillout/json-serializer": "^0.5.15",
|
|
124
124
|
"@brillout/picocolors": "^1.0.26",
|
|
125
125
|
"@brillout/require-shim": "^0.1.2",
|
|
126
|
-
"@brillout/vite-plugin-server-entry": "0.
|
|
126
|
+
"@brillout/vite-plugin-server-entry": "^0.7.1",
|
|
127
127
|
"acorn": "^8.0.0",
|
|
128
128
|
"cac": "^6.0.0",
|
|
129
129
|
"es-module-lexer": "^1.0.0",
|