@rspress/core 2.0.0-alpha.8 → 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.d.ts +1 -2
- package/dist/index.js +379 -281
- package/dist/loader.js +20 -19
- package/dist/runtime/App.d.ts +0 -6
- package/dist/runtime/App.js +8 -67
- package/dist/runtime/ClientApp.d.ts +4 -0
- package/dist/runtime/ClientApp.js +31 -0
- package/dist/runtime/csrClientEntry.d.ts +1 -0
- package/dist/runtime/csrClientEntry.js +13 -0
- package/dist/runtime/initPageData.d.ts +3 -0
- package/dist/runtime/initPageData.js +59 -0
- package/dist/runtime/ssrClientEntry.d.ts +1 -0
- package/dist/runtime/ssrClientEntry.js +19 -0
- package/dist/runtime/{ssrEntry.js → ssrServerEntry.js} +2 -1
- package/dist/runtime/tsconfig.js +3 -3
- package/package.json +33 -32
- package/dist/runtime/clientEntry.d.ts +0 -1
- package/dist/runtime/clientEntry.js +0 -71
- /package/dist/runtime/{ssrEntry.d.ts → ssrServerEntry.d.ts} +0 -0
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
|
|
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
|
|
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());
|
|
@@ -184,6 +184,39 @@ class PluginDriver {
|
|
|
184
184
|
_class_private_field_set(this, _plugins, []);
|
|
185
185
|
}
|
|
186
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
|
+
});
|
|
218
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.0"}');
|
|
219
|
+
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
187
220
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
188
221
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
189
222
|
const inlineThemeScript = `{
|
|
@@ -196,8 +229,10 @@ const inlineThemeScript = `{
|
|
|
196
229
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
197
230
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
198
231
|
const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
|
|
199
|
-
const
|
|
200
|
-
const
|
|
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');
|
|
201
236
|
const OUTPUT_DIR = 'doc_build';
|
|
202
237
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
203
238
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
@@ -206,7 +241,7 @@ const HTML_START_TAG = '<html';
|
|
|
206
241
|
const BODY_START_TAG = '<body';
|
|
207
242
|
const DEFAULT_TITLE = 'Rspress';
|
|
208
243
|
const PUBLIC_DIR = 'public';
|
|
209
|
-
const
|
|
244
|
+
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);
|
|
210
245
|
async function pathExists(path) {
|
|
211
246
|
try {
|
|
212
247
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].access(path);
|
|
@@ -251,6 +286,14 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
251
286
|
+ export * from 'rspress/theme';
|
|
252
287
|
`));
|
|
253
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
|
+
}
|
|
254
297
|
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
255
298
|
function slash(p) {
|
|
256
299
|
return p.replace(/\\/g, '/');
|
|
@@ -508,7 +551,7 @@ ${routeMeta.map((route, index)=>{
|
|
|
508
551
|
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
509
552
|
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
510
553
|
RouteService_class_private_field_set(this, _defaultLang, (null == userConfig ? void 0 : userConfig.lang) || '');
|
|
511
|
-
RouteService_class_private_field_set(this, _langs, ((null == userConfig ? void 0 : userConfig.locales) ?? (null == userConfig ? void 0 : null
|
|
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));
|
|
512
555
|
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
513
556
|
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
514
557
|
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
@@ -541,81 +584,27 @@ async function initRouteService(options) {
|
|
|
541
584
|
await init_routeService.init();
|
|
542
585
|
return init_routeService;
|
|
543
586
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
]
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
const { config, pluginDriver } = context;
|
|
557
|
-
let index = 0;
|
|
558
|
-
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
559
|
-
const globalComponents = [
|
|
560
|
-
...(null == config ? void 0 : config.globalUIComponents) || [],
|
|
561
|
-
...globalUIComponentsByPlugins
|
|
562
|
-
];
|
|
563
|
-
const moduleContent = globalComponents.map((source)=>{
|
|
564
|
-
const name = `Comp_${index}`;
|
|
565
|
-
if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
|
|
566
|
-
const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
567
|
-
index++;
|
|
568
|
-
return `import ${name} from ${JSON.stringify(source)};\n`;
|
|
569
|
-
}).concat(`export default [${Array.from({
|
|
570
|
-
length: index
|
|
571
|
-
}, (_, i)=>{
|
|
572
|
-
if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
|
|
573
|
-
return `Comp_${i}`;
|
|
574
|
-
}).join(', ')}];`).join('');
|
|
575
|
-
return {
|
|
576
|
-
[runtimeModule_RuntimeModuleID.GlobalComponents]: moduleContent
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
580
|
-
function getI18nData(docConfig) {
|
|
581
|
-
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
582
|
-
try {
|
|
583
|
-
delete require.cache[i18nSourcePath];
|
|
584
|
-
const i18nSource = require(i18nSourcePath);
|
|
585
|
-
return i18nSource;
|
|
586
|
-
} catch (e) {
|
|
587
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
588
|
-
return {};
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
function i18nVMPlugin(context) {
|
|
592
|
-
const { config } = context;
|
|
593
|
-
const i18nData = getI18nData(config);
|
|
594
|
-
return {
|
|
595
|
-
[runtimeModule_RuntimeModuleID.I18nText]: `export default ${JSON.stringify(i18nData, null, 2)}`
|
|
596
|
-
};
|
|
597
|
-
}
|
|
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
|
+
}({});
|
|
598
599
|
async function routeVMPlugin(context) {
|
|
599
600
|
const { routeService, isSSR } = context;
|
|
600
601
|
if (!isSSR) return {
|
|
601
|
-
[
|
|
602
|
-
[
|
|
603
|
-
};
|
|
604
|
-
return {
|
|
605
|
-
[runtimeModule_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
606
|
-
[runtimeModule_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
602
|
+
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
603
|
+
[types_RuntimeModuleID.RouteForSSR]: ''
|
|
607
604
|
};
|
|
608
|
-
}
|
|
609
|
-
async function searchHookVMPlugin(context) {
|
|
610
|
-
const { config } = context;
|
|
611
|
-
let content = 'export const onSearch = () => {};';
|
|
612
|
-
let extname = '';
|
|
613
|
-
if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) {
|
|
614
|
-
content = `export * from '${config.search.searchHooks}'`;
|
|
615
|
-
extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(config.search.searchHooks);
|
|
616
|
-
}
|
|
617
605
|
return {
|
|
618
|
-
[
|
|
606
|
+
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
607
|
+
[types_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
619
608
|
};
|
|
620
609
|
}
|
|
621
610
|
function createHash(str) {
|
|
@@ -678,7 +667,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
678
667
|
}
|
|
679
668
|
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>{
|
|
680
669
|
var _node_data_estree, _node_data;
|
|
681
|
-
return (null
|
|
670
|
+
return (null == (_node_data = node.data) ? void 0 : null == (_node_data_estree = _node_data.estree) ? void 0 : _node_data_estree.body) || [];
|
|
682
671
|
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
683
672
|
for (const importNode of importNodes){
|
|
684
673
|
const id = importNode.specifiers[0].local.name;
|
|
@@ -848,6 +837,29 @@ function handleHighlightLanguages(highlightLanguages, defaultLanguages) {
|
|
|
848
837
|
}
|
|
849
838
|
return aliases;
|
|
850
839
|
}
|
|
840
|
+
const DEFAULT_I18N_SOURCE = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), 'i18n.json');
|
|
841
|
+
function getI18nData(docConfig) {
|
|
842
|
+
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
|
|
843
|
+
try {
|
|
844
|
+
delete require.cache[i18nSourcePath];
|
|
845
|
+
const i18nSource = require(i18nSourcePath);
|
|
846
|
+
return i18nSource;
|
|
847
|
+
} catch (e) {
|
|
848
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug('getI18nData Failed: \n', e);
|
|
849
|
+
return {};
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
const i18nVMPlugin = (context)=>{
|
|
853
|
+
const { config } = context;
|
|
854
|
+
return {
|
|
855
|
+
[types_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
|
|
856
|
+
addDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
857
|
+
addMissingDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
858
|
+
const i18nData = getI18nData(config);
|
|
859
|
+
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
};
|
|
851
863
|
function normalizeThemeConfig(docConfig, pages = []) {
|
|
852
864
|
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
853
865
|
const { versions = [] } = multiVersion || {};
|
|
@@ -863,7 +875,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
863
875
|
};
|
|
864
876
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
865
877
|
var _i18nTextData_key;
|
|
866
|
-
const text = null
|
|
878
|
+
const text = null == (_i18nTextData_key = i18nTextData[key]) ? void 0 : _i18nTextData_key[currentLang];
|
|
867
879
|
return text || key;
|
|
868
880
|
};
|
|
869
881
|
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
@@ -937,7 +949,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
937
949
|
};
|
|
938
950
|
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
939
951
|
var _themeConfig_locales;
|
|
940
|
-
const localeInThemeConfig = null
|
|
952
|
+
const localeInThemeConfig = null == (_themeConfig_locales = themeConfig.locales) ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
941
953
|
return {
|
|
942
954
|
lang: currentLang,
|
|
943
955
|
label,
|
|
@@ -976,7 +988,7 @@ async function siteDataVMPlugin(context) {
|
|
|
976
988
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
977
989
|
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
978
990
|
var _page_frontmatter;
|
|
979
|
-
if ((null
|
|
991
|
+
if ((null == (_page_frontmatter = page.frontmatter) ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
980
992
|
const version = versioned ? page.version : '';
|
|
981
993
|
const lang = page.lang || '';
|
|
982
994
|
return `${version}###${lang}`;
|
|
@@ -990,10 +1002,10 @@ async function siteDataVMPlugin(context) {
|
|
|
990
1002
|
const [version, lang] = group.split('###');
|
|
991
1003
|
const indexVersion = version ? `.${version.replace('.', '_')}` : '';
|
|
992
1004
|
const indexLang = lang ? `.${lang}` : '';
|
|
993
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(
|
|
1005
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(constants_TEMP_DIR, {
|
|
994
1006
|
recursive: true
|
|
995
1007
|
});
|
|
996
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(
|
|
1008
|
+
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);
|
|
997
1009
|
}));
|
|
998
1010
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
999
1011
|
const siteData = {
|
|
@@ -1004,13 +1016,13 @@ async function siteDataVMPlugin(context) {
|
|
|
1004
1016
|
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
1005
1017
|
base: (null == userConfig ? void 0 : userConfig.base) || '/',
|
|
1006
1018
|
lang: (null == userConfig ? void 0 : userConfig.lang) || '',
|
|
1007
|
-
locales: (null == userConfig ? void 0 : userConfig.locales) || (null
|
|
1019
|
+
locales: (null == userConfig ? void 0 : userConfig.locales) || (null == (_userConfig_themeConfig = userConfig.themeConfig) ? void 0 : _userConfig_themeConfig.locales) || [],
|
|
1008
1020
|
logo: (null == userConfig ? void 0 : userConfig.logo) || '',
|
|
1009
1021
|
logoText: (null == userConfig ? void 0 : userConfig.logoText) || '',
|
|
1010
|
-
ssg: Boolean(null == userConfig ? void 0 : userConfig.ssg) ?? true,
|
|
1022
|
+
ssg: Boolean((null == userConfig ? void 0 : userConfig.ssg) ?? true),
|
|
1011
1023
|
multiVersion: {
|
|
1012
|
-
default: (null == userConfig ? void 0 : null
|
|
1013
|
-
versions: (null == userConfig ? void 0 : null
|
|
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) || []
|
|
1014
1026
|
},
|
|
1015
1027
|
search: tempSearchObj ?? {
|
|
1016
1028
|
mode: 'local'
|
|
@@ -1023,20 +1035,20 @@ async function siteDataVMPlugin(context) {
|
|
|
1023
1035
|
};
|
|
1024
1036
|
}),
|
|
1025
1037
|
markdown: {
|
|
1026
|
-
showLineNumbers: (null == userConfig ? void 0 : null
|
|
1027
|
-
defaultWrapCode: (null == userConfig ? void 0 : null
|
|
1028
|
-
codeHighlighter: (null == userConfig ? void 0 : null
|
|
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'
|
|
1029
1041
|
}
|
|
1030
1042
|
};
|
|
1031
1043
|
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1032
|
-
if (Array.isArray(null
|
|
1044
|
+
if (Array.isArray(null == (_siteData_pages_ = siteData.pages[0]) ? void 0 : _siteData_pages_.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1033
1045
|
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1034
1046
|
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1035
1047
|
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1036
1048
|
return {
|
|
1037
|
-
[`${
|
|
1038
|
-
[
|
|
1039
|
-
[
|
|
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)};
|
|
1040
1052
|
export const languages = {
|
|
1041
1053
|
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1042
1054
|
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
@@ -1046,11 +1058,7 @@ async function siteDataVMPlugin(context) {
|
|
|
1046
1058
|
}
|
|
1047
1059
|
const runtimeModuleFactory = [
|
|
1048
1060
|
routeVMPlugin,
|
|
1049
|
-
siteDataVMPlugin
|
|
1050
|
-
globalUIComponentsVMPlugin,
|
|
1051
|
-
globalStylesVMPlugin,
|
|
1052
|
-
i18nVMPlugin,
|
|
1053
|
-
searchHookVMPlugin
|
|
1061
|
+
siteDataVMPlugin
|
|
1054
1062
|
];
|
|
1055
1063
|
function rsbuildPluginDocVM(factoryContext) {
|
|
1056
1064
|
const { pluginDriver } = factoryContext;
|
|
@@ -1079,23 +1087,54 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1079
1087
|
}
|
|
1080
1088
|
};
|
|
1081
1089
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
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
|
+
});
|
|
1094
1133
|
async function writeSearchIndex(config) {
|
|
1095
1134
|
var _config_search;
|
|
1096
1135
|
if ((null == config ? void 0 : config.search) === false) return;
|
|
1097
1136
|
const cwd = process.cwd();
|
|
1098
|
-
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(
|
|
1137
|
+
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(constants_TEMP_DIR);
|
|
1099
1138
|
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1100
1139
|
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1101
1140
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
@@ -1105,14 +1144,14 @@ async function writeSearchIndex(config) {
|
|
|
1105
1144
|
let scanning = false;
|
|
1106
1145
|
for (const searchIndexFile of searchIndexFiles){
|
|
1107
1146
|
if (!searchIndexFile.includes(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME) || !searchIndexFile.endsWith('.json')) continue;
|
|
1108
|
-
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1147
|
+
const source = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(constants_TEMP_DIR, searchIndexFile);
|
|
1109
1148
|
const target = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(targetDir, searchIndexFile);
|
|
1110
|
-
const searchIndex = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(
|
|
1149
|
+
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');
|
|
1111
1150
|
searchIndexData = `${searchIndexData.slice(0, -1)}${scanning ? ',' : ''}${searchIndex.slice(1)}`;
|
|
1112
1151
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1113
1152
|
scanning = true;
|
|
1114
1153
|
}
|
|
1115
|
-
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && (null == config ? void 0 : null
|
|
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') {
|
|
1116
1155
|
const { apiUrl, indexName } = config.search;
|
|
1117
1156
|
try {
|
|
1118
1157
|
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
@@ -1132,7 +1171,7 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1132
1171
|
return (req, res, next)=>{
|
|
1133
1172
|
var _req_url;
|
|
1134
1173
|
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1135
|
-
if (null
|
|
1174
|
+
if (null == (_req_url = req.url) ? void 0 : _req_url.includes(searchIndexRequestMatch)) {
|
|
1136
1175
|
res.setHeader('Content-Type', 'application/json');
|
|
1137
1176
|
const outDir = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
|
|
1138
1177
|
const searchIndexFile = req.url.split('/').pop();
|
|
@@ -1142,6 +1181,170 @@ function serveSearchIndexMiddleware(config) {
|
|
|
1142
1181
|
} else null == next || next();
|
|
1143
1182
|
};
|
|
1144
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
|
+
});
|
|
1145
1348
|
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1146
1349
|
const DEFAULT_REACT_VERSION = 18;
|
|
1147
1350
|
async function detectReactVersion() {
|
|
@@ -1150,7 +1353,7 @@ async function detectReactVersion() {
|
|
|
1150
1353
|
if (await pathExists(reactPath)) {
|
|
1151
1354
|
var _reactPkg_version;
|
|
1152
1355
|
const reactPkg = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(reactPath, 'package.json'));
|
|
1153
|
-
const version = Number(null
|
|
1356
|
+
const version = Number(null == (_reactPkg_version = reactPkg.version) ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1154
1357
|
return version;
|
|
1155
1358
|
}
|
|
1156
1359
|
return DEFAULT_REACT_VERSION;
|
|
@@ -1239,18 +1442,16 @@ function getSocialIcons(socialLinks = []) {
|
|
|
1239
1442
|
}
|
|
1240
1443
|
function isPluginIncluded(config, pluginName) {
|
|
1241
1444
|
var _config_builderPlugins, _config_builderConfig_plugins, _config_builderConfig;
|
|
1242
|
-
return Boolean((null
|
|
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)));
|
|
1243
1446
|
}
|
|
1244
1447
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
|
|
1245
1448
|
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig, _config_themeConfig1;
|
|
1246
1449
|
const cwd = process.cwd();
|
|
1247
1450
|
const CUSTOM_THEME_DIR = (null == config ? void 0 : config.themeDir) ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
|
|
1248
|
-
const
|
|
1249
|
-
const csrOutDir = baseOutDir;
|
|
1250
|
-
const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
|
|
1451
|
+
const outDir = (null == config ? void 0 : config.outDir) ?? OUTPUT_DIR;
|
|
1251
1452
|
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1252
1453
|
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1253
|
-
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)((null == config ? void 0 : null
|
|
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) : '';
|
|
1254
1455
|
const reactVersion = await detectReactVersion();
|
|
1255
1456
|
const normalizeIcon = (icon)=>{
|
|
1256
1457
|
if (!icon) return;
|
|
@@ -1263,18 +1464,34 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1263
1464
|
resolveReactAlias(reactVersion, false),
|
|
1264
1465
|
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1265
1466
|
]);
|
|
1467
|
+
const context = {
|
|
1468
|
+
userDocRoot,
|
|
1469
|
+
config,
|
|
1470
|
+
runtimeTempDir,
|
|
1471
|
+
routeService,
|
|
1472
|
+
pluginDriver
|
|
1473
|
+
};
|
|
1266
1474
|
return {
|
|
1267
1475
|
plugins: [
|
|
1268
1476
|
...isPluginIncluded(config, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.PLUGIN_REACT_NAME) ? [] : [
|
|
1269
1477
|
(0, __WEBPACK_EXTERNAL_MODULE__rsbuild_plugin_react_7b149ee4__.pluginReact)()
|
|
1270
1478
|
],
|
|
1271
|
-
rsbuildPluginDocVM(
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1479
|
+
rsbuildPluginDocVM(context),
|
|
1480
|
+
pluginVirtualModule({
|
|
1481
|
+
virtualModules: {
|
|
1482
|
+
...i18nVMPlugin(context),
|
|
1483
|
+
...globalUIComponentsVMPlugin(context),
|
|
1484
|
+
...globalStylesVMPlugin(context),
|
|
1485
|
+
...searchHookVMPlugin(context)
|
|
1486
|
+
}
|
|
1487
|
+
}),
|
|
1488
|
+
...enableSSG ? [
|
|
1489
|
+
rsbuildPluginSSG({
|
|
1490
|
+
routeService,
|
|
1491
|
+
config,
|
|
1492
|
+
pluginDriver
|
|
1493
|
+
})
|
|
1494
|
+
] : []
|
|
1278
1495
|
],
|
|
1279
1496
|
server: {
|
|
1280
1497
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
@@ -1297,9 +1514,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1297
1514
|
html: {
|
|
1298
1515
|
title: (null == config ? void 0 : config.title) ?? DEFAULT_TITLE,
|
|
1299
1516
|
favicon: normalizeIcon(null == config ? void 0 : config.icon),
|
|
1300
|
-
template:
|
|
1517
|
+
template: TEMPLATE_PATH,
|
|
1301
1518
|
tags: [
|
|
1302
|
-
(null
|
|
1519
|
+
(null == (_config_themeConfig = config.themeConfig) ? void 0 : _config_themeConfig.darkMode) !== false ? {
|
|
1303
1520
|
tag: "script",
|
|
1304
1521
|
children: inlineThemeScript,
|
|
1305
1522
|
append: false
|
|
@@ -1309,7 +1526,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1309
1526
|
output: {
|
|
1310
1527
|
assetPrefix,
|
|
1311
1528
|
distPath: {
|
|
1312
|
-
root:
|
|
1529
|
+
root: outDir
|
|
1313
1530
|
}
|
|
1314
1531
|
},
|
|
1315
1532
|
resolve: {
|
|
@@ -1334,7 +1551,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1334
1551
|
define: {
|
|
1335
1552
|
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1336
1553
|
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1337
|
-
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null
|
|
1554
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(null == (_config_themeConfig1 = config.themeConfig) ? void 0 : _config_themeConfig1.socialLinks))
|
|
1338
1555
|
}
|
|
1339
1556
|
},
|
|
1340
1557
|
performance: {
|
|
@@ -1358,7 +1575,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1358
1575
|
const isServer = 'node' === target;
|
|
1359
1576
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1360
1577
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1361
|
-
const checkDeadLinks = ((null == config ? void 0 : null
|
|
1578
|
+
const checkDeadLinks = ((null == config ? void 0 : null == (_config_markdown = config.markdown) ? void 0 : _config_markdown.checkDeadLinks) && !isServer) ?? false;
|
|
1362
1579
|
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP).resolve.merge({
|
|
1363
1580
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1364
1581
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
@@ -1381,7 +1598,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1381
1598
|
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
1382
1599
|
sideEffects: true
|
|
1383
1600
|
});
|
|
1384
|
-
if (isServer) chain.output.filename(
|
|
1601
|
+
if (isServer) chain.output.filename(NODE_SSR_BUNDLE_NAME);
|
|
1385
1602
|
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1386
1603
|
if (enableIncremental) chain.merge({
|
|
1387
1604
|
experiments: {
|
|
@@ -1400,7 +1617,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1400
1617
|
},
|
|
1401
1618
|
source: {
|
|
1402
1619
|
entry: {
|
|
1403
|
-
index:
|
|
1620
|
+
index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
|
|
1404
1621
|
},
|
|
1405
1622
|
define: {
|
|
1406
1623
|
'process.env.__SSR__': JSON.stringify(false)
|
|
@@ -1409,7 +1626,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1409
1626
|
output: {
|
|
1410
1627
|
target: 'web',
|
|
1411
1628
|
distPath: {
|
|
1412
|
-
root:
|
|
1629
|
+
root: outDir
|
|
1413
1630
|
}
|
|
1414
1631
|
}
|
|
1415
1632
|
},
|
|
@@ -1421,23 +1638,29 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1421
1638
|
__VIRTUAL_ROUTES__: 'virtual-routes-ssr'
|
|
1422
1639
|
}
|
|
1423
1640
|
},
|
|
1641
|
+
tools: {
|
|
1642
|
+
rspack: {
|
|
1643
|
+
output: {
|
|
1644
|
+
asyncChunks: false
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
},
|
|
1424
1648
|
source: {
|
|
1425
1649
|
entry: {
|
|
1426
|
-
index:
|
|
1650
|
+
index: SSR_SERVER_ENTRY
|
|
1427
1651
|
},
|
|
1428
1652
|
define: {
|
|
1429
1653
|
'process.env.__SSR__': JSON.stringify(true)
|
|
1430
1654
|
}
|
|
1431
1655
|
},
|
|
1432
1656
|
performance: {
|
|
1433
|
-
printFileSize:
|
|
1657
|
+
printFileSize: {
|
|
1658
|
+
compressed: true
|
|
1659
|
+
}
|
|
1434
1660
|
},
|
|
1435
1661
|
output: {
|
|
1436
1662
|
emitAssets: false,
|
|
1437
1663
|
target: 'node',
|
|
1438
|
-
distPath: {
|
|
1439
|
-
root: ssrOutDir
|
|
1440
|
-
},
|
|
1441
1664
|
minify: false
|
|
1442
1665
|
}
|
|
1443
1666
|
}
|
|
@@ -1464,7 +1687,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1464
1687
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1465
1688
|
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
|
|
1466
1689
|
const rsbuild = await createRsbuild({
|
|
1467
|
-
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null
|
|
1690
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...(null == (_pluginDriver_getPlugins = pluginDriver.getPlugins()) ? void 0 : _pluginDriver_getPlugins.map((plugin)=>plugin.builderConfig ?? {})) || [], (null == config ? void 0 : config.builderConfig) || {}, extraRsbuildConfig || {})
|
|
1468
1691
|
});
|
|
1469
1692
|
rsbuild.addPlugins(builderPlugins);
|
|
1470
1693
|
return rsbuild;
|
|
@@ -1517,15 +1740,12 @@ async function checkLanguageParity(config) {
|
|
|
1517
1740
|
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1518
1741
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1519
1742
|
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1520
|
-
const includedDirs = (null
|
|
1743
|
+
const includedDirs = (null == (_config_languageParity_include = config.languageParity.include) ? void 0 : _config_languageParity_include.length) ? config.languageParity.include : [
|
|
1521
1744
|
''
|
|
1522
1745
|
];
|
|
1523
1746
|
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1524
|
-
const supportedLanguages = (null
|
|
1525
|
-
if (!supportedLanguages.length)
|
|
1526
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1527
|
-
return;
|
|
1528
|
-
}
|
|
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.');
|
|
1529
1749
|
const missingLanguagesFile = [];
|
|
1530
1750
|
try {
|
|
1531
1751
|
for (const includedDir of includedDirs){
|
|
@@ -1555,11 +1775,11 @@ async function dev(options) {
|
|
|
1555
1775
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1556
1776
|
try {
|
|
1557
1777
|
await pluginDriver.beforeBuild();
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1778
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
1779
|
+
rsbuild.onDevCompileDone(async ()=>{
|
|
1560
1780
|
await pluginDriver.afterBuild();
|
|
1561
1781
|
});
|
|
1562
|
-
const { server } = await
|
|
1782
|
+
const { server } = await rsbuild.startDevServer({
|
|
1563
1783
|
getPortSilently: true
|
|
1564
1784
|
});
|
|
1565
1785
|
return server;
|
|
@@ -1568,43 +1788,6 @@ async function dev(options) {
|
|
|
1568
1788
|
await checkLanguageParity(modifiedConfig);
|
|
1569
1789
|
}
|
|
1570
1790
|
}
|
|
1571
|
-
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-alpha.8"}');
|
|
1572
|
-
async function renderFrontmatterHead(route) {
|
|
1573
|
-
if (!isRouteMeta(route)) return '';
|
|
1574
|
-
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
1575
|
-
encoding: 'utf-8'
|
|
1576
|
-
});
|
|
1577
|
-
const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
|
|
1578
|
-
if (!head || 0 === head.length) return '';
|
|
1579
|
-
return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
|
|
1580
|
-
}
|
|
1581
|
-
async function renderConfigHead(config, route) {
|
|
1582
|
-
if (!isRouteMeta(route)) return '';
|
|
1583
|
-
if (!config.head || 0 === config.head.length) return '';
|
|
1584
|
-
return config.head.map((head)=>{
|
|
1585
|
-
if ('string' == typeof head) return head;
|
|
1586
|
-
if ('function' == typeof head) {
|
|
1587
|
-
const resultHead = head(route);
|
|
1588
|
-
if (!resultHead) return '';
|
|
1589
|
-
if ('string' == typeof resultHead) return resultHead;
|
|
1590
|
-
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
1591
|
-
}
|
|
1592
|
-
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1593
|
-
}).join('');
|
|
1594
|
-
}
|
|
1595
|
-
function renderAttrs(attrs) {
|
|
1596
|
-
return Object.entries(attrs).map(([key, value])=>{
|
|
1597
|
-
if ('boolean' == typeof value) return key;
|
|
1598
|
-
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
1599
|
-
throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
1600
|
-
}).join('');
|
|
1601
|
-
}
|
|
1602
|
-
function isRouteMeta(route) {
|
|
1603
|
-
return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
|
|
1604
|
-
}
|
|
1605
|
-
function isCSRFallback(ssgConfig) {
|
|
1606
|
-
return 'object' == typeof ssgConfig && 'csr' === ssgConfig.fallback;
|
|
1607
|
-
}
|
|
1608
1791
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
1609
1792
|
try {
|
|
1610
1793
|
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
@@ -1620,101 +1803,16 @@ function emptyDir(path) {
|
|
|
1620
1803
|
recursive: true
|
|
1621
1804
|
});
|
|
1622
1805
|
}
|
|
1623
|
-
async function renderPages(appDirectory, config, pluginDriver, ssgConfig) {
|
|
1624
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1625
|
-
const startTime = Date.now();
|
|
1626
|
-
const outputPath = (null == config ? void 0 : config.outDir) ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(appDirectory, OUTPUT_DIR);
|
|
1627
|
-
const ssrBundlePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr', 'main.cjs');
|
|
1628
|
-
try {
|
|
1629
|
-
let render;
|
|
1630
|
-
if (ssgConfig) try {
|
|
1631
|
-
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1632
|
-
({ render } = ssrExports);
|
|
1633
|
-
} catch (e) {
|
|
1634
|
-
if (isCSRFallback(ssgConfig)) {
|
|
1635
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(e);
|
|
1636
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}, fallback to CSR.`);
|
|
1637
|
-
} else {
|
|
1638
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}.`);
|
|
1639
|
-
throw e;
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
const routes = init_routeService.getRoutes();
|
|
1643
|
-
const base = (null == config ? void 0 : config.base) ?? '';
|
|
1644
|
-
const htmlTemplatePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'index.html');
|
|
1645
|
-
const htmlTemplate = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(htmlTemplatePath, 'utf-8');
|
|
1646
|
-
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1647
|
-
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
|
|
1648
|
-
}));
|
|
1649
|
-
const allRoutes = [
|
|
1650
|
-
...routes,
|
|
1651
|
-
...additionalRoutes
|
|
1652
|
-
];
|
|
1653
|
-
const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
|
|
1654
|
-
if (!is404RouteInRoutes) allRoutes.push({
|
|
1655
|
-
routePath: '/404'
|
|
1656
|
-
});
|
|
1657
|
-
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1658
|
-
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
|
|
1659
|
-
const { routePath } = route;
|
|
1660
|
-
let appHtml = '';
|
|
1661
|
-
if (render) try {
|
|
1662
|
-
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1663
|
-
} catch (e) {
|
|
1664
|
-
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);
|
|
1665
|
-
else {
|
|
1666
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1667
|
-
throw e;
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
const { helmet } = helmetContext.context;
|
|
1671
|
-
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, [
|
|
1672
|
-
await renderConfigHead(config, route),
|
|
1673
|
-
helmet.title.toString(),
|
|
1674
|
-
helmet.meta.toString(),
|
|
1675
|
-
helmet.link.toString(),
|
|
1676
|
-
helmet.style.toString(),
|
|
1677
|
-
helmet.script.toString(),
|
|
1678
|
-
await renderFrontmatterHead(route)
|
|
1679
|
-
].join(''));
|
|
1680
|
-
if (helmet.htmlAttributes) {
|
|
1681
|
-
var _helmet_htmlAttributes;
|
|
1682
|
-
html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${null === (_helmet_htmlAttributes = helmet.htmlAttributes) || void 0 === _helmet_htmlAttributes ? void 0 : _helmet_htmlAttributes.toString()}`);
|
|
1683
|
-
}
|
|
1684
|
-
if (helmet.bodyAttributes) {
|
|
1685
|
-
var _helmet_bodyAttributes;
|
|
1686
|
-
html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${null === (_helmet_bodyAttributes = helmet.bodyAttributes) || void 0 === _helmet_bodyAttributes ? void 0 : _helmet_bodyAttributes.toString()}`);
|
|
1687
|
-
}
|
|
1688
|
-
const normalizeHtmlFilePath = (path)=>{
|
|
1689
|
-
const normalizedBase = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)((null == config ? void 0 : config.base) || '/');
|
|
1690
|
-
if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
|
|
1691
|
-
return `${path}.html`.replace(normalizedBase, '');
|
|
1692
|
-
};
|
|
1693
|
-
const fileName = normalizeHtmlFilePath(routePath);
|
|
1694
|
-
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)), {
|
|
1695
|
-
recursive: true
|
|
1696
|
-
});
|
|
1697
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, fileName), html);
|
|
1698
|
-
}));
|
|
1699
|
-
if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'ssr'));
|
|
1700
|
-
await emptyDir((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outputPath, 'html'));
|
|
1701
|
-
const totalTime = Date.now() - startTime;
|
|
1702
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1703
|
-
} catch (e) {
|
|
1704
|
-
if (e instanceof Error) __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.stack}`);
|
|
1705
|
-
throw e;
|
|
1706
|
-
}
|
|
1707
|
-
}
|
|
1708
1806
|
async function build(options) {
|
|
1709
|
-
const { docDirectory,
|
|
1807
|
+
const { docDirectory, config } = options;
|
|
1710
1808
|
const pluginDriver = new PluginDriver(config, true);
|
|
1711
1809
|
await pluginDriver.init();
|
|
1712
1810
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1713
1811
|
await pluginDriver.beforeBuild();
|
|
1714
1812
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1715
|
-
await emptyDir(
|
|
1716
|
-
await bundle(docDirectory, modifiedConfig, pluginDriver,
|
|
1717
|
-
|
|
1813
|
+
await emptyDir(constants_TEMP_DIR);
|
|
1814
|
+
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1815
|
+
if (!ssgConfig) hintSSGFalse();
|
|
1718
1816
|
await pluginDriver.afterBuild();
|
|
1719
1817
|
}
|
|
1720
1818
|
async function serve(options) {
|
|
@@ -1723,8 +1821,8 @@ async function serve(options) {
|
|
|
1723
1821
|
const envPort = process.env.PORT;
|
|
1724
1822
|
const envHost = process.env.HOST;
|
|
1725
1823
|
const { builderConfig } = config;
|
|
1726
|
-
const port = Number(envPort || userPort || (null == builderConfig ? void 0 : null
|
|
1727
|
-
const host = envHost || userHost || (null == builderConfig ? void 0 : null
|
|
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';
|
|
1728
1826
|
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1729
1827
|
server: {
|
|
1730
1828
|
port,
|
|
@@ -1734,8 +1832,8 @@ async function serve(options) {
|
|
|
1734
1832
|
const pluginDriver = new PluginDriver(config, true);
|
|
1735
1833
|
await pluginDriver.init();
|
|
1736
1834
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1737
|
-
const
|
|
1738
|
-
return
|
|
1835
|
+
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1836
|
+
return rsbuild.preview();
|
|
1739
1837
|
}
|
|
1740
1838
|
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1741
1839
|
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|