vike 0.4.161-commit-ba539a4 → 0.4.161-commit-6a208ab
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/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +10 -3
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +11 -91
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +3 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/prerender/runPrerender.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +8 -19
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -3
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +8 -9
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +11 -4
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +13 -93
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +3 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/prerender/runPrerender.js +2 -1
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +7 -18
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -3
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +8 -9
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +1 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
|
@@ -3,6 +3,7 @@ export { envVarsPlugin };
|
|
|
3
3
|
export { applyEnvVar };
|
|
4
4
|
import { loadEnv } from 'vite';
|
|
5
5
|
import { assert, assertPosixPath, assertUsage, assertWarning, escapeRegex, getFilePathRelativeToUserRootDir, lowerFirst } from '../utils.js';
|
|
6
|
+
import { sourceMapPassthrough } from '../shared/rollupSourceMap.js';
|
|
6
7
|
function envVarsPlugin() {
|
|
7
8
|
let envsAll;
|
|
8
9
|
let config;
|
|
@@ -62,8 +63,11 @@ function envVarsPlugin() {
|
|
|
62
63
|
// Apply
|
|
63
64
|
code = applyEnvVar(envName, envVal, code);
|
|
64
65
|
});
|
|
65
|
-
//
|
|
66
|
-
|
|
66
|
+
// Line numbers didn't change.
|
|
67
|
+
// - We only break the column number of a couple of lines, wich is acceptable.
|
|
68
|
+
// - Anyways, I'm not even sure Vite supports high-resolution column number source mapping.
|
|
69
|
+
const ret = sourceMapPassthrough(code);
|
|
70
|
+
return ret;
|
|
67
71
|
}
|
|
68
72
|
};
|
|
69
73
|
}
|
|
@@ -11,10 +11,11 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js';
|
|
|
11
11
|
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
12
12
|
import { isAsset } from '../shared/isAsset.js';
|
|
13
13
|
import { getImportStatements } from '../shared/parseEsModule.js';
|
|
14
|
-
import {
|
|
14
|
+
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
import { fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
|
|
17
|
-
import { isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
17
|
+
import { getVikeConfig, isV1Design } from './importUserCode/v1-design/getVikeConfig.js';
|
|
18
|
+
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
18
19
|
const extractAssetsRE = /(\?|&)extractAssets(?:&|$)/;
|
|
19
20
|
const rawRE = /(\?|&)raw(?:&|$)/;
|
|
20
21
|
const urlRE = /(\?|&)url(?:&|$)/;
|
|
@@ -25,6 +26,7 @@ const debugEnabled = isDebugEnabled(debugNamespace);
|
|
|
25
26
|
function extractAssetsPlugin() {
|
|
26
27
|
let config;
|
|
27
28
|
let configVike;
|
|
29
|
+
let vikeConfig;
|
|
28
30
|
let isServerAssetsFixEnabled;
|
|
29
31
|
return [
|
|
30
32
|
// This plugin removes all JavaScript from server-side only code, so that only CSS imports remains. (And also satic files imports e.g. `import logoURL from './logo.svg.js'`).
|
|
@@ -37,14 +39,18 @@ function extractAssetsPlugin() {
|
|
|
37
39
|
if (!extractAssetsRE.test(id)) {
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
if (isServerAssetsFixEnabled) {
|
|
43
|
+
// I'm guessing isServerAssetsFixEnabled can only be true when mixing both designs: https://github.com/vikejs/vike/issues/1480
|
|
44
|
+
assertV1Design(true, vikeConfig.pageConfigs);
|
|
45
|
+
assert(false);
|
|
46
|
+
}
|
|
41
47
|
assert(configVike.includeAssetsImportedByServer);
|
|
42
48
|
assert(!viteIsSSR_options(options));
|
|
43
49
|
const importStatements = await getImportStatements(src);
|
|
44
50
|
const moduleNames = getImportedModules(importStatements);
|
|
45
51
|
const code = moduleNames.map((moduleName) => `import '${moduleName}';`).join('\n');
|
|
46
52
|
debugTransformResult(id, code, importStatements);
|
|
47
|
-
return
|
|
53
|
+
return sourceMapRemove(code);
|
|
48
54
|
}
|
|
49
55
|
},
|
|
50
56
|
// This plugin appends `?extractAssets` to module IDs
|
|
@@ -135,6 +141,7 @@ function extractAssetsPlugin() {
|
|
|
135
141
|
async configResolved(config_) {
|
|
136
142
|
configVike = await getConfigVike(config_);
|
|
137
143
|
config = config_;
|
|
144
|
+
vikeConfig = await getVikeConfig(config, false);
|
|
138
145
|
isServerAssetsFixEnabled = fixServerAssets_isEnabled() && (await isV1Design(config, false));
|
|
139
146
|
},
|
|
140
147
|
load(id) {
|
|
@@ -3,7 +3,7 @@ export { isUsingClientRouter };
|
|
|
3
3
|
export { extractExportNamesRE };
|
|
4
4
|
import { assert, getFileExtension, viteIsSSR_options, createDebugger, isDebugEnabled, getGlobalObject, assertUsage } from '../utils.js';
|
|
5
5
|
import { getExportNames } from '../shared/parseEsModule.js';
|
|
6
|
-
import {
|
|
6
|
+
import { sourceMapRemove } from '../shared/rollupSourceMap.js';
|
|
7
7
|
const extractExportNamesRE = /(\?|&)extractExportNames(?:&|$)/;
|
|
8
8
|
const debugNamespace = 'vike:extractExportNames';
|
|
9
9
|
const debug = createDebugger(debugNamespace);
|
|
@@ -38,7 +38,7 @@ async function getExtractExportNamesCode(src, isClientSide, isProduction, id) {
|
|
|
38
38
|
globalObject.usesClientRouter = true;
|
|
39
39
|
}
|
|
40
40
|
const code = getCode(exportNames, wildcardReExports, isClientSide, isProduction, id);
|
|
41
|
-
return
|
|
41
|
+
return sourceMapRemove(code);
|
|
42
42
|
}
|
|
43
43
|
function getCode(exportNames, wildcardReExports, isClientSide, isProduction, id) {
|
|
44
44
|
let code = '';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { getVikeManifest };
|
|
2
|
-
import { ResolvedConfig } from 'vite';
|
|
3
2
|
import { type PluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
4
3
|
import type { ConfigVikeResolved } from '../../../../shared/ConfigVike.js';
|
|
5
|
-
declare function getVikeManifest(
|
|
4
|
+
declare function getVikeManifest(configVike: ConfigVikeResolved): PluginManifest;
|
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
export { getVikeManifest };
|
|
2
|
-
import { projectInfo
|
|
2
|
+
import { projectInfo } from '../../utils.js';
|
|
3
3
|
import { assertPluginManifest } from '../../../shared/assertPluginManifest.js';
|
|
4
4
|
import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
|
|
5
|
-
import path from 'path';
|
|
6
5
|
import { getRuntimeManifest } from '../../../runtime/globalContext.js';
|
|
7
|
-
function getVikeManifest(
|
|
6
|
+
function getVikeManifest(configVike) {
|
|
8
7
|
const runtimeManifest = getRuntimeManifest(configVike);
|
|
9
8
|
const manifest = {
|
|
10
9
|
version: projectInfo.projectVersion,
|
|
11
10
|
usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
|
|
12
|
-
manifestKeyMap: getManifestKeyMap(configVike, config),
|
|
13
11
|
...runtimeManifest
|
|
14
12
|
};
|
|
15
13
|
assertPluginManifest(manifest);
|
|
16
14
|
return manifest;
|
|
17
15
|
}
|
|
18
|
-
function getManifestKeyMap(configVike, config) {
|
|
19
|
-
const manifestKeyMap = {};
|
|
20
|
-
configVike.extensions
|
|
21
|
-
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
22
|
-
.flat()
|
|
23
|
-
.filter(isNotNullish)
|
|
24
|
-
.forEach(({ importPath, filePath }) => {
|
|
25
|
-
// Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
|
|
26
|
-
const filePathRelative = path.posix.relative(config.root, toPosixPath(filePath));
|
|
27
|
-
assertPosixPath(filePathRelative);
|
|
28
|
-
assertPosixPath(importPath);
|
|
29
|
-
manifestKeyMap[importPath] = filePathRelative;
|
|
30
|
-
});
|
|
31
|
-
return manifestKeyMap;
|
|
32
|
-
}
|
|
@@ -34,7 +34,7 @@ function importBuild() {
|
|
|
34
34
|
}
|
|
35
35
|
function getEntryCode(config, configVike) {
|
|
36
36
|
const importPath = getImportPath(config);
|
|
37
|
-
const vikeManifest = getVikeManifest(
|
|
37
|
+
const vikeManifest = getVikeManifest(configVike);
|
|
38
38
|
const importerCode = [
|
|
39
39
|
` import { setImportBuildGetters } from '${importPath}';`,
|
|
40
40
|
` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
|
-
import { assert, assertPosixPath, viteIsSSR_options,
|
|
2
|
+
import { assert, assertPosixPath, viteIsSSR_options, scriptFileExtensions, debugGlob, getOutDirs, isVersionOrAbove } from '../../utils.js';
|
|
3
3
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
4
|
-
import {
|
|
4
|
+
import { version as viteVersion } from 'vite';
|
|
5
|
+
import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
5
6
|
import path from 'path';
|
|
6
7
|
import { getVirtualFilePageConfigs } from './v1-design/getVirtualFilePageConfigs.js';
|
|
7
|
-
import { generateEagerImport } from './generateEagerImport.js';
|
|
8
8
|
async function getVirtualFileImportUserCode(id, options, configVike, config, isDev) {
|
|
9
9
|
const idParsed = isVirtualFileIdImportUserCode(id);
|
|
10
10
|
assert(idParsed);
|
|
@@ -21,53 +21,13 @@ async function getCode(config, configVike, isForClientSide, isClientRouting, isP
|
|
|
21
21
|
assert(isDev === !isBuild);
|
|
22
22
|
let content = '';
|
|
23
23
|
{
|
|
24
|
-
const globRoots = getGlobRoots(config
|
|
24
|
+
const globRoots = getGlobRoots(config);
|
|
25
25
|
debugGlob('Glob roots: ', globRoots);
|
|
26
26
|
content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, configVike, isPrerendering, config, isDev, id);
|
|
27
27
|
}
|
|
28
|
-
{
|
|
29
|
-
const extensionsImportPaths = configVike.extensions
|
|
30
|
-
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
31
|
-
.flat()
|
|
32
|
-
.filter(isNotNullish)
|
|
33
|
-
.map(({ importPath }) => importPath);
|
|
34
|
-
content += generateExtensionImports(extensionsImportPaths, isForClientSide, isBuild, isClientRouting, isPrerendering);
|
|
35
|
-
}
|
|
36
28
|
debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
|
|
37
29
|
return content;
|
|
38
30
|
}
|
|
39
|
-
function generateExtensionImports(extensionsImportPaths, isForClientSide, isBuild, isClientRouting, isPrerendering) {
|
|
40
|
-
let fileContent = '\n\n';
|
|
41
|
-
extensionsImportPaths
|
|
42
|
-
.filter((importPath) => {
|
|
43
|
-
assert(
|
|
44
|
-
// V1 design
|
|
45
|
-
importPath.includes('+') ||
|
|
46
|
-
// V0.4 design
|
|
47
|
-
importPath.includes('.page.'));
|
|
48
|
-
return !importPath.includes('+');
|
|
49
|
-
})
|
|
50
|
-
.forEach((importPath) => {
|
|
51
|
-
const fileType = determineFileType(importPath);
|
|
52
|
-
const { includeImport, includeExportNames } = determineInjection({
|
|
53
|
-
fileType,
|
|
54
|
-
isForClientSide,
|
|
55
|
-
isClientRouting,
|
|
56
|
-
isPrerendering,
|
|
57
|
-
isBuild
|
|
58
|
-
});
|
|
59
|
-
if (includeImport) {
|
|
60
|
-
fileContent += addImport(importPath, fileType, false, isBuild);
|
|
61
|
-
}
|
|
62
|
-
if (includeExportNames) {
|
|
63
|
-
fileContent += addImport(importPath, fileType, true, isBuild);
|
|
64
|
-
}
|
|
65
|
-
if (!includeImport && !includeExportNames && !isForClientSide) {
|
|
66
|
-
fileContent += `pageFilesList.push("${importPath}");` + '\n';
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
return fileContent;
|
|
70
|
-
}
|
|
71
31
|
function determineInjection({ fileType, isForClientSide, isClientRouting, isPrerendering, isBuild }) {
|
|
72
32
|
if (!isForClientSide) {
|
|
73
33
|
return {
|
|
@@ -93,42 +53,6 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
|
|
|
93
53
|
}
|
|
94
54
|
}
|
|
95
55
|
}
|
|
96
|
-
function addImport(importPath, fileType, exportNames, isBuild) {
|
|
97
|
-
const pageFilesVar = (() => {
|
|
98
|
-
if (exportNames) {
|
|
99
|
-
if (isBuild) {
|
|
100
|
-
return 'pageFilesExportNamesEager';
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return 'pageFilesExportNamesLazy';
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if (fileType === '.page.route') {
|
|
108
|
-
return 'pageFilesEager';
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
return 'pageFilesLazy';
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
})();
|
|
115
|
-
const query = !exportNames ? '' : '?extractExportNames';
|
|
116
|
-
let fileContent = '';
|
|
117
|
-
const mapVar = `${pageFilesVar}['${fileType}']`;
|
|
118
|
-
fileContent += `${mapVar} = ${mapVar} ?? {};\n`;
|
|
119
|
-
const value = (() => {
|
|
120
|
-
if (!pageFilesVar.endsWith('Eager')) {
|
|
121
|
-
return `() => import('${importPath}${query}')`;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
const { importName, importStatement } = generateEagerImport(`${importPath}${query}`);
|
|
125
|
-
fileContent += importStatement + '\n';
|
|
126
|
-
return importName;
|
|
127
|
-
}
|
|
128
|
-
})();
|
|
129
|
-
fileContent += `${mapVar}['${importPath}'] = ${value};\n`;
|
|
130
|
-
return fileContent;
|
|
131
|
-
}
|
|
132
56
|
async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, configVike, isPrerendering, config, isDev, id) {
|
|
133
57
|
let fileContent = `// Generatead by node/plugin/plugins/virtualFiles/index.ts
|
|
134
58
|
|
|
@@ -206,10 +130,15 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
206
130
|
varNameLocals.push(varNameLocal);
|
|
207
131
|
const globIncludePath = `'${getGlobPath(globRoot.includeDir, fileType)}'`;
|
|
208
132
|
const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
|
|
209
|
-
const globOptions =
|
|
210
|
-
|
|
133
|
+
const globOptions = { eager: isEager };
|
|
134
|
+
if (isVersionOrAbove(viteVersion, '5.1.0')) {
|
|
135
|
+
globOptions.as = query;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
globOptions.query = `?${query}`;
|
|
139
|
+
}
|
|
211
140
|
const globPaths = globExcludePath ? `[${globIncludePath}, ${globExcludePath}]` : `[${globIncludePath}]`;
|
|
212
|
-
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${globOptions});`;
|
|
141
|
+
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${JSON.stringify(globOptions)});`;
|
|
213
142
|
return globLine;
|
|
214
143
|
}),
|
|
215
144
|
`const ${varName} = {${varNameLocals.map((varNameLocal) => `...${varNameLocal}`).join(',')}};`,
|
|
@@ -217,22 +146,13 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
217
146
|
''
|
|
218
147
|
].join('\n');
|
|
219
148
|
}
|
|
220
|
-
function getGlobRoots(config
|
|
149
|
+
function getGlobRoots(config) {
|
|
221
150
|
const globRoots = [
|
|
222
151
|
{
|
|
223
152
|
includeDir: '/',
|
|
224
153
|
excludeDir: path.posix.relative(config.root, getOutDirs(config).outDirRoot)
|
|
225
154
|
}
|
|
226
155
|
];
|
|
227
|
-
configVike.extensions
|
|
228
|
-
.map(({ pageConfigsSrcDir }) => pageConfigsSrcDir)
|
|
229
|
-
.filter(isNotNullish)
|
|
230
|
-
.forEach((pageConfigsSrcDir) => {
|
|
231
|
-
const globRoot = {
|
|
232
|
-
includeDir: path.posix.relative(config.root, pageConfigsSrcDir)
|
|
233
|
-
};
|
|
234
|
-
globRoots.push(globRoot);
|
|
235
|
-
});
|
|
236
156
|
return globRoots;
|
|
237
157
|
}
|
|
238
158
|
function getGlobPath(globRootDir, fileType) {
|
|
@@ -3,6 +3,7 @@ export { reloadVikeConfig };
|
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
5
|
export { isV1Design };
|
|
6
|
+
export type { VikeConfig };
|
|
6
7
|
export type { InterfaceValueFile };
|
|
7
8
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime, FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
8
9
|
import type { ExtensionResolved } from '../../../../../shared/ConfigVike.js';
|
|
@@ -72,7 +72,9 @@ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, exten
|
|
|
72
72
|
return await vikeConfigPromise;
|
|
73
73
|
}
|
|
74
74
|
async function isV1Design(config, isDev) {
|
|
75
|
-
const
|
|
75
|
+
const vikeConfig = await getVikeConfig(config, isDev);
|
|
76
|
+
const { pageConfigs } = vikeConfig;
|
|
77
|
+
const isV1Design = pageConfigs.length > 0;
|
|
76
78
|
return isV1Design;
|
|
77
79
|
}
|
|
78
80
|
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
|
-
import { setGlobalContext_viteDevServer
|
|
2
|
+
import { setGlobalContext_viteDevServer } from '../../runtime/globalContext.js';
|
|
3
3
|
function setGlobalContext() {
|
|
4
4
|
return {
|
|
5
5
|
name: 'vike:setGlobalContext',
|
|
@@ -9,20 +9,6 @@ function setGlobalContext() {
|
|
|
9
9
|
handler(viteDevServer) {
|
|
10
10
|
setGlobalContext_viteDevServer(viteDevServer);
|
|
11
11
|
}
|
|
12
|
-
},
|
|
13
|
-
configurePreviewServer: {
|
|
14
|
-
order: 'pre',
|
|
15
|
-
handler(vitePreviewServer) {
|
|
16
|
-
setGlobalContext_vitePreviewServer(
|
|
17
|
-
// Type cast won't be necessary after https://github.com/vitejs/vite/pull/14119 is released in Vite 5
|
|
18
|
-
vitePreviewServer);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
configResolved: {
|
|
22
|
-
order: 'pre',
|
|
23
|
-
handler(config) {
|
|
24
|
-
setGlobalContext_viteConfig(config);
|
|
25
|
-
}
|
|
26
12
|
}
|
|
27
13
|
};
|
|
28
14
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { sourceMapRemove };
|
|
2
|
+
export { sourceMapPassthrough };
|
|
3
|
+
/** Remove entire source mapping, to save KBs. */
|
|
4
|
+
declare function sourceMapRemove(code: string): {
|
|
5
|
+
code: string;
|
|
6
|
+
map: {
|
|
7
|
+
mappings: '';
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** Don't provide any source map, pass through current source map instead. */
|
|
11
|
+
declare function sourceMapPassthrough(code: string): {
|
|
12
|
+
code: string;
|
|
13
|
+
map: null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { sourceMapRemove };
|
|
2
|
+
export { sourceMapPassthrough };
|
|
3
|
+
// https://rollupjs.org/guide/en/#source-code-transformations
|
|
4
|
+
/** Remove entire source mapping, to save KBs. */
|
|
5
|
+
function sourceMapRemove(code) {
|
|
6
|
+
return {
|
|
7
|
+
code,
|
|
8
|
+
map: { mappings: '' }
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Don't provide any source map, pass through current source map instead. */
|
|
12
|
+
function sourceMapPassthrough(code) {
|
|
13
|
+
return {
|
|
14
|
+
code,
|
|
15
|
+
map: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -10,7 +10,7 @@ import { pLimit } from '../../utils/pLimit.js';
|
|
|
10
10
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import { cpus } from 'os';
|
|
13
|
-
import { getGlobalContext, initGlobalContext } from '../runtime/globalContext.js';
|
|
13
|
+
import { getGlobalContext, initGlobalContext, setGlobalContext_prerender } from '../runtime/globalContext.js';
|
|
14
14
|
import { resolveConfig } from 'vite';
|
|
15
15
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
16
16
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
@@ -62,6 +62,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
62
62
|
handleNodeEnv();
|
|
63
63
|
await disableReactStreaming();
|
|
64
64
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
65
|
+
setGlobalContext_prerender(viteConfig);
|
|
65
66
|
assertLoadedConfig(viteConfig, options);
|
|
66
67
|
const configVike = await getConfigVike(viteConfig);
|
|
67
68
|
const { outDirClient, outDirRoot } = getOutDirs(viteConfig);
|
|
@@ -3,11 +3,10 @@ export { getGlobalContext };
|
|
|
3
3
|
export { getViteDevServer };
|
|
4
4
|
export { getViteConfig };
|
|
5
5
|
export { setGlobalContext_viteDevServer };
|
|
6
|
-
export {
|
|
7
|
-
export { setGlobalContext_viteConfig };
|
|
6
|
+
export { setGlobalContext_prerender };
|
|
8
7
|
export { getRuntimeManifest };
|
|
9
8
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
10
|
-
import type { ResolvedConfig, ViteDevServer
|
|
9
|
+
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
11
10
|
import { PluginManifest } from '../shared/assertPluginManifest.js';
|
|
12
11
|
import type { ConfigVikeResolved } from '../../shared/ConfigVike.js';
|
|
13
12
|
import { type RuntimeManifest } from '../shared/assertRuntimeManifest.js';
|
|
@@ -22,9 +21,7 @@ type GlobalContext = {
|
|
|
22
21
|
isProduction: false;
|
|
23
22
|
isPrerendering: false;
|
|
24
23
|
viteConfig: ResolvedConfig;
|
|
25
|
-
configVike: ConfigVikeResolved;
|
|
26
24
|
viteDevServer: ViteDevServer;
|
|
27
|
-
vitePreviewServer: null;
|
|
28
25
|
clientManifest: null;
|
|
29
26
|
pluginManifest: null;
|
|
30
27
|
} | ({
|
|
@@ -32,21 +29,17 @@ type GlobalContext = {
|
|
|
32
29
|
clientManifest: ViteManifest;
|
|
33
30
|
pluginManifest: PluginManifest;
|
|
34
31
|
viteDevServer: null;
|
|
35
|
-
vitePreviewServer: null | VitePreviewServer;
|
|
36
32
|
} & ({
|
|
37
33
|
isPrerendering: false;
|
|
38
34
|
viteConfig: null;
|
|
39
|
-
configVike: null;
|
|
40
35
|
} | {
|
|
41
36
|
isPrerendering: true;
|
|
42
37
|
viteConfig: ResolvedConfig;
|
|
43
|
-
configVike: ConfigVikeResolved;
|
|
44
38
|
})));
|
|
45
39
|
declare function getGlobalContext(): GlobalContext;
|
|
46
40
|
declare function setGlobalContext_viteDevServer(viteDevServer: ViteDevServer): void;
|
|
47
|
-
declare function setGlobalContext_vitePreviewServer(vitePreviewServer: VitePreviewServer): void;
|
|
48
41
|
declare function getViteDevServer(): ViteDevServer | null;
|
|
49
|
-
declare function
|
|
42
|
+
declare function setGlobalContext_prerender(viteConfig: ResolvedConfig): void;
|
|
50
43
|
declare function getViteConfig(): ResolvedConfig | null;
|
|
51
44
|
declare function initGlobalContext(isPrerendering?: boolean, outDir?: string): Promise<void>;
|
|
52
45
|
declare function getRuntimeManifest(configVike: ConfigVikeResolved): RuntimeManifest;
|
|
@@ -3,8 +3,7 @@ export { getGlobalContext };
|
|
|
3
3
|
export { getViteDevServer };
|
|
4
4
|
export { getViteConfig };
|
|
5
5
|
export { setGlobalContext_viteDevServer };
|
|
6
|
-
export {
|
|
7
|
-
export { setGlobalContext_viteConfig };
|
|
6
|
+
export { setGlobalContext_prerender };
|
|
8
7
|
export { getRuntimeManifest };
|
|
9
8
|
import { assert, assertUsage, getGlobalObject, getNodeEnv, getNodeEnvDesc, isNodeEnvDev, isPlainObject, objectAssign } from './utils.js';
|
|
10
9
|
import { loadImportBuild } from './globalContext/loadImportBuild.js';
|
|
@@ -22,18 +21,14 @@ function setGlobalContext_viteDevServer(viteDevServer) {
|
|
|
22
21
|
if (globalObject.viteDevServer)
|
|
23
22
|
return;
|
|
24
23
|
assert(!globalObject.globalContext);
|
|
25
|
-
globalObject.viteDevServer = viteDevServer;
|
|
26
|
-
}
|
|
27
|
-
function setGlobalContext_vitePreviewServer(vitePreviewServer) {
|
|
28
|
-
if (globalObject.vitePreviewServer)
|
|
29
|
-
return;
|
|
30
24
|
assert(!globalObject.globalContext);
|
|
31
|
-
globalObject.
|
|
25
|
+
globalObject.viteConfig = viteDevServer.config;
|
|
26
|
+
globalObject.viteDevServer = viteDevServer;
|
|
32
27
|
}
|
|
33
28
|
function getViteDevServer() {
|
|
34
29
|
return globalObject.viteDevServer ?? null;
|
|
35
30
|
}
|
|
36
|
-
function
|
|
31
|
+
function setGlobalContext_prerender(viteConfig) {
|
|
37
32
|
if (globalObject.viteConfig)
|
|
38
33
|
return;
|
|
39
34
|
assert(!globalObject.globalContext);
|
|
@@ -45,13 +40,12 @@ function getViteConfig() {
|
|
|
45
40
|
async function initGlobalContext(isPrerendering = false, outDir) {
|
|
46
41
|
if (globalObject.globalContext)
|
|
47
42
|
return;
|
|
48
|
-
const { viteDevServer,
|
|
43
|
+
const { viteDevServer, viteConfig } = globalObject;
|
|
49
44
|
assertNodeEnv(!!viteDevServer);
|
|
50
45
|
const isProduction = !viteDevServer;
|
|
51
46
|
if (!isProduction) {
|
|
52
47
|
assert(viteConfig);
|
|
53
48
|
assert(!isPrerendering);
|
|
54
|
-
assert(!vitePreviewServer);
|
|
55
49
|
const configVike = await getConfigVike(viteConfig);
|
|
56
50
|
const pluginManifest = getRuntimeManifest(configVike);
|
|
57
51
|
globalObject.globalContext = {
|
|
@@ -60,9 +54,7 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
60
54
|
clientManifest: null,
|
|
61
55
|
pluginManifest: null,
|
|
62
56
|
viteDevServer,
|
|
63
|
-
vitePreviewServer: null,
|
|
64
57
|
viteConfig,
|
|
65
|
-
configVike,
|
|
66
58
|
baseServer: pluginManifest.baseServer,
|
|
67
59
|
baseAssets: pluginManifest.baseAssets,
|
|
68
60
|
includeAssetsImportedByServer: pluginManifest.includeAssetsImportedByServer,
|
|
@@ -83,7 +75,6 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
83
75
|
clientManifest,
|
|
84
76
|
pluginManifest,
|
|
85
77
|
viteDevServer: null,
|
|
86
|
-
vitePreviewServer: vitePreviewServer ?? null,
|
|
87
78
|
baseServer: pluginManifest.baseServer,
|
|
88
79
|
baseAssets: pluginManifest.baseAssets,
|
|
89
80
|
includeAssetsImportedByServer: pluginManifest.includeAssetsImportedByServer,
|
|
@@ -97,16 +88,14 @@ async function initGlobalContext(isPrerendering = false, outDir) {
|
|
|
97
88
|
assert(configVike);
|
|
98
89
|
objectAssign(globalContext, {
|
|
99
90
|
isPrerendering: true,
|
|
100
|
-
viteConfig
|
|
101
|
-
configVike
|
|
91
|
+
viteConfig
|
|
102
92
|
});
|
|
103
93
|
globalObject.globalContext = globalContext;
|
|
104
94
|
}
|
|
105
95
|
else {
|
|
106
96
|
objectAssign(globalContext, {
|
|
107
97
|
isPrerendering: false,
|
|
108
|
-
viteConfig: null
|
|
109
|
-
configVike: null
|
|
98
|
+
viteConfig: null
|
|
110
99
|
});
|
|
111
100
|
globalObject.globalContext = globalContext;
|
|
112
101
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getManifestEntry };
|
|
2
2
|
import type { ViteManifest, ViteManifestEntry } from '../../../shared/ViteManifest.js';
|
|
3
|
-
declare function getManifestEntry(id: string, clientManifest: ViteManifest
|
|
3
|
+
declare function getManifestEntry(id: string, clientManifest: ViteManifest): {
|
|
4
4
|
manifestKey: string;
|
|
5
5
|
manifestEntry: ViteManifestEntry;
|
|
6
6
|
};
|
|
@@ -3,9 +3,7 @@ import { assert, slice, isNpmPackageImport } from '../../utils.js';
|
|
|
3
3
|
import { assertClientEntryId } from './assertClientEntryId.js';
|
|
4
4
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
|
|
6
|
-
function getManifestEntry(id, clientManifest
|
|
7
|
-
// TODO: remove
|
|
8
|
-
manifestKeyMap) {
|
|
6
|
+
function getManifestEntry(id, clientManifest) {
|
|
9
7
|
assertClientEntryId(id);
|
|
10
8
|
const debugInfo = getDebugInfo(id, clientManifest);
|
|
11
9
|
// Vike client entry
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { retrieveAssetsProd };
|
|
2
2
|
import type { ViteManifest } from '../../../shared/ViteManifest.js';
|
|
3
3
|
import type { ClientDependency } from '../../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
4
|
-
declare function retrieveAssetsProd(clientDependencies: ClientDependency[], clientManifest: ViteManifest, includeAssetsImportedByServer: boolean
|
|
4
|
+
declare function retrieveAssetsProd(clientDependencies: ClientDependency[], clientManifest: ViteManifest, includeAssetsImportedByServer: boolean): string[];
|
|
@@ -2,7 +2,7 @@ export { retrieveAssetsProd };
|
|
|
2
2
|
import { assert, isNpmPackageImport } from '../../utils.js';
|
|
3
3
|
import { getManifestEntry } from './getManifestEntry.js';
|
|
4
4
|
import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
|
|
5
|
-
function retrieveAssetsProd(clientDependencies, clientManifest, includeAssetsImportedByServer
|
|
5
|
+
function retrieveAssetsProd(clientDependencies, clientManifest, includeAssetsImportedByServer) {
|
|
6
6
|
let assetUrls = new Set();
|
|
7
7
|
assert(clientManifest);
|
|
8
8
|
const visistedAssets = new Set();
|
|
@@ -19,7 +19,7 @@ function retrieveAssetsProd(clientDependencies, clientManifest, includeAssetsImp
|
|
|
19
19
|
id = extractAssetsAddQuery(id);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
const { manifestKey } = getManifestEntry(id, clientManifest
|
|
22
|
+
const { manifestKey } = getManifestEntry(id, clientManifest);
|
|
23
23
|
collectAssets(manifestKey, assetUrls, visistedAssets, clientManifest, onlyAssets);
|
|
24
24
|
});
|
|
25
25
|
collectSingleStyle(assetUrls, clientManifest);
|
|
@@ -14,15 +14,14 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
14
14
|
let assetUrls;
|
|
15
15
|
let clientEntriesSrc;
|
|
16
16
|
if (isDev) {
|
|
17
|
-
const { viteDevServer
|
|
18
|
-
clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer
|
|
17
|
+
const { viteDevServer } = globalContext;
|
|
18
|
+
clientEntriesSrc = await Promise.all(clientEntries.map((clientEntry) => resolveClientEntriesDev(clientEntry, viteDevServer)));
|
|
19
19
|
assetUrls = await retrieveAssetsDev(clientDependencies, viteDevServer);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
assetUrls = retrieveAssetsProd(clientDependencies, clientManifest, pageContext._includeAssetsImportedByServer, manifestKeyMap);
|
|
22
|
+
const { clientManifest } = globalContext;
|
|
23
|
+
clientEntriesSrc = clientEntries.map((clientEntry) => resolveClientEntriesProd(clientEntry, clientManifest));
|
|
24
|
+
assetUrls = retrieveAssetsProd(clientDependencies, clientManifest, pageContext._includeAssetsImportedByServer);
|
|
26
25
|
}
|
|
27
26
|
let pageAssets = [];
|
|
28
27
|
unique([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
|
|
@@ -56,7 +55,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
|
|
|
56
55
|
sortPageAssetsForEarlyHintsHeader(pageAssets);
|
|
57
56
|
return pageAssets;
|
|
58
57
|
}
|
|
59
|
-
async function resolveClientEntriesDev(clientEntry, viteDevServer
|
|
58
|
+
async function resolveClientEntriesDev(clientEntry, viteDevServer) {
|
|
60
59
|
assertClientEntryId(clientEntry);
|
|
61
60
|
let root = viteDevServer.config.root;
|
|
62
61
|
assert(root);
|
|
@@ -117,8 +116,8 @@ async function resolveClientEntriesDev(clientEntry, viteDevServer, configVike) {
|
|
|
117
116
|
assertPosixPath(filePath);
|
|
118
117
|
return filePath;
|
|
119
118
|
}
|
|
120
|
-
function resolveClientEntriesProd(clientEntry, clientManifest
|
|
121
|
-
const { manifestEntry } = getManifestEntry(clientEntry, clientManifest
|
|
119
|
+
function resolveClientEntriesProd(clientEntry, clientManifest) {
|
|
120
|
+
const { manifestEntry } = getManifestEntry(clientEntry, clientManifest);
|
|
122
121
|
assert(manifestEntry.isEntry || manifestEntry.isDynamicEntry || clientEntry.endsWith('.css'), { clientEntry });
|
|
123
122
|
let { file } = manifestEntry;
|
|
124
123
|
assert(!file.startsWith('/'));
|