@rspress/core 2.0.0-alpha.9 → 2.0.0-beta.0

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.js CHANGED
@@ -62,9 +62,9 @@ class PluginDriver {
62
62
  this.clearPlugins();
63
63
  const config = _class_private_field_get(this, _config);
64
64
  const themeConfig = (null == config ? void 0 : config.themeConfig) || {};
65
- const enableLastUpdated = (null == themeConfig ? void 0 : themeConfig.lastUpdated) || (null == themeConfig ? void 0 : null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.some((locale)=>locale.lastUpdated));
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));
66
66
  const mediumZoomConfig = (null == config ? void 0 : config.mediumZoom) ?? true;
67
- const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || (null === (_themeConfig_locales1 = themeConfig.locales) || void 0 === _themeConfig_locales1 ? void 0 : null === (_themeConfig_locales_ = _themeConfig_locales1[0]) || void 0 === _themeConfig_locales_ ? void 0 : _themeConfig_locales_.nav) || (null === (_themeConfig_locales2 = themeConfig.locales) || void 0 === _themeConfig_locales2 ? void 0 : null === (_themeConfig_locales_1 = _themeConfig_locales2[0]) || void 0 === _themeConfig_locales_1 ? void 0 : _themeConfig_locales_1.sidebar);
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);
68
68
  if (enableLastUpdated) {
69
69
  const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
70
70
  this.addPlugin(pluginLastUpdated());
@@ -215,6 +215,8 @@ const pluginVirtualModule = (pluginOptions = {})=>({
215
215
  }
216
216
  }
217
217
  });
218
+ var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.0"}');
219
+ const RSPRESS_VERSION = package_namespaceObject.i8;
218
220
  const isProduction = ()=>'production' === process.env.NODE_ENV;
219
221
  const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
220
222
  const inlineThemeScript = `{
@@ -227,8 +229,10 @@ const inlineThemeScript = `{
227
229
  }`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
228
230
  const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
229
231
  const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
230
- const CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'clientEntry.js');
231
- const SSR_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrEntry.js');
232
+ const TEMPLATE_PATH = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html');
233
+ const CSR_CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
234
+ const SSR_CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
235
+ const SSR_SERVER_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
232
236
  const OUTPUT_DIR = 'doc_build';
233
237
  const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
234
238
  const HEAD_MARKER = '<!--<?- HEAD ?>-->';
@@ -282,6 +286,14 @@ async function hintThemeBreakingChange(customThemeDir) {
282
286
  + export * from 'rspress/theme';
283
287
  `));
284
288
  }
289
+ function hintSSGFailed() {
290
+ __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:
291
+ 1. Fix code to make it SSR-compatible.
292
+ 2. Set \`ssg: false\`, but the SSG feature will be lost.`);
293
+ }
294
+ function hintSSGFalse() {
295
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('`ssg: false` detected, SSG will be disabled.');
296
+ }
285
297
  const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
286
298
  function slash(p) {
287
299
  return p.replace(/\\/g, '/');
@@ -539,7 +551,7 @@ ${routeMeta.map((route, index)=>{
539
551
  RouteService_class_private_field_set(this, _include, routeOptions.include || []);
540
552
  RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
541
553
  RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
542
- 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 ? void 0 : _userConfig_themeConfig.locales) ?? []).map((item)=>item.lang));
554
+ 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));
543
555
  RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
544
556
  RouteService_class_private_field_set(this, _tempDir, tempDir);
545
557
  RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
@@ -572,62 +584,27 @@ async function initRouteService(options) {
572
584
  await init_routeService.init();
573
585
  return init_routeService;
574
586
  }
