@rspress/core 2.0.0-alpha.1 → 2.0.0-alpha.11
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/index.d.ts +2 -1
- package/dist/index.js +164 -118
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +35 -29
- package/dist/runtime/App.d.ts +0 -6
- package/dist/runtime/App.js +3 -65
- package/dist/runtime/ClientApp.d.ts +4 -0
- package/dist/runtime/ClientApp.js +31 -0
- package/dist/runtime/clientEntry.d.ts +1 -1
- package/dist/runtime/clientEntry.js +18 -63
- package/dist/runtime/initPageData.d.ts +3 -0
- package/dist/runtime/initPageData.js +59 -0
- package/dist/runtime/ssrEntry.js +2 -1
- package/dist/runtime/tsconfig.js +3 -3
- package/package.json +35 -33
package/dist/index.js
CHANGED
|
@@ -4,17 +4,14 @@ import * as __WEBPACK_EXTERNAL_MODULE__rspress_plugin_container_syntax_12d3c700_
|
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__ from "@rspress/shared";
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__ from "node:fs/promises";
|
|
6
6
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
7
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_less_4c557a99__ from "@rsbuild/plugin-less";
|
|
8
7
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__ from "@rsbuild/plugin-react";
|
|
9
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_sass_b13a7d33__ from "@rsbuild/plugin-sass";
|
|
10
8
|
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
11
|
-
import * as
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
12
10
|
import * as __WEBPACK_EXTERNAL_MODULE_picocolors__ from "picocolors";
|
|
13
11
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__ from "@rspress/shared/constants";
|
|
14
12
|
import * as __WEBPACK_EXTERNAL_MODULE_tinyglobby__ from "tinyglobby";
|
|
15
13
|
import * as __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__ from "node:os";
|
|
16
14
|
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
17
|
-
import * as __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__ from "@rspress/shared/logger";
|
|
18
15
|
import * as __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__ from "lodash-es";
|
|
19
16
|
import * as __WEBPACK_EXTERNAL_MODULE_node_crypto_9ba42079__ from "node:crypto";
|
|
20
17
|
import * as __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__ from "@rspress/mdx-rs";
|
|
@@ -25,6 +22,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__mdx_js_mdx_b904bd09__ from "@mdx-js/mdx";
|
|
|
25
22
|
import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced-resolve";
|
|
26
23
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
27
24
|
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
|
|
25
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
28
26
|
export * from "@rspress/shared";
|
|
29
27
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
30
28
|
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
@@ -64,9 +62,9 @@ class PluginDriver {
|
|
|
64
62
|
this.clearPlugins();
|
|
65
63
|
const config = _class_private_field_get(this, _config);
|
|
66
64
|
const themeConfig = (null == config ? void 0 : config.themeConfig) || {};
|
|
67
|
-
const enableLastUpdated = (null == themeConfig ? void 0 : themeConfig.lastUpdated) || (null == themeConfig ? void 0 : null
|
|
65
|
+
const enableLastUpdated = (null == themeConfig ? void 0 : themeConfig.lastUpdated) || (null == themeConfig ? void 0 : null == (_themeConfig_locales = themeConfig.locales) ? void 0 : _themeConfig_locales.some((locale)=>locale.lastUpdated));
|
|
68
66
|
const mediumZoomConfig = (null == config ? void 0 : config.mediumZoom) ?? true;
|
|
69
|
-
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || (null
|
|
67
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || (null == (_themeConfig_locales1 = themeConfig.locales) ? void 0 : null == (_themeConfig_locales_ = _themeConfig_locales1[0]) ? void 0 : _themeConfig_locales_.nav) || (null == (_themeConfig_locales2 = themeConfig.locales) ? void 0 : null == (_themeConfig_locales_1 = _themeConfig_locales2[0]) ? void 0 : _themeConfig_locales_1.sidebar);
|
|
70
68
|
if (enableLastUpdated) {
|
|
71
69
|
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
72
70
|
this.addPlugin(pluginLastUpdated());
|
|
@@ -186,6 +184,37 @@ class PluginDriver {
|
|
|
186
184
|
_class_private_field_set(this, _plugins, []);
|
|
187
185
|
}
|
|
188
186
|
}
|
|
187
|
+
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
188
|
+
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
189
|
+
name: PLUGIN_VIRTUAL_MODULE_NAME,
|
|
190
|
+
async setup (api) {
|
|
191
|
+
const TEMP_DIR = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'node_modules/.rsbuild-virtual-module');
|
|
192
|
+
const { virtualModules = {} } = pluginOptions;
|
|
193
|
+
const virtualFileAbsolutePaths = Object.keys(virtualModules).map((i)=>{
|
|
194
|
+
let absolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(TEMP_DIR, i);
|
|
195
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.extname)(absolutePath)) absolutePath = `${absolutePath}.js`;
|
|
196
|
+
return [
|
|
197
|
+
i,
|
|
198
|
+
absolutePath
|
|
199
|
+
];
|
|
200
|
+
});
|
|
201
|
+
api.onBeforeCreateCompiler(async ()=>{
|
|
202
|
+
await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(TEMP_DIR, {
|
|
203
|
+
recursive: true
|
|
204
|
+
});
|
|
205
|
+
await Promise.all(virtualFileAbsolutePaths.map(([_, absolutePath])=>(0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.writeFile)(absolutePath, '', 'utf-8')));
|
|
206
|
+
});
|
|
207
|
+
api.modifyBundlerChain((chain)=>{
|
|
208
|
+
chain.resolve.alias.merge(Object.fromEntries(virtualFileAbsolutePaths));
|
|
209
|
+
});
|
|
210
|
+
for (const [moduleName, absolutePath] of virtualFileAbsolutePaths){
|
|
211
|
+
const handler = virtualModules[moduleName];
|
|
212
|
+
if (handler) api.transform({
|
|
213
|
+
test: absolutePath
|
|
214
|
+
}, handler);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
189
218
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
190
219
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
191
220
|
const inlineThemeScript = `{
|
|
@@ -193,6 +222,7 @@ const inlineThemeScript = `{
|
|
|
193
222
|
const preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
194
223
|
const isDark = !saved || saved === 'auto' ? preferDark : saved === 'dark'
|
|
195
224
|
document.documentElement.classList.toggle('dark', isDark)
|
|
225
|
+
document.documentElement.classList.toggle('rp-dark', isDark)
|
|
196
226
|
document.documentElement.style.colorScheme = isDark ? 'dark' : 'light'
|
|
197
227
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
198
228
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
@@ -207,7 +237,7 @@ const HTML_START_TAG = '<html';
|
|
|
207
237
|
const BODY_START_TAG = '<body';
|
|
208
238
|
const DEFAULT_TITLE = 'Rspress';
|
|
209
239
|
const PUBLIC_DIR = 'public';
|
|
210
|
-
const
|
|
240
|
+
const constants_TEMP_DIR = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'node_modules', __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR);
|
|
211
241
|
async function pathExists(path) {
|
|
212
242
|
try {
|
|
213
243
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
@@ -220,7 +250,7 @@ async function readJson(path) {
|
|
|
220
250
|
const raw = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(path, 'utf8');
|
|
221
251
|
return JSON.parse(raw);
|
|
222
252
|
}
|
|
223
|
-
const THEME_DEFAULT_EXPORT_PATTERN = /export
|
|
253
|
+
const THEME_DEFAULT_EXPORT_PATTERN = /export\s+default\s+\{/;
|
|
224
254
|
async function hintThemeBreakingChange(customThemeDir) {
|
|
225
255
|
const fileList = [
|
|
226
256
|
'index.ts',
|
|
@@ -236,20 +266,30 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
236
266
|
encoding: 'utf-8'
|
|
237
267
|
});
|
|
238
268
|
if (THEME_DEFAULT_EXPORT_PATTERN.test(content)) useDefaultExportFilePath = filePath;
|
|
269
|
+
break;
|
|
239
270
|
}
|
|
240
271
|
}
|
|
241
|
-
if (useDefaultExportFilePath)
|
|
272
|
+
if (useDefaultExportFilePath) __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`[Rspress v2] Breaking Change: The "theme/index.tsx" is now using named export instead of default export, please update ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].greenBright(useDefaultExportFilePath)} (https://github.com/web-infra-dev/rspress/discussions/1891#discussioncomment-12422737).\n`, __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].redBright(`
|
|
242
273
|
- import Theme from '@rspress/theme-default';
|
|
243
274
|
- export default {
|
|
244
275
|
- ...Theme,
|
|
245
276
|
- Layout,
|
|
246
277
|
- };
|
|
247
|
-
- export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].
|
|
278
|
+
- export * from 'rspress/theme';`) + __WEBPACK_EXTERNAL_MODULE_picocolors__["default"].greenBright(`
|
|
279
|
+
+ import { Layout } from '@rspress/theme-default';
|
|
248
280
|
|
|
249
281
|
+ export { Layout };
|
|
250
282
|
+ export * from 'rspress/theme';
|
|
251
283
|
`));
|
|
252
284
|
}
|
|
285
|
+
function hintSSGFailed() {
|
|
286
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info(`[Rspress v2] \`ssg: true\` requires the source code to support SSR. If the code is not compatible to SSR, the build process will fail. You can try:
|
|
287
|
+
1. Fix code to make it SSR-compatible.
|
|
288
|
+
2. Set \`ssg: false\`, but the SSG feature will be lost.`);
|
|
289
|
+
}
|
|
290
|
+
function hintSSGFalse() {
|
|
291
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
292
|
+
}
|
|
253
293
|
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
254
294
|
function slash(p) {
|
|
255
295
|
return p.replace(/\\/g, '/');
|
|
@@ -261,7 +301,7 @@ function getPageKey(route) {
|
|
|
261
301
|
const cleanRoute = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeLeadingSlash)(route);
|
|
262
302
|
return cleanRoute.replace(/\//g, '_').replace(/\.[^.]+$/, '') || 'index';
|
|
263
303
|
}
|
|
264
|
-
const
|
|
304
|
+
const getRoutePathParts = (routePath, lang, version, langs, versions)=>{
|
|
265
305
|
const hasTrailSlash = routePath.endsWith('/');
|
|
266
306
|
let versionPart = '';
|
|
267
307
|
let langPart = '';
|
|
@@ -282,14 +322,20 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
282
322
|
}
|
|
283
323
|
}
|
|
284
324
|
purePathPart = parts.join('/');
|
|
325
|
+
return [
|
|
326
|
+
versionPart,
|
|
327
|
+
langPart,
|
|
328
|
+
hasTrailSlash ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(purePathPart) : purePathPart
|
|
329
|
+
];
|
|
330
|
+
};
|
|
331
|
+
const normalizeRoutePath = (routePath, base, lang, version, langs, versions, extensions = __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS)=>{
|
|
332
|
+
const [versionPart, langPart, purePathPart] = getRoutePathParts(routePath, lang, version, langs, versions);
|
|
285
333
|
const extensionsWithoutDot = extensions.map((i)=>i.slice(1));
|
|
286
334
|
const cleanExtensionPattern = new RegExp(`\\.(${extensionsWithoutDot.join('|')})$`, 'i');
|
|
287
|
-
|
|
335
|
+
const normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)([
|
|
288
336
|
versionPart,
|
|
289
|
-
langPart
|
|
290
|
-
|
|
291
|
-
].filter(Boolean).join('/')).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
292
|
-
if (hasTrailSlash) normalizedRoutePath = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addTrailingSlash)(normalizedRoutePath);
|
|
337
|
+
langPart
|
|
338
|
+
].filter(Boolean).join('/') + (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(purePathPart)).replace(cleanExtensionPattern, '').replace(/\.html$/, '').replace(/\/index$/, '/');
|
|
293
339
|
return {
|
|
294
340
|
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedRoutePath, base),
|
|
295
341
|
lang: langPart || lang,
|
|
@@ -347,6 +393,9 @@ function _define_property(obj, key, value) {
|
|
|
347
393
|
}
|
|
348
394
|
var _scanDir = /*#__PURE__*/ new WeakMap(), _defaultLang = /*#__PURE__*/ new WeakMap(), _defaultVersion = /*#__PURE__*/ new WeakMap(), _extensions = /*#__PURE__*/ new WeakMap(), _langs = /*#__PURE__*/ new WeakMap(), _versions = /*#__PURE__*/ new WeakMap(), _include = /*#__PURE__*/ new WeakMap(), _exclude = /*#__PURE__*/ new WeakMap(), _base = /*#__PURE__*/ new WeakMap(), _tempDir = /*#__PURE__*/ new WeakMap(), _pluginDriver = /*#__PURE__*/ new WeakMap(), _writeTempFile = /*#__PURE__*/ new WeakSet(), _generateRouteInfo = /*#__PURE__*/ new WeakSet();
|
|
349
395
|
class RouteService {
|
|
396
|
+
get extensions() {
|
|
397
|
+
return RouteService_class_private_field_get(this, _extensions);
|
|
398
|
+
}
|
|
350
399
|
async init() {
|
|
351
400
|
const extensions = RouteService_class_private_field_get(this, _extensions).map((i)=>i.slice(1));
|
|
352
401
|
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
@@ -437,6 +486,9 @@ ${routeMeta.map((route, index)=>{
|
|
|
437
486
|
];
|
|
438
487
|
`;
|
|
439
488
|
}
|
|
489
|
+
getRoutePathParts(routePath) {
|
|
490
|
+
return getRoutePathParts(routePath, RouteService_class_private_field_get(this, _defaultLang), RouteService_class_private_field_get(this, _defaultVersion), RouteService_class_private_field_get(this, _langs), RouteService_class_private_field_get(this, _versions));
|
|
491
|
+
}
|
|
440
492
|
normalizeRoutePath(routePath) {
|
|
441
493
|
return normalizeRoutePath(routePath, RouteService_class_private_field_get(this, _base), RouteService_class_private_field_get(this, _defaultLang), RouteService_class_private_field_get(this, _defaultVersion), RouteService_class_private_field_get(this, _langs), RouteService_class_private_field_get(this, _versions), RouteService_class_private_field_get(this, _extensions));
|
|
442
494
|
}
|
|
@@ -495,7 +547,7 @@ ${routeMeta.map((route, index)=>{
|
|
|
495
547
|
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
496
548
|
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
497
549
|
RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
|
|
498
|
-
RouteService_class_private_field_set(this, _langs, ((null == userConfig ? void 0 : userConfig.locales) ?? (null == userConfig ? void 0 : null
|
|
550
|
+
RouteService_class_private_field_set(this, _langs, ((null == userConfig ? void 0 : userConfig.locales) ?? (null == userConfig ? void 0 : null == (_userConfig_themeConfig = userConfig.themeConfig) ? void 0 : _userConfig_themeConfig.locales) ?? []).map((item)=>item.lang));
|
|
499
551
|
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
500
552
|
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
501
553
|
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
@@ -531,16 +583,10 @@ async function initRouteService(options) {
|
|
|
531
583
|
async function globalStylesVMPlugin(context) {
|
|
532
584
|
const { config, pluginDriver } = context;
|
|
533
585
|
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const styleContent = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(source, 'utf-8');
|
|
537
|
-
const patchedStyleContent = styleContent.replace(/--modern-/g, '--rp-').replace(/\.modern-doc/g, '.rspress').replace(/\.modern-/g, '.rspress-');
|
|
538
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(source, patchedStyleContent, 'utf-8');
|
|
539
|
-
}
|
|
540
|
-
const moduleContent = (await Promise.all([
|
|
541
|
-
(null == config ? void 0 : config.globalStyles) || '',
|
|
586
|
+
const moduleContent = [
|
|
587
|
+
null == config ? void 0 : config.globalStyles,
|
|
542
588
|
...globalStylesByPlugins
|
|
543
|
-
].filter(
|
|
589
|
+
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
544
590
|
return {
|
|
545
591
|
[runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
|
|
546
592
|
};
|
|
@@ -569,25 +615,6 @@ const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
|
569
615
|
[runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
|
|
570
616
|
};
|
|
571
617
|
}
|
|
572
|
-
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
573
|
-
function getI18nData(docConfig) {
|
|
574
|
-
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
575
|
-
try {
|
|
576
|
-
delete require.cache[i18nSourcePath];
|
|
577
|
-
const i18nSource = require(i18nSourcePath);
|
|
578
|
-
return i18nSource;
|
|
579
|
-
} catch (e) {
|
|
580
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
581
|
-
return {};
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
function i18nVMPlugin(context) {
|
|
585
|
-
const { config } = context;
|
|
586
|
-
const i18nData = getI18nData(config);
|
|
587
|
-
return {
|
|
588
|
-
[runtimeModule_RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData, null, 2)}`
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
618
|
async function routeVMPlugin(context) {
|
|
592
619
|
const { routeService, isSSR } = context;
|
|
593
620
|
if (!isSSR) return {
|
|
@@ -671,7 +698,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
671
698
|
}
|
|
672
699
|
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
|
|
673
700
|
var _node_data_estree, _node_data;
|
|
674
|
-
return (null
|
|
701
|
+
return (null == (_node_data = node.data) ? void 0 : null == (_node_data_estree = _node_data.estree) ? void 0 : _node_data_estree.body) || [];
|
|
675
702
|
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
676
703
|
for (const importNode of importNodes){
|
|
677
704
|
const id = importNode.specifiers[0].local.name;
|
|
@@ -841,6 +868,29 @@ function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
|
841
868
|
}
|
|
842
869
|
return aliases;
|
|
843
870
|
}
|
|
871
|
+
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
872
|
+
function getI18nData(docConfig) {
|
|
873
|
+
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
874
|
+
try {
|
|
875
|
+
delete require.cache[i18nSourcePath];
|
|
876
|
+
const i18nSource = require(i18nSourcePath);
|
|
877
|
+
return i18nSource;
|
|
878
|
+
} catch (e) {
|
|
879
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
880
|
+
return {};
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
function i18nVMPlugin(context) {
|
|
884
|
+
const { config } = context;
|
|
885
|
+
return {
|
|
886
|
+
[runtimeModule_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
|
|
887
|
+
addDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
888
|
+
addMissingDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
889
|
+
const i18nData = getI18nData(config);
|
|
890
|
+
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
}
|
|
844
894
|
function normalizeThemeConfig(docConfig, pages = []) {
|
|
845
895
|
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
846
896
|
const { versions = [] } = multiVersion || {};
|
|
@@ -856,7 +906,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
856
906
|
};
|
|
857
907
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
858
908
|
var _i18nTextData_key;
|
|
859
|
-
const text = null
|
|
909
|
+
const text = null == (_i18nTextData_key = i18nTextData[key]) ? void 0 : _i18nTextData_key[currentLang];
|
|
860
910
|
return text || key;
|
|
861
911
|
};
|
|
862
912
|
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
@@ -930,7 +980,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
930
980
|
};
|
|
931
981
|
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
932
982
|
var _themeConfig_locales;
|
|
933
|
-
const localeInThemeConfig = null
|
|
983
|
+
const localeInThemeConfig = null == (_themeConfig_locales = themeConfig.locales) ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
934
984
|
return {
|
|
935
985
|
lang: currentLang,
|
|
936
986
|
label,
|
|
@@ -963,13 +1013,13 @@ async function siteDataVMPlugin(context) {
|
|
|
963
1013
|
const replaceRules = (null == userConfig ? void 0 : userConfig.replaceRules) || [];
|
|
964
1014
|
const searchConfig = (null == userConfig ? void 0 : userConfig.search) || {};
|
|
965
1015
|
const domain = (null == searchConfig ? void 0 : searchConfig.mode) === 'remote' ? searchConfig.domain ?? '' : '';
|
|
966
|
-
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) :
|
|
1016
|
+
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
967
1017
|
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
968
1018
|
await pluginDriver.modifySearchIndexData(pages);
|
|
969
1019
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
970
1020
|
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
971
1021
|
var _page_frontmatter;
|
|
972
|
-
if ((null
|
|
1022
|
+
if ((null == (_page_frontmatter = page.frontmatter) ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
973
1023
|
const version = versioned ? page.version : '';
|
|
974
1024
|
const lang = page.lang || '';
|
|
975
1025
|
return `${version}###${lang}`;
|
|
@@ -983,10 +1033,10 @@ async function siteDataVMPlugin(context) {
|
|
|
983
1033
|
const [version, lang] = group.split('###');
|
|
984
1034
|
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
985
1035
|
const indexLang = lang ? `.${lang}` : '';
|
|
986
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(
|
|
1036
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(constants_TEMP_DIR, {
|
|
987
1037
|
recursive: true
|
|
988
1038
|
});
|
|
989
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(
|
|
1039
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(constants_TEMP_DIR, `${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}${indexVersion}${indexLang}.${indexHash}.json`), stringifiedIndex);
|
|
990
1040
|
}));
|
|
991
1041
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
992
1042
|
const siteData = {
|
|
@@ -997,13 +1047,13 @@ async function siteDataVMPlugin(context) {
|
|
|
997
1047
|
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
998
1048
|
base: (null == userConfig ? void 0 : userConfig.base) || '/',
|
|
999
1049
|
lang: (null == userConfig ? void 0 : userConfig.lang) || '',
|
|
1000
|
-
locales: (null == userConfig ? void 0 : userConfig.locales) || (null
|
|
1050
|
+
locales: (null == userConfig ? void 0 : userConfig.locales) || (null == (_userConfig_themeConfig = userConfig.themeConfig) ? void 0 : _userConfig_themeConfig.locales) || [],
|
|
1001
1051
|
logo: (null == userConfig ? void 0 : userConfig.logo) || '',
|
|
1002
1052
|
logoText: (null == userConfig ? void 0 : userConfig.logoText) || '',
|
|
1003
|
-
ssg: Boolean(null == userConfig ? void 0 : userConfig.ssg) ?? true,
|
|
1053
|
+
ssg: Boolean((null == userConfig ? void 0 : userConfig.ssg) ?? true),
|
|
1004
1054
|
multiVersion: {
|
|
1005
|
-
default: (null == userConfig ? void 0 : null
|
|
1006
|
-
versions: (null == userConfig ? void 0 : null
|
|
1055
|
+
default: (null == userConfig ? void 0 : null == (_userConfig_multiVersion = userConfig.multiVersion) ? void 0 : _userConfig_multiVersion.default) || '',
|
|
1056
|
+
versions: (null == userConfig ? void 0 : null == (_userConfig_multiVersion1 = userConfig.multiVersion) ? void 0 : _userConfig_multiVersion1.versions) || []
|
|
1007
1057
|
},
|
|
1008
1058
|
search: tempSearchObj ?? {
|
|
1009
1059
|
mode: 'local'
|
|
@@ -1016,13 +1066,13 @@ async function siteDataVMPlugin(context) {
|
|
|
1016
1066
|
};
|
|
1017
1067
|
}),
|
|
1018
1068
|
markdown: {
|
|
1019
|
-
showLineNumbers: (null == userConfig ? void 0 : null
|
|
1020
|
-
defaultWrapCode: (null == userConfig ? void 0 : null
|
|
1021
|
-
codeHighlighter: (null == userConfig ? void 0 : null
|
|
1069
|
+
showLineNumbers: (null == userConfig ? void 0 : null == (_userConfig_markdown = userConfig.markdown) ? void 0 : _userConfig_markdown.showLineNumbers) ?? false,
|
|
1070
|
+
defaultWrapCode: (null == userConfig ? void 0 : null == (_userConfig_markdown1 = userConfig.markdown) ? void 0 : _userConfig_markdown1.defaultWrapCode) ?? false,
|
|
1071
|
+
codeHighlighter: (null == userConfig ? void 0 : null == (_userConfig_markdown2 = userConfig.markdown) ? void 0 : _userConfig_markdown2.codeHighlighter) || 'prism'
|
|
1022
1072
|
}
|
|
1023
1073
|
};
|
|
1024
1074
|
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1025
|
-
if (Array.isArray(null
|
|
1075
|
+
if (Array.isArray(null == (_siteData_pages_ = siteData.pages[0]) ? void 0 : _siteData_pages_.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1026
1076
|
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1027
1077
|
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1028
1078
|
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
@@ -1042,7 +1092,6 @@ const runtimeModuleFactory = [
|
|
|
1042
1092
|
siteDataVMPlugin,
|
|
1043
1093
|
globalUIComponentsVMPlugin,
|
|
1044
1094
|
globalStylesVMPlugin,
|
|
1045
|
-
i18nVMPlugin,
|
|
1046
1095
|
searchHookVMPlugin
|
|
1047
1096
|
];
|
|
1048
1097
|
function rsbuildPluginDocVM(factoryContext) {
|
|
@@ -1088,7 +1137,7 @@ async function writeSearchIndex(config) {
|
|
|
1088
1137
|
var _config_search;
|
|
1089
1138
|
if ((null == config ? void 0 : config.search) === false) return;
|
|
1090
1139
|
const cwd = process.cwd();
|
|
1091
|
-
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(
|
|
1140
|
+
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(constants_TEMP_DIR);
|
|
1092
1141
|
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1093
1142
|
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1094
1143
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
@@ -1098,14 +1147,14 @@ async function writeSearchIndex(config) {
|
|
|
1098
1147
|
let scanning = false;
|
|
1099
1148
|
for (const searchIndexFile of searchIndexFiles){
|
|
1100
1149
|
if (!searchIndexFile.includes(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
1101
|
-
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1150
|
+
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_TEMP_DIR, searchIndexFile);
|
|
1102
1151
|
const target = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(targetDir, searchIndexFile);
|
|
1103
|
-
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1152
|
+
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_TEMP_DIR, searchIndexFile), 'utf-8');
|
|
1104
1153
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
1105
1154
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1106
1155
|
scanning = true;
|
|
1107
1156
|
}
|
|
1108
|
-
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && (null == config ? void 0 : null
|
|
1157
|
+
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && (null == config ? void 0 : null == (_config_search = config.search) ? void 0 : _config_search.mode) === 'remote') {
|
|
1109
1158
|
const { apiUrl, indexName } = config.search;
|
|
1110
1159
|
try {
|
|
1111
1160
|
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
@@ -1125,7 +1174,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1125
1174
|
return (req, res, next)=>{
|
|
1126
1175
|
var _req_url;
|
|
1127
1176
|
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1128
|
-
if (null
|
|
1177
|
+
if (null == (_req_url = req.url) ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
|
|
1129
1178
|
res.setHeader('Content-Type', 'application/json');
|
|
1130
1179
|
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
|
|
1131
1180
|
const searchIndexFile = req.url.split('/').pop();
|
|
@@ -1143,7 +1192,7 @@ async function detectReactVersion() {
|
|
|
1143
1192
|
if (await pathExists(reactPath)) {
|
|
1144
1193
|
var _reactPkg_version;
|
|
1145
1194
|
const reactPkg = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(reactPath, 'package.json'));
|
|
1146
|
-
const version = Number(null
|
|
1195
|
+
const version = Number(null == (_reactPkg_version = reactPkg.version) ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1147
1196
|
return version;
|
|
1148
1197
|
}
|
|
1149
1198
|
return DEFAULT_REACT_VERSION;
|
|
@@ -1232,7 +1281,7 @@ function getSocialIcons(socialLinks = []) {
|
|
|
1232
1281
|
}
|
|
1233
1282
|
function isPluginIncluded(config, pluginName) {
|
|
1234
1283
|
var _config_builderPlugins, _config_builderConfig_plugins, _config_builderConfig;
|
|
1235
|
-
return Boolean((null
|
|
1284
|
+
return Boolean((null == (_config_builderPlugins = config.builderPlugins) ? void 0 : _config_builderPlugins.some((plugin)=>plugin.name === pluginName)) || (null == (_config_builderConfig = config.builderConfig) ? void 0 : null == (_config_builderConfig_plugins = _config_builderConfig.plugins) ? void 0 : _config_builderConfig_plugins.some((plugin)=>plugin && plugin.name === pluginName)));
|
|
1236
1285
|
}
|
|
1237
1286
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
|
|
1238
1287
|
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig, _config_themeConfig1;
|
|
@@ -1243,7 +1292,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1243
1292
|
const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
|
|
1244
1293
|
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1245
1294
|
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1246
|
-
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)((null == config ? void 0 : null
|
|
1295
|
+
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)((null == config ? void 0 : null == (_config_builderConfig = config.builderConfig) ? void 0 : null == (_config_builderConfig_output = _config_builderConfig.output) ? void 0 : _config_builderConfig_output.assetPrefix) ?? base) : '';
|
|
1247
1296
|
const reactVersion = await detectReactVersion();
|
|
1248
1297
|
const normalizeIcon = (icon)=>{
|
|
1249
1298
|
if (!icon) return;
|
|
@@ -1256,23 +1305,23 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1256
1305
|
resolveReactAlias(reactVersion, false),
|
|
1257
1306
|
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1258
1307
|
]);
|
|
1308
|
+
const context = {
|
|
1309
|
+
userDocRoot,
|
|
1310
|
+
config,
|
|
1311
|
+
runtimeTempDir,
|
|
1312
|
+
routeService,
|
|
1313
|
+
pluginDriver
|
|
1314
|
+
};
|
|
1259
1315
|
return {
|
|
1260
1316
|
plugins: [
|
|
1261
1317
|
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.PLUGIN_REACT_NAME) ? [] : [
|
|
1262
1318
|
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
|
1263
1319
|
],
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
],
|
|
1270
|
-
rsbuildPluginDocVM({
|
|
1271
|
-
userDocRoot,
|
|
1272
|
-
config,
|
|
1273
|
-
runtimeTempDir,
|
|
1274
|
-
routeService,
|
|
1275
|
-
pluginDriver
|
|
1320
|
+
rsbuildPluginDocVM(context),
|
|
1321
|
+
pluginVirtualModule({
|
|
1322
|
+
virtualModules: {
|
|
1323
|
+
...i18nVMPlugin(context)
|
|
1324
|
+
}
|
|
1276
1325
|
})
|
|
1277
1326
|
],
|
|
1278
1327
|
server: {
|
|
@@ -1298,7 +1347,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1298
1347
|
favicon: normalizeIcon(null == config ? void 0 : config.icon),
|
|
1299
1348
|
template: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html'),
|
|
1300
1349
|
tags: [
|
|
1301
|
-
(null
|
|
1350
|
+
(null == (_config_themeConfig = config.themeConfig) ? void 0 : _config_themeConfig.darkMode) !== false ? {
|
|
1302
1351
|
tag: "script",
|
|
1303
1352
|
children: inlineThemeScript,
|
|
1304
1353
|
append: false
|
|
@@ -1333,7 +1382,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1333
1382
|
define: {
|
|
1334
1383
|
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1335
1384
|
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1336
|
-
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null
|
|
1385
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null == (_config_themeConfig1 = config.themeConfig) ? void 0 : _config_themeConfig1.socialLinks))
|
|
1337
1386
|
}
|
|
1338
1387
|
},
|
|
1339
1388
|
performance: {
|
|
@@ -1357,7 +1406,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1357
1406
|
const isServer = 'node' === target;
|
|
1358
1407
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1359
1408
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1360
|
-
const checkDeadLinks = ((null == config ? void 0 : null
|
|
1409
|
+
const checkDeadLinks = ((null == config ? void 0 : null == (_config_markdown = config.markdown) ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
|
|
1361
1410
|
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP).resolve.merge({
|
|
1362
1411
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1363
1412
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
@@ -1463,7 +1512,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1463
1512
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1464
1513
|
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
|
|
1465
1514
|
const rsbuild = await createRsbuild({
|
|
1466
|
-
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null
|
|
1515
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null == (_pluginDriver_getPlugins = pluginDriver.getPlugins()) ? void 0 : _pluginDriver_getPlugins.map((plugin)=>plugin.builderConfig ?? {})) || [], (null == config ? void 0 : config.builderConfig) || {}, extraRsbuildConfig || {})
|
|
1467
1516
|
});
|
|
1468
1517
|
rsbuild.addPlugins(builderPlugins);
|
|
1469
1518
|
return rsbuild;
|
|
@@ -1516,15 +1565,12 @@ async function checkLanguageParity(config) {
|
|
|
1516
1565
|
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1517
1566
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1518
1567
|
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1519
|
-
const includedDirs = (null
|
|
1568
|
+
const includedDirs = (null == (_config_languageParity_include = config.languageParity.include) ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
|
|
1520
1569
|
''
|
|
1521
1570
|
];
|
|
1522
1571
|
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1523
|
-
const supportedLanguages = (null
|
|
1524
|
-
if (!supportedLanguages.length)
|
|
1525
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1526
|
-
return;
|
|
1527
|
-
}
|
|
1572
|
+
const supportedLanguages = (null == (_this = config.locales ?? (null == (_config_themeConfig = config.themeConfig) ? void 0 : _config_themeConfig.locales)) ? void 0 : _this.map((locale)=>locale.lang)) || [];
|
|
1573
|
+
if (!supportedLanguages.length) return void __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1528
1574
|
const missingLanguagesFile = [];
|
|
1529
1575
|
try {
|
|
1530
1576
|
for (const includedDir of includedDirs){
|
|
@@ -1567,7 +1613,7 @@ async function dev(options) {
|
|
|
1567
1613
|
await checkLanguageParity(modifiedConfig);
|
|
1568
1614
|
}
|
|
1569
1615
|
}
|
|
1570
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.
|
|
1616
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.11"}');
|
|
1571
1617
|
async function renderFrontmatterHead(route) {
|
|
1572
1618
|
if (!isRouteMeta(route)) return '';
|
|
1573
1619
|
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
@@ -1616,24 +1662,23 @@ function emptyDir(path) {
|
|
|
1616
1662
|
recursive: true
|
|
1617
1663
|
});
|
|
1618
1664
|
}
|
|
1619
|
-
async function renderPages(appDirectory, config, pluginDriver
|
|
1665
|
+
async function renderPages(appDirectory, config, pluginDriver) {
|
|
1620
1666
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1621
1667
|
const startTime = Date.now();
|
|
1622
1668
|
const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
|
|
1623
1669
|
const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
|
|
1670
|
+
let render;
|
|
1624
1671
|
try {
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
|
|
1632
|
-
throw e;
|
|
1633
|
-
}
|
|
1634
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1635
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}, fallback to CSR.`);
|
|
1672
|
+
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1673
|
+
({ render } = ssrExports);
|
|
1674
|
+
} catch (e) {
|
|
1675
|
+
if (e instanceof Error) {
|
|
1676
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}: ${e.message}`);
|
|
1677
|
+
hintSSGFailed();
|
|
1636
1678
|
}
|
|
1679
|
+
throw e;
|
|
1680
|
+
}
|
|
1681
|
+
try {
|
|
1637
1682
|
const routes = init_routeService.getRoutes();
|
|
1638
1683
|
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1639
1684
|
const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
|
|
@@ -1650,17 +1695,14 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
1650
1695
|
routePath: '/404'
|
|
1651
1696
|
});
|
|
1652
1697
|
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1653
|
-
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__.HelmetData({});
|
|
1698
|
+
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
|
|
1654
1699
|
const { routePath } = route;
|
|
1655
1700
|
let appHtml = '';
|
|
1656
1701
|
if (render) try {
|
|
1657
1702
|
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1658
1703
|
} catch (e) {
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
throw e;
|
|
1662
|
-
}
|
|
1663
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error, fallback to CSR.`, e);
|
|
1704
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1705
|
+
throw e;
|
|
1664
1706
|
}
|
|
1665
1707
|
const { helmet } = helmetContext.context;
|
|
1666
1708
|
let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${package_namespaceObject.i8}">`).replace(HEAD_MARKER, [
|
|
@@ -1674,11 +1716,11 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
1674
1716
|
].join(''));
|
|
1675
1717
|
if (helmet.htmlAttributes) {
|
|
1676
1718
|
var _helmet_htmlAttributes;
|
|
1677
|
-
html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null
|
|
1719
|
+
html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null == (_helmet_htmlAttributes = helmet.htmlAttributes) ? void 0 : _helmet_htmlAttributes.toString()}`);
|
|
1678
1720
|
}
|
|
1679
1721
|
if (helmet.bodyAttributes) {
|
|
1680
1722
|
var _helmet_bodyAttributes;
|
|
1681
|
-
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null
|
|
1723
|
+
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null == (_helmet_bodyAttributes = helmet.bodyAttributes) ? void 0 : _helmet_bodyAttributes.toString()}`);
|
|
1682
1724
|
}
|
|
1683
1725
|
const normalizeHtmlFilePath = (path)=>{
|
|
1684
1726
|
const normalizedBase = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/');
|
|
@@ -1696,7 +1738,10 @@ async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
|
1696
1738
|
const totalTime = Date.now() - startTime;
|
|
1697
1739
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1698
1740
|
} catch (e) {
|
|
1699
|
-
if (e instanceof Error)
|
|
1741
|
+
if (e instanceof Error) {
|
|
1742
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.message}`);
|
|
1743
|
+
hintSSGFailed();
|
|
1744
|
+
}
|
|
1700
1745
|
throw e;
|
|
1701
1746
|
}
|
|
1702
1747
|
}
|
|
@@ -1707,9 +1752,10 @@ async function build(options) {
|
|
|
1707
1752
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1708
1753
|
await pluginDriver.beforeBuild();
|
|
1709
1754
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1710
|
-
await emptyDir(
|
|
1755
|
+
await emptyDir(constants_TEMP_DIR);
|
|
1711
1756
|
await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
|
|
1712
|
-
await renderPages(appDirectory, modifiedConfig, pluginDriver
|
|
1757
|
+
if (ssgConfig) await renderPages(appDirectory, modifiedConfig, pluginDriver);
|
|
1758
|
+
else hintSSGFalse();
|
|
1713
1759
|
await pluginDriver.afterBuild();
|
|
1714
1760
|
}
|
|
1715
1761
|
async function serve(options) {
|
|
@@ -1718,8 +1764,8 @@ async function serve(options) {
|
|
|
1718
1764
|
const envPort = process.env.PORT;
|
|
1719
1765
|
const envHost = process.env.HOST;
|
|
1720
1766
|
const { builderConfig } = config;
|
|
1721
|
-
const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null
|
|
1722
|
-
const host = envHost || userHost || (null == builderConfig ? void 0 : null
|
|
1767
|
+
const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null == (_builderConfig_server = builderConfig.server) ? void 0 : _builderConfig_server.port) || 4173);
|
|
1768
|
+
const host = envHost || userHost || (null == builderConfig ? void 0 : null == (_builderConfig_server1 = builderConfig.server) ? void 0 : _builderConfig_server1.host) || 'localhost';
|
|
1723
1769
|
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1724
1770
|
server: {
|
|
1725
1771
|
port,
|
|
@@ -1730,7 +1776,7 @@ async function serve(options) {
|
|
|
1730
1776
|
await pluginDriver.init();
|
|
1731
1777
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1732
1778
|
const builder = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1733
|
-
|
|
1779
|
+
return builder.preview();
|
|
1734
1780
|
}
|
|
1735
1781
|
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1736
1782
|
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|