575
- async function globalStylesVMPlugin(context) {
576
- const { config, pluginDriver } = context;
577
- const globalStylesByPlugins = pluginDriver.globalStyles();
578
- const moduleContent = [
579
- null == config ? void 0 : config.globalStyles,
580
- ...globalStylesByPlugins
581
- ].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
582
- return {
583
- [runtimeModule_RuntimeModuleID.GlobalStyles]: moduleContent
584
- };
585
- }
586
- async function globalUIComponentsVMPlugin(context) {
587
- const { config, pluginDriver } = context;
588
- let index = 0;
589
- const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
590
- const globalComponents = [
591
- ...(null == config ? void 0 : config.globalUIComponents) || [],
592
- ...globalUIComponentsByPlugins
593
- ];
594
- const moduleContent = globalComponents.map((source)=>{
595
- const name = `Comp_${index}`;
596
- if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
597
- const Props_${index++} = ${JSON.stringify(source[1])};\n`;
598
- index++;
599
- return `import ${name} from ${JSON.stringify(source)};\n`;
600
- }).concat(`export default [${Array.from({
601
- length: index
602
- }, (_, i)=>{
603
- if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
604
- return `Comp_${i}`;
605
- }).join(', ')}];`).join('');
606
- return {
607
- [runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
608
- };
609
- }
587
+ var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
588
+ RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
589
+ RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
590
+ RuntimeModuleID["RouteForClient"] = "virtual-routes";
591
+ RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
592
+ RuntimeModuleID["SiteData"] = "virtual-site-data";
593
+ RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
594
+ RuntimeModuleID["I18nText"] = "virtual-i18n-text";
595
+ RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
596
+ RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
597
+ return RuntimeModuleID;
598
+ }({});
610
599
  async function routeVMPlugin(context) {
611
600
  const { routeService, isSSR } = context;
612
601
  if (!isSSR) return {
613
- [runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
614
- [runtimeModule_RuntimeModuleID.RouteForSSR]: ''
602
+ [types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
603
+ [types_RuntimeModuleID.RouteForSSR]: ''
615
604
  };
616
605
  return {
617
- [runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
618
- [runtimeModule_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
619
- };
620
- }
621
- async function searchHookVMPlugin(context) {
622
- const { config } = context;
623
- let content = 'export const onSearch = () => {};';
624
- let extname = '';
625
- if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) {
626
- content = `export * from '${config.search.searchHooks}'`;
627
- extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(config.search.searchHooks);
628
- }
629
- return {
630
- [`${runtimeModule_RuntimeModuleID.SearchHooks}${extname}`]: content
606
+ [types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
607
+ [types_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
631
608
  };
632
609
  }
633
610
  function createHash(str) {
@@ -690,7 +667,7 @@ async function flattenMdxContent(content, basePath, alias) {
690
667
  }
691
668
  const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
692
669
  var _node_data_estree, _node_data;
693
- return (null === (_node_data = node.data) || void 0 === _node_data ? void 0 : null === (_node_data_estree = _node_data.estree) || void 0 === _node_data_estree ? void 0 : _node_data_estree.body) || [];
670
+ return (null == (_node_data = node.data) ? void 0 : null == (_node_data_estree = _node_data.estree) ? void 0 : _node_data_estree.body) || [];
694
671
  }).filter((node)=>'ImportDeclaration' === node.type);
695
672
  for (const importNode of importNodes){
696
673
  const id = importNode.specifiers[0].local.name;
@@ -872,17 +849,17 @@ function getI18nData(docConfig) {
872
849
  return {};
873
850
  }
874
851
  }
875
- function i18nVMPlugin(context) {
852
+ const i18nVMPlugin = (context)=>{
876
853
  const { config } = context;
877
854
  return {
878
- [runtimeModule_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
855
+ [types_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
879
856
  addDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
880
857
  addMissingDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
881
858
  const i18nData = getI18nData(config);
882
859
  return `export default ${JSON.stringify(i18nData, null, 2)}`;
883
860
  }
884
861
  };
885
- }
862
+ };
886
863
  function normalizeThemeConfig(docConfig, pages = []) {
887
864
  const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
888
865
  const { versions = [] } = multiVersion || {};
@@ -898,7 +875,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
898
875
  };
899
876
  const getI18nText = (key = '', currentLang = '')=>{
900
877
  var _i18nTextData_key;
901
- const text = null === (_i18nTextData_key = i18nTextData[key]) || void 0 === _i18nTextData_key ? void 0 : _i18nTextData_key[currentLang];
878
+ const text = null == (_i18nTextData_key = i18nTextData[key]) ? void 0 : _i18nTextData_key[currentLang];
902
879
  return text || key;
903
880
  };
904
881
  const normalizeSidebar = (sidebar, currentLang = '')=>{
@@ -972,7 +949,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
972
949
  };
973
950
  if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
974
951
  var _themeConfig_locales;
975
- const localeInThemeConfig = null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
952
+ const localeInThemeConfig = null == (_themeConfig_locales = themeConfig.locales) ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
976
953
  return {
977
954
  lang: currentLang,
978
955
  label,
@@ -1011,7 +988,7 @@ async function siteDataVMPlugin(context) {
1011
988
  const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
1012
989
  const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
1013
990
  var _page_frontmatter;
1014
- if ((null === (_page_frontmatter = page.frontmatter) || void 0 === _page_frontmatter ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
991
+ if ((null == (_page_frontmatter = page.frontmatter) ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
1015
992
  const version = versioned ? page.version : '';
1016
993
  const lang = page.lang || '';
1017
994
  return `${version}###${lang}`;
@@ -1039,13 +1016,13 @@ async function siteDataVMPlugin(context) {
1039
1016
  themeConfig: normalizeThemeConfig(userConfig, pages),
1040
1017
  base: (null == userConfig ? void 0 : userConfig.base) || '/',
1041
1018
  lang: (null == userConfig ? void 0 : userConfig.lang) || '',
1042
- locales: (null == userConfig ? void 0 : userConfig.locales) || (null === (_userConfig_themeConfig = userConfig.themeConfig) || void 0 === _userConfig_themeConfig ? void 0 : _userConfig_themeConfig.locales) || [],
1019
+ locales: (null == userConfig ? void 0 : userConfig.locales) || (null == (_userConfig_themeConfig = userConfig.themeConfig) ? void 0 : _userConfig_themeConfig.locales) || [],
1043
1020
  logo: (null == userConfig ? void 0 : userConfig.logo) || '',
1044
1021
  logoText: (null == userConfig ? void 0 : userConfig.logoText) || '',
1045
- ssg: Boolean(null == userConfig ? void 0 : userConfig.ssg) ?? true,
1022
+ ssg: Boolean((null == userConfig ? void 0 : userConfig.ssg) ?? true),
1046
1023
  multiVersion: {
1047
- default: (null == userConfig ? void 0 : null === (_userConfig_multiVersion = userConfig.multiVersion) || void 0 === _userConfig_multiVersion ? void 0 : _userConfig_multiVersion.default) || '',
1048
- versions: (null == userConfig ? void 0 : null === (_userConfig_multiVersion1 = userConfig.multiVersion) || void 0 === _userConfig_multiVersion1 ? void 0 : _userConfig_multiVersion1.versions) || []
1024
+ default: (null == userConfig ? void 0 : null == (_userConfig_multiVersion = userConfig.multiVersion) ? void 0 : _userConfig_multiVersion.default) || '',
1025
+ versions: (null == userConfig ? void 0 : null == (_userConfig_multiVersion1 = userConfig.multiVersion) ? void 0 : _userConfig_multiVersion1.versions) || []
1049
1026
  },
1050
1027
  search: tempSearchObj ?? {
1051
1028
  mode: 'local'
@@ -1058,20 +1035,20 @@ async function siteDataVMPlugin(context) {
1058
1035
  };
1059
1036
  }),
1060
1037
  markdown: {
1061
- showLineNumbers: (null == userConfig ? void 0 : null === (_userConfig_markdown = userConfig.markdown) || void 0 === _userConfig_markdown ? void 0 : _userConfig_markdown.showLineNumbers) ?? false,
1062
- defaultWrapCode: (null == userConfig ? void 0 : null === (_userConfig_markdown1 = userConfig.markdown) || void 0 === _userConfig_markdown1 ? void 0 : _userConfig_markdown1.defaultWrapCode) ?? false,
1063
- codeHighlighter: (null == userConfig ? void 0 : null === (_userConfig_markdown2 = userConfig.markdown) || void 0 === _userConfig_markdown2 ? void 0 : _userConfig_markdown2.codeHighlighter) || 'prism'
1038
+ showLineNumbers: (null == userConfig ? void 0 : null == (_userConfig_markdown = userConfig.markdown) ? void 0 : _userConfig_markdown.showLineNumbers) ?? false,
1039
+ defaultWrapCode: (null == userConfig ? void 0 : null == (_userConfig_markdown1 = userConfig.markdown) ? void 0 : _userConfig_markdown1.defaultWrapCode) ?? false,
1040
+ codeHighlighter: (null == userConfig ? void 0 : null == (_userConfig_markdown2 = userConfig.markdown) ? void 0 : _userConfig_markdown2.codeHighlighter) || 'prism'
1064
1041
  }
1065
1042
  };
1066
1043
  const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
1067
- if (Array.isArray(null === (_siteData_pages_ = siteData.pages[0]) || void 0 === _siteData_pages_ ? void 0 : _siteData_pages_.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
1044
+ if (Array.isArray(null == (_siteData_pages_ = siteData.pages[0]) ? void 0 : _siteData_pages_.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
1068
1045
  const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
1069
1046
  const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
1070
1047
  const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
1071
1048
  return {
1072
- [`${runtimeModule_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
1073
- [runtimeModule_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`,
1074
- [runtimeModule_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
1049
+ [`${types_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
1050
+ [types_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`,
1051
+ [types_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
1075
1052
  export const languages = {
1076
1053
  ${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
1077
1054
  "react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
@@ -1081,10 +1058,7 @@ async function siteDataVMPlugin(context) {
1081
1058
  }
1082
1059
  const runtimeModuleFactory = [
1083
1060
  routeVMPlugin,
1084
- siteDataVMPlugin,
1085
- globalUIComponentsVMPlugin,
1086
- globalStylesVMPlugin,
1087
- searchHookVMPlugin
1061
+ siteDataVMPlugin
1088
1062
  ];
1089
1063
  function rsbuildPluginDocVM(factoryContext) {
1090
1064
  const { pluginDriver } = factoryContext;
@@ -1113,18 +1087,49 @@ function rsbuildPluginDocVM(factoryContext) {
1113
1087
  }
1114
1088
  };
1115
1089
  }
1116
- var runtimeModule_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
1117
- RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
1118
- RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
1119
- RuntimeModuleID["RouteForClient"] = "virtual-routes";
1120
- RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
1121
- RuntimeModuleID["SiteData"] = "virtual-site-data";
1122
- RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
1123
- RuntimeModuleID["I18nText"] = "virtual-i18n-text";
1124
- RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
1125
- RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
1126
- return RuntimeModuleID;
1127
- }({});
1090
+ const globalStylesVMPlugin = (context)=>({
1091
+ [types_RuntimeModuleID.GlobalStyles]: ()=>{
1092
+ const { config, pluginDriver } = context;
1093
+ const globalStylesByPlugins = pluginDriver.globalStyles();
1094
+ const moduleContent = [
1095
+ null == config ? void 0 : config.globalStyles,
1096
+ ...globalStylesByPlugins
1097
+ ].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
1098
+ return moduleContent;
1099
+ }
1100
+ });
1101
+ const globalUIComponentsVMPlugin = (context)=>({
1102
+ [types_RuntimeModuleID.GlobalComponents]: ()=>{
1103
+ const { config, pluginDriver } = context;
1104
+ let index = 0;
1105
+ const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
1106
+ const globalComponents = [
1107
+ ...(null == config ? void 0 : config.globalUIComponents) || [],
1108
+ ...globalUIComponentsByPlugins
1109
+ ];
1110
+ const moduleContent = globalComponents.map((source)=>{
1111
+ const name = `Comp_${index}`;
1112
+ if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
1113
+ const Props_${index++} = ${JSON.stringify(source[1])};\n`;
1114
+ index++;
1115
+ return `import ${name} from ${JSON.stringify(source)};\n`;
1116
+ }).concat(`export default [${Array.from({
1117
+ length: index
1118
+ }, (_, i)=>{
1119
+ if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
1120
+ return `Comp_${i}`;
1121
+ }).join(', ')}];`).join('');
1122
+ return moduleContent;
1123
+ }
1124
+ });
1125
+ const searchHookVMPlugin = (context)=>({
1126
+ [`${types_RuntimeModuleID.SearchHooks}`]: ()=>{
1127
+ const { config } = context;
1128
+ let content = 'export const onSearch = () => {};';
1129
+ if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) content = `export * from '${config.search.searchHooks}'`;
1130
+ return content;
1131
+ }
1132
+ });
1128
1133
  async function writeSearchIndex(config) {
1129
1134
  var _config_search;
1130
1135
  if ((null == config ? void 0 : config.search) === false) return;
@@ -1146,7 +1151,7 @@ async function writeSearchIndex(config) {
1146
1151
  await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
1147
1152
  scanning = true;
1148
1153
  }
1149
- if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && (null == config ? void 0 : null === (_config_search = config.search) || void 0 === _config_search ? void 0 : _config_search.mode) === 'remote') {
1154
+ 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') {
1150
1155
  const { apiUrl, indexName } = config.search;
1151
1156
  try {
1152
1157
  await fetch(`${apiUrl}?index=${indexName}`, {
@@ -1166,7 +1171,7 @@ function serveSearchIndexMiddleware(config) {
1166
1171
  return (req, res, next)=>{
1167
1172
  var _req_url;
1168
1173
  const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
1169
- if (null === (_req_url = req.url) || void 0 === _req_url ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
1174
+ if (null == (_req_url = req.url) ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
1170
1175
  res.setHeader('Content-Type', 'application/json');
1171
1176
  const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
1172
1177
  const searchIndexFile = req.url.split('/').pop();
@@ -1176,6 +1181,170 @@ function serveSearchIndexMiddleware(config) {
1176
1181
  } else null == next || next();
1177
1182
  };
1178
1183
  }
1184
+ async function renderFrontmatterHead(route) {
1185
+ if (!isRouteMeta(route)) return '';
1186
+ const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
1187
+ encoding: 'utf-8'
1188
+ });
1189
+ const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
1190
+ if (!head || 0 === head.length) return '';
1191
+ return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
1192
+ }
1193
+ async function renderConfigHead(config, route) {
1194
+ if (!isRouteMeta(route)) return '';
1195
+ if (!config.head || 0 === config.head.length) return '';
1196
+ return config.head.map((head)=>{
1197
+ if ('string' == typeof head) return head;
1198
+ if ('function' == typeof head) {
1199
+ const resultHead = head(route);
1200
+ if (!resultHead) return '';
1201
+ if ('string' == typeof resultHead) return resultHead;
1202
+ return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
1203
+ }
1204
+ return `<${head[0]} ${renderAttrs(head[1])}>`;
1205
+ }).join('');
1206
+ }
1207
+ function renderAttrs(attrs) {
1208
+ return Object.entries(attrs).map(([key, value])=>{
1209
+ if ('boolean' == typeof value) return key;
1210
+ if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
1211
+ throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
1212
+ }).join('');
1213
+ }
1214
+ function isRouteMeta(route) {
1215
+ return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
1216
+ }
1217
+ async function renderPages(routeService, config, pluginDriver, ssrBundlePath, htmlTemplate, emitAsset) {
1218
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
1219
+ const startTime = Date.now();
1220
+ let render;
1221
+ try {
1222
+ const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
1223
+ ({ render } = ssrExports);
1224
+ } catch (e) {
1225
+ if (e instanceof Error) {
1226
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}: ${e.message}`);
1227
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
1228
+ hintSSGFailed();
1229
+ }
1230
+ throw e;
1231
+ }
1232
+ try {
1233
+ const routes = routeService.getRoutes();
1234
+ const base = (null == config ? void 0 : config.base) ?? '';
1235
+ const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
1236
+ routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
1237
+ }));
1238
+ const allRoutes = [
1239
+ ...routes,
1240
+ ...additionalRoutes
1241
+ ];
1242
+ const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
1243
+ if (!is404RouteInRoutes) allRoutes.push({
1244
+ routePath: '/404'
1245
+ });
1246
+ await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
1247
+ const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
1248
+ const { routePath } = route;
1249
+ let appHtml = '';
1250
+ if (render) try {
1251
+ ({ appHtml } = await render(routePath, helmetContext.context));
1252
+ } catch (e) {
1253
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
1254
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
1255
+ throw e;
1256
+ }
1257
+ const { helmet } = helmetContext.context;
1258
+ let html = htmlTemplate.replace(/<title>(.*?)<\/title>/gi, '').replace(APP_HTML_MARKER, ()=>appHtml).replace(META_GENERATOR, ()=>`<meta name="generator" content="Rspress v${RSPRESS_VERSION}">`).replace(HEAD_MARKER, [
1259
+ await renderConfigHead(config, route),
1260
+ helmet.title.toString(),
1261
+ helmet.meta.toString(),
1262
+ helmet.link.toString(),
1263
+ helmet.style.toString(),
1264
+ helmet.script.toString(),
1265
+ await renderFrontmatterHead(route)
1266
+ ].join(''));
1267
+ if (helmet.htmlAttributes) {
1268
+ var _helmet_htmlAttributes;
1269
+ html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null == (_helmet_htmlAttributes = helmet.htmlAttributes) ? void 0 : _helmet_htmlAttributes.toString()}`);
1270
+ }
1271
+ if (helmet.bodyAttributes) {
1272
+ var _helmet_bodyAttributes;
1273
+ html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null == (_helmet_bodyAttributes = helmet.bodyAttributes) ? void 0 : _helmet_bodyAttributes.toString()}`);
1274
+ }
1275
+ const normalizeHtmlFilePath = (path)=>{
1276
+ const normalizedBase = `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/')}/`;
1277
+ if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
1278
+ return `${path}.html`.replace(normalizedBase, '');
1279
+ };
1280
+ const fileName = normalizeHtmlFilePath(routePath);
1281
+ emitAsset(fileName, html);
1282
+ }));
1283
+ const totalTime = Date.now() - startTime;
1284
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
1285
+ } catch (e) {
1286
+ if (e instanceof Error) {
1287
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.message}`);
1288
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
1289
+ hintSSGFailed();
1290
+ }
1291
+ throw e;
1292
+ }
1293
+ }
1294
+ const NODE_SSR_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
1295
+ const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
1296
+ name: 'rspress-inner-rsbuild-plugin-ssg',
1297
+ async setup (api) {
1298
+ api.onBeforeBuild(()=>{
1299
+ let htmlTemplate = '';
1300
+ const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
1301
+ api.processAssets({
1302
+ stage: 'report',
1303
+ targets: [
1304
+ 'web'
1305
+ ]
1306
+ }, ({ assets, compilation })=>{
1307
+ for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
1308
+ htmlTemplate = assetSource.source().toString();
1309
+ compilation.deleteAsset(assetName);
1310
+ resolve();
1311
+ break;
1312
+ }
1313
+ reject();
1314
+ });
1315
+ }).catch(()=>{
1316
+ const message = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
1317
+ __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(message);
1318
+ const error = new Error(message);
1319
+ throw error;
1320
+ });
1321
+ api.processAssets({
1322
+ stage: 'optimize-transfer',
1323
+ targets: [
1324
+ 'node'
1325
+ ]
1326
+ }, async ({ assets, compilation, environment, compiler })=>{
1327
+ const distPath = environment.distPath;
1328
+ await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(distPath, {
1329
+ recursive: true
1330
+ });
1331
+ let mainCjsAbsolutePath = '';
1332
+ for (const [assetName, assetSource] of Object.entries(assets))if (assetName.includes(NODE_SSR_BUNDLE_NAME)) {
1333
+ mainCjsAbsolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, assetName);
1334
+ await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.writeFile)(mainCjsAbsolutePath, assetSource.source().toString());
1335
+ compilation.deleteAsset(assetName);
1336
+ break;
1337
+ }
1338
+ const emitAsset = (assetName, content)=>{
1339
+ compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
1340
+ };
1341
+ await indexHtmlEmittedInWeb;
1342
+ await renderPages(routeService, config, pluginDriver, mainCjsAbsolutePath, htmlTemplate, emitAsset);
1343
+ if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.rm)(mainCjsAbsolutePath);
1344
+ });
1345
+ });
1346
+ }
1347
+ });
1179
1348
  const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
1180
1349
  const DEFAULT_REACT_VERSION = 18;
1181
1350
  async function detectReactVersion() {
@@ -1184,7 +1353,7 @@ async function detectReactVersion() {
1184
1353
  if (await pathExists(reactPath)) {
1185
1354
  var _reactPkg_version;
1186
1355
  const reactPkg = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(reactPath, 'package.json'));
1187
- const version = Number(null === (_reactPkg_version = reactPkg.version) || void 0 === _reactPkg_version ? void 0 : _reactPkg_version.split('.')[0]);
1356
+ const version = Number(null == (_reactPkg_version = reactPkg.version) ? void 0 : _reactPkg_version.split('.')[0]);
1188
1357
  return version;
1189
1358
  }
1190
1359
  return DEFAULT_REACT_VERSION;
@@ -1273,18 +1442,16 @@ function getSocialIcons(socialLinks = []) {
1273
1442
  }
1274
1443
  function isPluginIncluded(config, pluginName) {
1275
1444
  var _config_builderPlugins, _config_builderConfig_plugins, _config_builderConfig;
1276
- return Boolean((null === (_config_builderPlugins = config.builderPlugins) || void 0 === _config_builderPlugins ? void 0 : _config_builderPlugins.some((plugin)=>plugin.name === pluginName)) || (null === (_config_builderConfig = config.builderConfig) || void 0 === _config_builderConfig ? void 0 : null === (_config_builderConfig_plugins = _config_builderConfig.plugins) || void 0 === _config_builderConfig_plugins ? void 0 : _config_builderConfig_plugins.some((plugin)=>plugin && plugin.name === pluginName)));
1445
+ 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)));
1277
1446
  }
1278
1447
  async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
1279
1448
  var _config_builderConfig_output, _config_builderConfig, _config_themeConfig, _config_themeConfig1;
1280
1449
  const cwd = process.cwd();
1281
1450
  const CUSTOM_THEME_DIR = (null == config ? void 0 : config.themeDir) ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
1282
- const baseOutDir = (null == config ? void 0 : config.outDir) ?? OUTPUT_DIR;
1283
- const csrOutDir = baseOutDir;
1284
- const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
1451
+ const outDir = (null == config ? void 0 : config.outDir) ?? OUTPUT_DIR;
1285
1452
  const DEFAULT_THEME = require.resolve('@rspress/theme-default');
1286
1453
  const base = (null == config ? void 0 : config.base) ?? '';
1287
- const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)((null == config ? void 0 : null === (_config_builderConfig = config.builderConfig) || void 0 === _config_builderConfig ? void 0 : null === (_config_builderConfig_output = _config_builderConfig.output) || void 0 === _config_builderConfig_output ? void 0 : _config_builderConfig_output.assetPrefix) ?? base) : '';
1454
+ 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) : '';
1288
1455
  const reactVersion = await detectReactVersion();
1289
1456
  const normalizeIcon = (icon)=>{
1290
1457
  if (!icon) return;
@@ -1312,9 +1479,19 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1312
1479
  rsbuildPluginDocVM(context),
1313
1480
  pluginVirtualModule({
1314
1481
  virtualModules: {
1315
- ...i18nVMPlugin(context)
1482
+ ...i18nVMPlugin(context),
1483
+ ...globalUIComponentsVMPlugin(context),
1484
+ ...globalStylesVMPlugin(context),
1485
+ ...searchHookVMPlugin(context)
1316
1486
  }
1317
- })
1487
+ }),
1488
+ ...enableSSG ? [
1489
+ rsbuildPluginSSG({
1490
+ routeService,
1491
+ config,
1492
+ pluginDriver
1493
+ })
1494
+ ] : []
1318
1495
  ],
1319
1496
  server: {
1320
1497
  port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
@@ -1337,9 +1514,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1337
1514
  html: {
1338
1515
  title: (null == config ? void 0 : config.title) ?? DEFAULT_TITLE,
1339
1516
  favicon: normalizeIcon(null == config ? void 0 : config.icon),
1340
- template: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html'),
1517
+ template: TEMPLATE_PATH,
1341
1518
  tags: [
1342
- (null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : _config_themeConfig.darkMode) !== false ? {
1519
+ (null == (_config_themeConfig = config.themeConfig) ? void 0 : _config_themeConfig.darkMode) !== false ? {
1343
1520
  tag: "script",
1344
1521
  children: inlineThemeScript,
1345
1522
  append: false
@@ -1349,7 +1526,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1349
1526
  output: {
1350
1527
  assetPrefix,
1351
1528
  distPath: {
1352
- root: csrOutDir
1529
+ root: outDir
1353
1530
  }
1354
1531
  },
1355
1532
  resolve: {
@@ -1374,7 +1551,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1374
1551
  define: {
1375
1552
  'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
1376
1553
  'process.env.TEST': JSON.stringify(process.env.TEST),
1377
- 'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null === (_config_themeConfig1 = config.themeConfig) || void 0 === _config_themeConfig1 ? void 0 : _config_themeConfig1.socialLinks))
1554
+ 'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null == (_config_themeConfig1 = config.themeConfig) ? void 0 : _config_themeConfig1.socialLinks))
1378
1555
  }
1379
1556
  },
1380
1557
  performance: {
@@ -1398,7 +1575,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1398
1575
  const isServer = 'node' === target;
1399
1576
  const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
1400
1577
  const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
1401
- const checkDeadLinks = ((null == config ? void 0 : null === (_config_markdown = config.markdown) || void 0 === _config_markdown ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
1578
+ const checkDeadLinks = ((null == config ? void 0 : null == (_config_markdown = config.markdown) ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
1402
1579
  chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP).resolve.merge({
1403
1580
  conditionNames: jsModuleRule.resolve.conditionNames.values(),
1404
1581
  mainFields: jsModuleRule.resolve.mainFields.values()
@@ -1421,7 +1598,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1421
1598
  chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
1422
1599
  sideEffects: true
1423
1600
  });
1424
- if (isServer) chain.output.filename('main.cjs');
1601
+ if (isServer) chain.output.filename(NODE_SSR_BUNDLE_NAME);
1425
1602
  const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
1426
1603
  if (enableIncremental) chain.merge({
1427
1604
  experiments: {
@@ -1440,7 +1617,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1440
1617
  },
1441
1618
  source: {
1442
1619
  entry: {
1443
- index: CLIENT_ENTRY
1620
+ index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
1444
1621
  },
1445
1622
  define: {
1446
1623
  'process.env.__SSR__': JSON.stringify(false)
@@ -1449,7 +1626,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1449
1626
  output: {
1450
1627
  target: 'web',
1451
1628
  distPath: {
1452
- root: csrOutDir
1629
+ root: outDir
1453
1630
  }
1454
1631
  }
1455
1632
  },
@@ -1461,23 +1638,29 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
1461
1638
  __VIRTUAL_ROUTES__: 'virtual-routes-ssr'
1462
1639
  }
1463
1640
  },
1641
+ tools: {
1642
+ rspack: {
1643
+ output: {
1644
+ asyncChunks: false
1645
+ }
1646
+ }
1647
+ },
1464
1648
  source: {
1465
1649
  entry: {
1466
- index: SSR_ENTRY
1650
+ index: SSR_SERVER_ENTRY
1467
1651
  },
1468
1652
  define: {
1469
1653
  'process.env.__SSR__': JSON.stringify(true)
1470
1654
  }
1471
1655
  },
1472
1656
  performance: {
1473
- printFileSize: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()
1657
+ printFileSize: {
1658
+ compressed: true
1659
+ }
1474
1660
  },
1475
1661
  output: {
1476
1662
  emitAssets: false,
1477
1663
  target: 'node',
1478
- distPath: {
1479
- root: ssrOutDir
1480
- },
1481
1664
  minify: false
1482
1665
  }
1483
1666
  }
@@ -1504,7 +1687,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
1504
1687
  const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
1505
1688
  const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
1506
1689
  const rsbuild = await createRsbuild({
1507
- rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null === (_pluginDriver_getPlugins = pluginDriver.getPlugins()) || void 0 === _pluginDriver_getPlugins ? void 0 : _pluginDriver_getPlugins.map((plugin)=>plugin.builderConfig ?? {})) || [], (null == config ? void 0 : config.builderConfig) || {}, extraRsbuildConfig || {})
1690
+ rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null == (_pluginDriver_getPlugins = pluginDriver.getPlugins()) ? void 0 : _pluginDriver_getPlugins.map((plugin)=>plugin.builderConfig ?? {})) || [], (null == config ? void 0 : config.builderConfig) || {}, extraRsbuildConfig || {})
1508
1691
  });
1509
1692
  rsbuild.addPlugins(builderPlugins);
1510
1693
  return rsbuild;
@@ -1557,15 +1740,12 @@ async function checkLanguageParity(config) {
1557
1740
  if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
1558
1741
  __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
1559
1742
  const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
1560
- const includedDirs = (null === (_config_languageParity_include = config.languageParity.include) || void 0 === _config_languageParity_include ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
1743
+ const includedDirs = (null == (_config_languageParity_include = config.languageParity.include) ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
1561
1744
  ''
1562
1745
  ];
1563
1746
  const excludedDirs = config.languageParity.exclude ?? [];
1564
- const supportedLanguages = (null === (_this = config.locales ?? (null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : _config_themeConfig.locales)) || void 0 === _this ? void 0 : _this.map((locale)=>locale.lang)) || [];
1565
- if (!supportedLanguages.length) {
1566
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
1567
- return;
1568
- }
1747
+ const supportedLanguages = (null == (_this = config.locales ?? (null == (_config_themeConfig = config.themeConfig) ? void 0 : _config_themeConfig.locales)) ? void 0 : _this.map((locale)=>locale.lang)) || [];
1748
+ if (!supportedLanguages.length) return void __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
1569
1749
  const missingLanguagesFile = [];
1570
1750
  try {
1571
1751
  for (const includedDir of includedDirs){
@@ -1595,11 +1775,11 @@ async function dev(options) {
1595
1775
  const modifiedConfig = await pluginDriver.modifyConfig();
1596
1776
  try {
1597
1777
  await pluginDriver.beforeBuild();
1598
- const builder = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
1599
- builder.onDevCompileDone(async ()=>{
1778
+ const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
1779
+ rsbuild.onDevCompileDone(async ()=>{
1600
1780
  await pluginDriver.afterBuild();
1601
1781
  });
1602
- const { server } = await builder.startDevServer({
1782
+ const { server } = await rsbuild.startDevServer({
1603
1783
  getPortSilently: true
1604
1784
  });
1605
1785
  return server;
@@ -1608,43 +1788,6 @@ async function dev(options) {
1608
1788
  await checkLanguageParity(modifiedConfig);
1609
1789
  }
1610
1790
  }
1611
- var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.9"}');
1612
- async function renderFrontmatterHead(route) {
1613
- if (!isRouteMeta(route)) return '';
1614
- const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
1615
- encoding: 'utf-8'
1616
- });
1617
- const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
1618
- if (!head || 0 === head.length) return '';
1619
- return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
1620
- }
1621
- async function renderConfigHead(config, route) {
1622
- if (!isRouteMeta(route)) return '';
1623
- if (!config.head || 0 === config.head.length) return '';
1624
- return config.head.map((head)=>{
1625
- if ('string' == typeof head) return head;
1626
- if ('function' == typeof head) {
1627
- const resultHead = head(route);
1628
- if (!resultHead) return '';
1629
- if ('string' == typeof resultHead) return resultHead;
1630
- return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
1631
- }
1632
- return `<${head[0]} ${renderAttrs(head[1])}>`;
1633
- }).join('');
1634
- }
1635
- function renderAttrs(attrs) {
1636
- return Object.entries(attrs).map(([key, value])=>{
1637
- if ('boolean' == typeof value) return key;
1638
- if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
1639
- throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
1640
- }).join('');
1641
- }
1642
- function isRouteMeta(route) {
1643
- return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
1644
- }
1645
- function isCSRFallback(ssgConfig) {
1646
- return 'object' == typeof ssgConfig && 'csr' === ssgConfig.fallback;
1647
- }
1648
1791
  async function bundle(docDirectory, config, pluginDriver, enableSSG) {
1649
1792
  try {
1650
1793
  const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
@@ -1660,101 +1803,16 @@ function emptyDir(path) {
1660
1803
  recursive: true
1661
1804
  });
1662
1805
  }
1663
- async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
1664
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
1665
- const startTime = Date.now();
1666
- const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
1667
- const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
1668
- try {
1669
- let render;
1670
- if (ssgConfig) try {
1671
- const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
1672
- ({ render } = ssrExports);
1673
- } catch (e) {
1674
- if (isCSRFallback(ssgConfig)) {
1675
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
1676
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}, fallback to CSR.`);
1677
- } else {
1678
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
1679
- throw e;
1680
- }
1681
- }
1682
- const routes = init_routeService.getRoutes();
1683
- const base = (null == config ? void 0 : config.base) ?? '';
1684
- const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
1685
- const htmlTemplate = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(htmlTemplatePath, 'utf-8');
1686
- const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
1687
- routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
1688
- }));
1689
- const allRoutes = [
1690
- ...routes,
1691
- ...additionalRoutes
1692
- ];
1693
- const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
1694
- if (!is404RouteInRoutes) allRoutes.push({
1695
- routePath: '/404'
1696
- });
1697
- await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
1698
- const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
1699
- const { routePath } = route;
1700
- let appHtml = '';
1701
- if (render) try {
1702
- ({ appHtml } = await render(routePath, helmetContext.context));
1703
- } catch (e) {
1704
- if (isCSRFallback(ssgConfig)) __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering error, fallback to CSR.`, e);
1705
- else {
1706
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
1707
- throw e;
1708
- }
1709
- }
1710
- const { helmet } = helmetContext.context;
1711
- 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, [
1712
- await renderConfigHead(config, route),
1713
- helmet.title.toString(),
1714
- helmet.meta.toString(),
1715
- helmet.link.toString(),
1716
- helmet.style.toString(),
1717
- helmet.script.toString(),
1718
- await renderFrontmatterHead(route)
1719
- ].join(''));
1720
- if (helmet.htmlAttributes) {
1721
- var _helmet_htmlAttributes;
1722
- html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null === (_helmet_htmlAttributes = helmet.htmlAttributes) || void 0 === _helmet_htmlAttributes ? void 0 : _helmet_htmlAttributes.toString()}`);
1723
- }
1724
- if (helmet.bodyAttributes) {
1725
- var _helmet_bodyAttributes;
1726
- html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null === (_helmet_bodyAttributes = helmet.bodyAttributes) || void 0 === _helmet_bodyAttributes ? void 0 : _helmet_bodyAttributes.toString()}`);
1727
- }
1728
- const normalizeHtmlFilePath = (path)=>{
1729
- const normalizedBase = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/');
1730
- if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
1731
- return `${path}.html`.replace(normalizedBase, '');
1732
- };
1733
- const fileName = normalizeHtmlFilePath(routePath);
1734
- await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(fileName)), {
1735
- recursive: true
1736
- });
1737
- await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, fileName), html);
1738
- }));
1739
- if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr'));
1740
- await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'html'));
1741
- const totalTime = Date.now() - startTime;
1742
- __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
1743
- } catch (e) {
1744
- if (e instanceof Error) __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.stack}`);
1745
- throw e;
1746
- }
1747
- }
1748
1806
  async function build(options) {
1749
- const { docDirectory, appDirectory, config } = options;
1807
+ const { docDirectory, config } = options;
1750
1808
  const pluginDriver = new PluginDriver(config, true);
1751
1809
  await pluginDriver.init();
1752
1810
  const modifiedConfig = await pluginDriver.modifyConfig();
1753
1811
  await pluginDriver.beforeBuild();
1754
1812
  const ssgConfig = modifiedConfig.ssg ?? true;
1755
1813
  await emptyDir(constants_TEMP_DIR);
1756
- await bundle(docDirectory, modifiedConfig, pluginDriver, Boolean(ssgConfig));
1757
- await renderPages(appDirectory, modifiedConfig, pluginDriver, ssgConfig);
1814
+ await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
1815
+ if (!ssgConfig) hintSSGFalse();
1758
1816
  await pluginDriver.afterBuild();
1759
1817
  }
1760
1818
  async function serve(options) {
@@ -1763,8 +1821,8 @@ async function serve(options) {
1763
1821
  const envPort = process.env.PORT;
1764
1822
  const envHost = process.env.HOST;
1765
1823
  const { builderConfig } = config;
1766
- const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null === (_builderConfig_server = builderConfig.server) || void 0 === _builderConfig_server ? void 0 : _builderConfig_server.port) || 4173);
1767
- const host = envHost || userHost || (null == builderConfig ? void 0 : null === (_builderConfig_server1 = builderConfig.server) || void 0 === _builderConfig_server1 ? void 0 : _builderConfig_server1.host) || 'localhost';
1824
+ const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null == (_builderConfig_server = builderConfig.server) ? void 0 : _builderConfig_server.port) || 4173);
1825
+ const host = envHost || userHost || (null == builderConfig ? void 0 : null == (_builderConfig_server1 = builderConfig.server) ? void 0 : _builderConfig_server1.host) || 'localhost';
1768
1826
  config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
1769
1827
  server: {
1770
1828
  port,
@@ -1774,8 +1832,8 @@ async function serve(options) {
1774
1832
  const pluginDriver = new PluginDriver(config, true);
1775
1833
  await pluginDriver.init();
1776
1834
  const modifiedConfig = await pluginDriver.modifyConfig();
1777
- const builder = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
1778
- return builder.preview();
1835
+ const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
1836
+ return rsbuild.preview();
1779
1837
  }
1780
1838
  var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
1781
1839
  export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };