@rspress/core 2.0.0-alpha.9 → 2.0.0-beta.1
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 +154 -2
- package/dist/index.js +603 -533
- package/dist/loader.d.ts +2 -1
- package/dist/loader.js +71 -121
- package/dist/runtime/App.js +6 -5
- package/dist/runtime/ClientApp.d.ts +4 -1
- package/dist/runtime/ClientApp.js +15 -24
- package/dist/runtime/csrClientEntry.d.ts +1 -0
- package/dist/runtime/csrClientEntry.js +13 -0
- package/dist/runtime/initPageData.js +3 -5
- package/dist/runtime/ssrClientEntry.d.ts +1 -0
- package/dist/runtime/ssrClientEntry.js +19 -0
- package/dist/runtime/tsconfig.js +3 -3
- package/package.json +19 -18
- package/dist/runtime/clientEntry.d.ts +0 -1
- package/dist/runtime/clientEntry.js +0 -39
- /package/dist/runtime/{ssrEntry.d.ts → ssrServerEntry.d.ts} +0 -0
- /package/dist/runtime/{ssrEntry.js → ssrServerEntry.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -23,48 +23,24 @@ import * as __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__ from "enhanced
|
|
|
23
23
|
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
24
24
|
import * as __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__ from "react-helmet-async";
|
|
25
25
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
|
|
26
|
+
import * as __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__ from "unist-util-visit";
|
|
26
27
|
export * from "@rspress/shared";
|
|
27
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
28
|
-
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
29
|
-
}
|
|
30
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
31
|
-
if (descriptor.get) return descriptor.get.call(receiver);
|
|
32
|
-
return descriptor.value;
|
|
33
|
-
}
|
|
34
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
35
|
-
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
36
|
-
else {
|
|
37
|
-
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
38
|
-
descriptor.value = value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
42
|
-
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
43
|
-
return privateMap.get(receiver);
|
|
44
|
-
}
|
|
45
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
46
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
47
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
48
|
-
}
|
|
49
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
50
|
-
_check_private_redeclaration(obj, privateMap);
|
|
51
|
-
privateMap.set(obj, value);
|
|
52
|
-
}
|
|
53
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
54
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
55
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
56
|
-
return value;
|
|
57
|
-
}
|
|
58
|
-
var _config = /*#__PURE__*/ new WeakMap(), _plugins = /*#__PURE__*/ new WeakMap(), _isProd = /*#__PURE__*/ new WeakMap();
|
|
59
28
|
class PluginDriver {
|
|
29
|
+
#config;
|
|
30
|
+
#plugins;
|
|
31
|
+
#isProd;
|
|
32
|
+
constructor(config, isProd){
|
|
33
|
+
this.#config = config;
|
|
34
|
+
this.#isProd = isProd;
|
|
35
|
+
this.#plugins = [];
|
|
36
|
+
}
|
|
60
37
|
async init() {
|
|
61
|
-
var _themeConfig_locales, _themeConfig_locales_, _themeConfig_locales1, _themeConfig_locales_1, _themeConfig_locales2;
|
|
62
38
|
this.clearPlugins();
|
|
63
|
-
const config =
|
|
64
|
-
const themeConfig =
|
|
65
|
-
const enableLastUpdated =
|
|
66
|
-
const mediumZoomConfig =
|
|
67
|
-
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar ||
|
|
39
|
+
const config = this.#config;
|
|
40
|
+
const themeConfig = config?.themeConfig || {};
|
|
41
|
+
const enableLastUpdated = themeConfig?.lastUpdated || themeConfig?.locales?.some((locale)=>locale.lastUpdated);
|
|
42
|
+
const mediumZoomConfig = config?.mediumZoom ?? true;
|
|
43
|
+
const haveNavSidebarConfig = themeConfig.nav || themeConfig.sidebar || themeConfig.locales?.[0]?.nav || themeConfig.locales?.[0]?.sidebar;
|
|
68
44
|
if (enableLastUpdated) {
|
|
69
45
|
const { pluginLastUpdated } = await import("@rspress/plugin-last-updated");
|
|
70
46
|
this.addPlugin(pluginLastUpdated());
|
|
@@ -87,78 +63,81 @@ class PluginDriver {
|
|
|
87
63
|
}
|
|
88
64
|
}
|
|
89
65
|
addPlugin(plugin) {
|
|
90
|
-
const existedIndex =
|
|
66
|
+
const existedIndex = this.#plugins.findIndex((item)=>item.name === plugin.name);
|
|
91
67
|
if (-1 !== existedIndex) throw new Error(`The plugin "${plugin.name}" has been registered`);
|
|
92
|
-
|
|
68
|
+
this.#plugins.push(plugin);
|
|
93
69
|
}
|
|
94
70
|
getPlugins() {
|
|
95
|
-
return
|
|
71
|
+
return this.#plugins;
|
|
96
72
|
}
|
|
97
73
|
clearPlugins() {
|
|
98
|
-
|
|
74
|
+
this.#plugins = [];
|
|
99
75
|
}
|
|
100
76
|
removePlugin(pluginName) {
|
|
101
|
-
const index =
|
|
102
|
-
if (-1 !== index)
|
|
77
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
78
|
+
if (-1 !== index) this.#plugins.splice(index, 1);
|
|
103
79
|
}
|
|
104
80
|
async modifyConfig() {
|
|
105
|
-
let config =
|
|
106
|
-
for(let i = 0; i <
|
|
107
|
-
const plugin =
|
|
81
|
+
let config = this.#config;
|
|
82
|
+
for(let i = 0; i < this.#plugins.length; i++){
|
|
83
|
+
const plugin = this.#plugins[i];
|
|
108
84
|
if ('function' == typeof plugin.config) config = await plugin.config(config || {}, {
|
|
109
85
|
addPlugin: this.addPlugin.bind(this),
|
|
110
86
|
removePlugin: (pluginName)=>{
|
|
111
|
-
const index =
|
|
87
|
+
const index = this.#plugins.findIndex((item)=>item.name === pluginName);
|
|
112
88
|
this.removePlugin(pluginName);
|
|
113
89
|
if (index <= i && index > 0) i--;
|
|
114
90
|
}
|
|
115
|
-
},
|
|
91
|
+
}, this.#isProd);
|
|
116
92
|
}
|
|
117
|
-
|
|
118
|
-
return
|
|
93
|
+
this.#config = config;
|
|
94
|
+
return this.#config;
|
|
119
95
|
}
|
|
120
96
|
async beforeBuild() {
|
|
121
|
-
return this._runParallelAsyncHook('beforeBuild',
|
|
97
|
+
return this._runParallelAsyncHook('beforeBuild', this.#config || {}, this.#isProd);
|
|
122
98
|
}
|
|
123
99
|
async afterBuild() {
|
|
124
|
-
return this._runParallelAsyncHook('afterBuild',
|
|
100
|
+
return this._runParallelAsyncHook('afterBuild', this.#config || {}, this.#isProd);
|
|
125
101
|
}
|
|
126
102
|
async modifySearchIndexData(pages) {
|
|
127
|
-
return this._runParallelAsyncHook('modifySearchIndexData', pages,
|
|
103
|
+
return this._runParallelAsyncHook('modifySearchIndexData', pages, this.#isProd);
|
|
128
104
|
}
|
|
129
105
|
async extendPageData(pageData) {
|
|
130
|
-
return this._runParallelAsyncHook('extendPageData', pageData,
|
|
106
|
+
return this._runParallelAsyncHook('extendPageData', pageData, this.#isProd);
|
|
131
107
|
}
|
|
132
108
|
async addPages() {
|
|
133
|
-
const result = await this._runParallelAsyncHook('addPages',
|
|
109
|
+
const result = await this._runParallelAsyncHook('addPages', this.#config || {}, this.#isProd);
|
|
134
110
|
return result.flat();
|
|
135
111
|
}
|
|
136
112
|
async routeGenerated(routes) {
|
|
137
|
-
return this._runParallelAsyncHook('routeGenerated', routes,
|
|
113
|
+
return this._runParallelAsyncHook('routeGenerated', routes, this.#isProd);
|
|
114
|
+
}
|
|
115
|
+
async routeServiceGenerated(routeService) {
|
|
116
|
+
return this._runParallelAsyncHook('routeServiceGenerated', routeService, this.#isProd);
|
|
138
117
|
}
|
|
139
118
|
async addRuntimeModules() {
|
|
140
|
-
const result = await this._runParallelAsyncHook('addRuntimeModules',
|
|
119
|
+
const result = await this._runParallelAsyncHook('addRuntimeModules', this.#config || {}, this.#isProd);
|
|
141
120
|
return result.reduce((prev, current)=>({
|
|
142
121
|
...prev,
|
|
143
122
|
...current
|
|
144
123
|
}), {});
|
|
145
124
|
}
|
|
146
125
|
async addSSGRoutes() {
|
|
147
|
-
const result = await this._runParallelAsyncHook('addSSGRoutes',
|
|
126
|
+
const result = await this._runParallelAsyncHook('addSSGRoutes', this.#config || {}, this.#isProd);
|
|
148
127
|
return result.flat();
|
|
149
128
|
}
|
|
150
129
|
globalUIComponents() {
|
|
151
|
-
const result =
|
|
130
|
+
const result = this.#plugins.map((plugin)=>plugin.globalUIComponents || []);
|
|
152
131
|
return result.flat();
|
|
153
132
|
}
|
|
154
133
|
globalStyles() {
|
|
155
|
-
return
|
|
134
|
+
return this.#plugins.filter((plugin)=>'string' == typeof plugin.globalStyles).map((plugin)=>plugin.globalStyles);
|
|
156
135
|
}
|
|
157
136
|
_runParallelAsyncHook(hookName, ...args) {
|
|
158
|
-
return Promise.all(
|
|
137
|
+
return Promise.all(this.#plugins.filter((plugin)=>'function' == typeof plugin[hookName]).map((plugin)=>plugin[hookName](...args)));
|
|
159
138
|
}
|
|
160
139
|
_runSerialAsyncHook(hookName, ...args) {
|
|
161
|
-
return
|
|
140
|
+
return this.#plugins.reduce(async (prev, plugin)=>{
|
|
162
141
|
if ('function' == typeof plugin[hookName]) {
|
|
163
142
|
await prev;
|
|
164
143
|
return plugin[hookName](...args);
|
|
@@ -166,23 +145,6 @@ class PluginDriver {
|
|
|
166
145
|
return prev;
|
|
167
146
|
}, Promise.resolve());
|
|
168
147
|
}
|
|
169
|
-
constructor(config, isProd){
|
|
170
|
-
_class_private_field_init(this, _config, {
|
|
171
|
-
writable: true,
|
|
172
|
-
value: void 0
|
|
173
|
-
});
|
|
174
|
-
_class_private_field_init(this, _plugins, {
|
|
175
|
-
writable: true,
|
|
176
|
-
value: void 0
|
|
177
|
-
});
|
|
178
|
-
_class_private_field_init(this, _isProd, {
|
|
179
|
-
writable: true,
|
|
180
|
-
value: void 0
|
|
181
|
-
});
|
|
182
|
-
_class_private_field_set(this, _config, config);
|
|
183
|
-
_class_private_field_set(this, _isProd, isProd);
|
|
184
|
-
_class_private_field_set(this, _plugins, []);
|
|
185
|
-
}
|
|
186
148
|
}
|
|
187
149
|
const PLUGIN_VIRTUAL_MODULE_NAME = 'rsbuild:virtual-module';
|
|
188
150
|
const pluginVirtualModule = (pluginOptions = {})=>({
|
|
@@ -215,6 +177,8 @@ const pluginVirtualModule = (pluginOptions = {})=>({
|
|
|
215
177
|
}
|
|
216
178
|
}
|
|
217
179
|
});
|
|
180
|
+
var package_namespaceObject = JSON.parse('{"i8":"2.0.0-beta.1"}');
|
|
181
|
+
const RSPRESS_VERSION = package_namespaceObject.i8;
|
|
218
182
|
const isProduction = ()=>'production' === process.env.NODE_ENV;
|
|
219
183
|
const importStatementRegex = /import\s+(.*?)\s+from\s+(['"])(.*?)(?:"|');?/gm;
|
|
220
184
|
const inlineThemeScript = `{
|
|
@@ -227,8 +191,10 @@ const inlineThemeScript = `{
|
|
|
227
191
|
}`.replace(/\n/g, ';').replace(/\s{2,}/g, '');
|
|
228
192
|
const dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(new URL(import.meta.url)));
|
|
229
193
|
const PACKAGE_ROOT = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(dirname, '..');
|
|
230
|
-
const
|
|
231
|
-
const
|
|
194
|
+
const TEMPLATE_PATH = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'index.html');
|
|
195
|
+
const CSR_CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'csrClientEntry.js');
|
|
196
|
+
const SSR_CLIENT_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrClientEntry.js');
|
|
197
|
+
const SSR_SERVER_ENTRY = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(PACKAGE_ROOT, 'dist', 'runtime', 'ssrServerEntry.js');
|
|
232
198
|
const OUTPUT_DIR = 'doc_build';
|
|
233
199
|
const APP_HTML_MARKER = '<!--<?- DOC_CONTENT ?>-->';
|
|
234
200
|
const HEAD_MARKER = '<!--<?- HEAD ?>-->';
|
|
@@ -282,6 +248,14 @@ async function hintThemeBreakingChange(customThemeDir) {
|
|
|
282
248
|
+ export * from 'rspress/theme';
|
|
283
249
|
`));
|
|
284
250
|
}
|
|
251
|
+
function hintSSGFailed() {
|
|
252
|
+
__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:
|
|
253
|
+
1. Fix code to make it SSR-compatible.
|
|
254
|
+
2. Set \`ssg: false\`, but the SSG feature will be lost.`);
|
|
255
|
+
}
|
|
256
|
+
function hintSSGFalse() {
|
|
257
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('`ssg: false` detected, SSG will be disabled.');
|
|
258
|
+
}
|
|
285
259
|
const isWindows = 'win32' === __WEBPACK_EXTERNAL_MODULE_node_os_74b4b876__["default"].platform();
|
|
286
260
|
function slash(p) {
|
|
287
261
|
return p.replace(/\\/g, '/');
|
|
@@ -334,71 +308,49 @@ const normalizeRoutePath = (routePath, base, lang, version, langs, versions, ext
|
|
|
334
308
|
version: versionPart || version
|
|
335
309
|
};
|
|
336
310
|
};
|
|
337
|
-
function RouteService_check_private_redeclaration(obj, privateCollection) {
|
|
338
|
-
if (privateCollection.has(obj)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
339
|
-
}
|
|
340
|
-
function RouteService_class_apply_descriptor_get(receiver, descriptor) {
|
|
341
|
-
if (descriptor.get) return descriptor.get.call(receiver);
|
|
342
|
-
return descriptor.value;
|
|
343
|
-
}
|
|
344
|
-
function RouteService_class_apply_descriptor_set(receiver, descriptor, value) {
|
|
345
|
-
if (descriptor.set) descriptor.set.call(receiver, value);
|
|
346
|
-
else {
|
|
347
|
-
if (!descriptor.writable) throw new TypeError("attempted to set read only private field");
|
|
348
|
-
descriptor.value = value;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
function RouteService_class_extract_field_descriptor(receiver, privateMap, action) {
|
|
352
|
-
if (!privateMap.has(receiver)) throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
353
|
-
return privateMap.get(receiver);
|
|
354
|
-
}
|
|
355
|
-
function RouteService_class_private_field_get(receiver, privateMap) {
|
|
356
|
-
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "get");
|
|
357
|
-
return RouteService_class_apply_descriptor_get(receiver, descriptor);
|
|
358
|
-
}
|
|
359
|
-
function RouteService_class_private_field_init(obj, privateMap, value) {
|
|
360
|
-
RouteService_check_private_redeclaration(obj, privateMap);
|
|
361
|
-
privateMap.set(obj, value);
|
|
362
|
-
}
|
|
363
|
-
function RouteService_class_private_field_set(receiver, privateMap, value) {
|
|
364
|
-
var descriptor = RouteService_class_extract_field_descriptor(receiver, privateMap, "set");
|
|
365
|
-
RouteService_class_apply_descriptor_set(receiver, descriptor, value);
|
|
366
|
-
return value;
|
|
367
|
-
}
|
|
368
|
-
function _class_private_method_get(receiver, privateSet, fn) {
|
|
369
|
-
if (!privateSet.has(receiver)) throw new TypeError("attempted to get private field on non-instance");
|
|
370
|
-
return fn;
|
|
371
|
-
}
|
|
372
|
-
function _class_private_method_init(obj, privateSet) {
|
|
373
|
-
RouteService_check_private_redeclaration(obj, privateSet);
|
|
374
|
-
privateSet.add(obj);
|
|
375
|
-
}
|
|
376
|
-
function _define_property(obj, key, value) {
|
|
377
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
378
|
-
value: value,
|
|
379
|
-
enumerable: true,
|
|
380
|
-
configurable: true,
|
|
381
|
-
writable: true
|
|
382
|
-
});
|
|
383
|
-
else obj[key] = value;
|
|
384
|
-
return obj;
|
|
385
|
-
}
|
|
386
|
-
var _scanDir = /*#__PURE__*/ new WeakMap(), _defaultLang = /*#__PURE__*/ new WeakMap(), _defaultVersion = /*#__PURE__*/ new WeakMap(), _extensions = /*#__PURE__*/ new WeakMap(), _langs = /*#__PURE__*/ new WeakMap(), _versions = /*#__PURE__*/ new WeakMap(), _include = /*#__PURE__*/ new WeakMap(), _exclude = /*#__PURE__*/ new WeakMap(), _base = /*#__PURE__*/ new WeakMap(), _tempDir = /*#__PURE__*/ new WeakMap(), _pluginDriver = /*#__PURE__*/ new WeakMap(), _writeTempFile = /*#__PURE__*/ new WeakSet(), _generateRouteInfo = /*#__PURE__*/ new WeakSet();
|
|
387
311
|
class RouteService {
|
|
312
|
+
routeData = new Map();
|
|
313
|
+
#scanDir;
|
|
314
|
+
#defaultLang;
|
|
315
|
+
#defaultVersion = '';
|
|
316
|
+
#extensions = [];
|
|
317
|
+
#langs = [];
|
|
318
|
+
#versions = [];
|
|
319
|
+
#include = [];
|
|
320
|
+
#exclude = [];
|
|
321
|
+
#base = '';
|
|
322
|
+
#tempDir = '';
|
|
323
|
+
#pluginDriver;
|
|
324
|
+
constructor(scanDir, userConfig, tempDir, pluginDriver){
|
|
325
|
+
const routeOptions = userConfig?.route || {};
|
|
326
|
+
this.#scanDir = scanDir;
|
|
327
|
+
this.#extensions = routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS;
|
|
328
|
+
this.#include = routeOptions.include || [];
|
|
329
|
+
this.#exclude = routeOptions.exclude || [];
|
|
330
|
+
this.#defaultLang = userConfig?.lang || '';
|
|
331
|
+
this.#langs = (userConfig?.locales ?? userConfig?.themeConfig?.locales ?? []).map((item)=>item.lang);
|
|
332
|
+
this.#base = userConfig?.base || '';
|
|
333
|
+
this.#tempDir = tempDir;
|
|
334
|
+
this.#pluginDriver = pluginDriver;
|
|
335
|
+
if (userConfig.multiVersion) {
|
|
336
|
+
this.#defaultVersion = userConfig.multiVersion.default || '';
|
|
337
|
+
this.#versions = userConfig.multiVersion.versions || [];
|
|
338
|
+
}
|
|
339
|
+
}
|
|
388
340
|
get extensions() {
|
|
389
|
-
return
|
|
341
|
+
return this.#extensions;
|
|
390
342
|
}
|
|
391
343
|
async init() {
|
|
392
|
-
const extensions =
|
|
344
|
+
const extensions = this.#extensions.map((i)=>i.slice(1));
|
|
393
345
|
const files = (await (0, __WEBPACK_EXTERNAL_MODULE_tinyglobby__.glob)([
|
|
394
346
|
`**/*.{${extensions.join(',')}}`,
|
|
395
|
-
...
|
|
347
|
+
...this.#include
|
|
396
348
|
], {
|
|
397
|
-
cwd:
|
|
349
|
+
cwd: this.#scanDir,
|
|
398
350
|
absolute: true,
|
|
399
351
|
onlyFiles: true,
|
|
400
352
|
ignore: [
|
|
401
|
-
...
|
|
353
|
+
...this.#exclude,
|
|
402
354
|
'**/node_modules/**',
|
|
403
355
|
'**/.eslintrc.js',
|
|
404
356
|
'**/.nx/**',
|
|
@@ -406,9 +358,9 @@ class RouteService {
|
|
|
406
358
|
]
|
|
407
359
|
})).sort();
|
|
408
360
|
files.forEach((filePath)=>{
|
|
409
|
-
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(
|
|
361
|
+
const fileRelativePath = normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filePath));
|
|
410
362
|
const { routePath, lang, version } = this.normalizeRoutePath(fileRelativePath);
|
|
411
|
-
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(
|
|
363
|
+
const absolutePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(this.#scanDir, fileRelativePath);
|
|
412
364
|
const routeInfo = {
|
|
413
365
|
routePath,
|
|
414
366
|
absolutePath: normalizePath(absolutePath),
|
|
@@ -419,32 +371,32 @@ class RouteService {
|
|
|
419
371
|
};
|
|
420
372
|
this.addRoute(routeInfo);
|
|
421
373
|
});
|
|
422
|
-
const externalPages = await
|
|
374
|
+
const externalPages = await this.#pluginDriver.addPages();
|
|
423
375
|
await Promise.all(externalPages.map(async (route, index)=>{
|
|
424
376
|
const { routePath, content, filepath } = route;
|
|
425
377
|
if (filepath) {
|
|
426
|
-
const routeInfo =
|
|
378
|
+
const routeInfo = this.#generateRouteInfo(routePath, filepath);
|
|
427
379
|
this.addRoute(routeInfo);
|
|
428
380
|
return;
|
|
429
381
|
}
|
|
430
382
|
if (content) {
|
|
431
|
-
const filepath = await
|
|
432
|
-
const routeInfo =
|
|
383
|
+
const filepath = await this.#writeTempFile(index, content);
|
|
384
|
+
const routeInfo = this.#generateRouteInfo(routePath, filepath);
|
|
433
385
|
this.addRoute(routeInfo);
|
|
434
386
|
}
|
|
435
387
|
}));
|
|
436
|
-
await
|
|
388
|
+
await this.#pluginDriver.routeGenerated(this.getRoutes());
|
|
437
389
|
}
|
|
438
390
|
addRoute(routeInfo) {
|
|
439
391
|
const { routePath, absolutePath } = routeInfo;
|
|
440
392
|
if (this.routeData.has(routePath)) {
|
|
441
|
-
const preRouteExtIndex =
|
|
442
|
-
const currRouteExtIndex =
|
|
393
|
+
const preRouteExtIndex = this.#extensions.indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(this.routeData.get(routePath).absolutePath));
|
|
394
|
+
const currRouteExtIndex = this.#extensions.indexOf(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(absolutePath));
|
|
443
395
|
if (-1 !== currRouteExtIndex && (currRouteExtIndex < preRouteExtIndex || -1 === preRouteExtIndex)) this.routeData.set(routePath, routeInfo);
|
|
444
396
|
} else this.routeData.set(routePath, routeInfo);
|
|
445
397
|
}
|
|
446
398
|
removeRoute(filePath) {
|
|
447
|
-
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(
|
|
399
|
+
const fileRelativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filePath);
|
|
448
400
|
const { routePath } = this.normalizeRoutePath(fileRelativePath);
|
|
449
401
|
this.routeData.delete(routePath);
|
|
450
402
|
}
|
|
@@ -479,155 +431,57 @@ ${routeMeta.map((route, index)=>{
|
|
|
479
431
|
`;
|
|
480
432
|
}
|
|
481
433
|
getRoutePathParts(routePath) {
|
|
482
|
-
return getRoutePathParts(routePath,
|
|
434
|
+
return getRoutePathParts(routePath, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions);
|
|
483
435
|
}
|
|
484
436
|
normalizeRoutePath(routePath) {
|
|
485
|
-
return normalizeRoutePath(routePath,
|
|
437
|
+
return normalizeRoutePath(routePath, this.#base, this.#defaultLang, this.#defaultVersion, this.#langs, this.#versions, this.#extensions);
|
|
486
438
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
value: ''
|
|
503
|
-
});
|
|
504
|
-
RouteService_class_private_field_init(this, _extensions, {
|
|
505
|
-
writable: true,
|
|
506
|
-
value: []
|
|
507
|
-
});
|
|
508
|
-
RouteService_class_private_field_init(this, _langs, {
|
|
509
|
-
writable: true,
|
|
510
|
-
value: []
|
|
511
|
-
});
|
|
512
|
-
RouteService_class_private_field_init(this, _versions, {
|
|
513
|
-
writable: true,
|
|
514
|
-
value: []
|
|
515
|
-
});
|
|
516
|
-
RouteService_class_private_field_init(this, _include, {
|
|
517
|
-
writable: true,
|
|
518
|
-
value: []
|
|
519
|
-
});
|
|
520
|
-
RouteService_class_private_field_init(this, _exclude, {
|
|
521
|
-
writable: true,
|
|
522
|
-
value: []
|
|
523
|
-
});
|
|
524
|
-
RouteService_class_private_field_init(this, _base, {
|
|
525
|
-
writable: true,
|
|
526
|
-
value: ''
|
|
527
|
-
});
|
|
528
|
-
RouteService_class_private_field_init(this, _tempDir, {
|
|
529
|
-
writable: true,
|
|
530
|
-
value: ''
|
|
531
|
-
});
|
|
532
|
-
RouteService_class_private_field_init(this, _pluginDriver, {
|
|
533
|
-
writable: true,
|
|
534
|
-
value: void 0
|
|
535
|
-
});
|
|
536
|
-
const routeOptions = (null == userConfig ? void 0 : userConfig.route) || {};
|
|
537
|
-
RouteService_class_private_field_set(this, _scanDir, scanDir);
|
|
538
|
-
RouteService_class_private_field_set(this, _extensions, routeOptions.extensions || __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS);
|
|
539
|
-
RouteService_class_private_field_set(this, _include, routeOptions.include || []);
|
|
540
|
-
RouteService_class_private_field_set(this, _exclude, routeOptions.exclude || []);
|
|
541
|
-
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));
|
|
543
|
-
RouteService_class_private_field_set(this, _base, (null == userConfig ? void 0 : userConfig.base) || '');
|
|
544
|
-
RouteService_class_private_field_set(this, _tempDir, tempDir);
|
|
545
|
-
RouteService_class_private_field_set(this, _pluginDriver, pluginDriver);
|
|
546
|
-
if (userConfig.multiVersion) {
|
|
547
|
-
RouteService_class_private_field_set(this, _defaultVersion, userConfig.multiVersion.default || '');
|
|
548
|
-
RouteService_class_private_field_set(this, _versions, userConfig.multiVersion.versions || []);
|
|
549
|
-
}
|
|
439
|
+
async #writeTempFile(index, content) {
|
|
440
|
+
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(this.#tempDir, `temp-${index}.mdx`);
|
|
441
|
+
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
442
|
+
return tempFilePath;
|
|
443
|
+
}
|
|
444
|
+
#generateRouteInfo(routePath, filepath) {
|
|
445
|
+
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
446
|
+
return {
|
|
447
|
+
routePath: normalizedPath,
|
|
448
|
+
absolutePath: normalizePath(filepath),
|
|
449
|
+
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(this.#scanDir, filepath)),
|
|
450
|
+
pageName: getPageKey(routePath),
|
|
451
|
+
lang,
|
|
452
|
+
version
|
|
453
|
+
};
|
|
550
454
|
}
|
|
551
|
-
}
|
|
552
|
-
async function writeTempFile(index, content) {
|
|
553
|
-
const tempFilePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(RouteService_class_private_field_get(this, _tempDir), `temp-${index}.mdx`);
|
|
554
|
-
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].writeFile(tempFilePath, content);
|
|
555
|
-
return tempFilePath;
|
|
556
|
-
}
|
|
557
|
-
function generateRouteInfo(routePath, filepath) {
|
|
558
|
-
const { routePath: normalizedPath, lang, version } = this.normalizeRoutePath(routePath);
|
|
559
|
-
return {
|
|
560
|
-
routePath: normalizedPath,
|
|
561
|
-
absolutePath: normalizePath(filepath),
|
|
562
|
-
relativePath: normalizePath(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(RouteService_class_private_field_get(this, _scanDir), filepath)),
|
|
563
|
-
pageName: getPageKey(routePath),
|
|
564
|
-
lang,
|
|
565
|
-
version
|
|
566
|
-
};
|
|
567
455
|
}
|
|
568
456
|
let init_routeService = null;
|
|
569
457
|
async function initRouteService(options) {
|
|
570
458
|
const { scanDir, config, runtimeTempDir, pluginDriver } = options;
|
|
571
459
|
init_routeService = new RouteService(scanDir, config, runtimeTempDir, pluginDriver);
|
|
572
460
|
await init_routeService.init();
|
|
461
|
+
await pluginDriver.routeServiceGenerated(init_routeService);
|
|
573
462
|
return init_routeService;
|
|
574
463
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
]
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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
|
-
}
|
|
464
|
+
var types_RuntimeModuleID = /*#__PURE__*/ function(RuntimeModuleID) {
|
|
465
|
+
RuntimeModuleID["GlobalStyles"] = "virtual-global-styles";
|
|
466
|
+
RuntimeModuleID["GlobalComponents"] = "virtual-global-components";
|
|
467
|
+
RuntimeModuleID["RouteForClient"] = "virtual-routes";
|
|
468
|
+
RuntimeModuleID["RouteForSSR"] = "virtual-routes-ssr";
|
|
469
|
+
RuntimeModuleID["SiteData"] = "virtual-site-data";
|
|
470
|
+
RuntimeModuleID["SearchIndexHash"] = "virtual-search-index-hash";
|
|
471
|
+
RuntimeModuleID["I18nText"] = "virtual-i18n-text";
|
|
472
|
+
RuntimeModuleID["SearchHooks"] = "virtual-search-hooks";
|
|
473
|
+
RuntimeModuleID["PrismLanguages"] = "virtual-prism-languages";
|
|
474
|
+
return RuntimeModuleID;
|
|
475
|
+
}({});
|
|
610
476
|
async function routeVMPlugin(context) {
|
|
611
477
|
const { routeService, isSSR } = context;
|
|
612
478
|
if (!isSSR) return {
|
|
613
|
-
[
|
|
614
|
-
[
|
|
479
|
+
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
480
|
+
[types_RuntimeModuleID.RouteForSSR]: ''
|
|
615
481
|
};
|
|
616
482
|
return {
|
|
617
|
-
[
|
|
618
|
-
[
|
|
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
|
|
483
|
+
[types_RuntimeModuleID.RouteForClient]: routeService.generateRoutesCode(false),
|
|
484
|
+
[types_RuntimeModuleID.RouteForSSR]: routeService.generateRoutesCode(true)
|
|
631
485
|
};
|
|
632
486
|
}
|
|
633
487
|
function createHash(str) {
|
|
@@ -688,10 +542,7 @@ async function flattenMdxContent(content, basePath, alias) {
|
|
|
688
542
|
deps
|
|
689
543
|
};
|
|
690
544
|
}
|
|
691
|
-
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>
|
|
692
|
-
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) || [];
|
|
694
|
-
}).filter((node)=>'ImportDeclaration' === node.type);
|
|
545
|
+
const importNodes = ast.children.filter((node)=>'mdxjsEsm' === node.type).flatMap((node)=>node.data?.estree?.body || []).filter((node)=>'ImportDeclaration' === node.type);
|
|
695
546
|
for (const importNode of importNodes){
|
|
696
547
|
const id = importNode.specifiers[0].local.name;
|
|
697
548
|
const importPath = importNode.source.value;
|
|
@@ -729,6 +580,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
729
580
|
id: index,
|
|
730
581
|
title: '',
|
|
731
582
|
content: '',
|
|
583
|
+
_flattenContent: '',
|
|
732
584
|
_html: '',
|
|
733
585
|
routePath: route.routePath,
|
|
734
586
|
lang: route.lang,
|
|
@@ -741,9 +593,9 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
741
593
|
};
|
|
742
594
|
if (!__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP.test(route.absolutePath)) return defaultIndexInfo;
|
|
743
595
|
let content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, 'utf8');
|
|
744
|
-
const { frontmatter, content:
|
|
596
|
+
const { frontmatter, content: contentWithoutFrontMatter } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, root);
|
|
745
597
|
applyReplaceRulesToNestedObject(frontmatter, replaceRules);
|
|
746
|
-
const { flattenContent } = await flattenMdxContent(applyReplaceRules(
|
|
598
|
+
const { flattenContent } = await flattenMdxContent(applyReplaceRules(contentWithoutFrontMatter, replaceRules), route.absolutePath, alias);
|
|
747
599
|
content = flattenContent.replace(importStatementRegex, '');
|
|
748
600
|
const { html: rawHtml, title, toc: rawToc, languages } = await (0, __WEBPACK_EXTERNAL_MODULE__rspress_mdx_rs_d2f3021f__.compile)({
|
|
749
601
|
value: content,
|
|
@@ -812,6 +664,7 @@ async function extractPageData(replaceRules, alias, domain, root, routeService,
|
|
|
812
664
|
title: frontmatter.title || title,
|
|
813
665
|
toc,
|
|
814
666
|
content,
|
|
667
|
+
_flattenContent: flattenContent,
|
|
815
668
|
_html: html,
|
|
816
669
|
frontmatter: {
|
|
817
670
|
...frontmatter,
|
|
@@ -872,24 +725,24 @@ function getI18nData(docConfig) {
|
|
|
872
725
|
return {};
|
|
873
726
|
}
|
|
874
727
|
}
|
|
875
|
-
|
|
728
|
+
const i18nVMPlugin = (context)=>{
|
|
876
729
|
const { config } = context;
|
|
877
730
|
return {
|
|
878
|
-
[
|
|
731
|
+
[types_RuntimeModuleID.I18nText]: ({ addDependency, addMissingDependency })=>{
|
|
879
732
|
addDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
880
733
|
addMissingDependency(config.i18nSourcePath || DEFAULT_I18N_SOURCE);
|
|
881
734
|
const i18nData = getI18nData(config);
|
|
882
735
|
return `export default ${JSON.stringify(i18nData, null, 2)}`;
|
|
883
736
|
}
|
|
884
737
|
};
|
|
885
|
-
}
|
|
738
|
+
};
|
|
886
739
|
function normalizeThemeConfig(docConfig, pages = []) {
|
|
887
740
|
const { locales: siteLocales, base = '', lang, replaceRules = [], multiVersion } = docConfig;
|
|
888
741
|
const { versions = [] } = multiVersion || {};
|
|
889
742
|
const hasMultiVersion = versions.length > 0;
|
|
890
743
|
docConfig.themeConfig = docConfig.themeConfig || {};
|
|
891
744
|
const { themeConfig } = docConfig;
|
|
892
|
-
const locales = siteLocales ?? (
|
|
745
|
+
const locales = siteLocales ?? (themeConfig?.locales || []);
|
|
893
746
|
const i18nTextData = getI18nData(docConfig);
|
|
894
747
|
const normalizeLinkPrefix = (link = '', currentLang = '')=>{
|
|
895
748
|
const normalizedLink = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(link);
|
|
@@ -897,8 +750,7 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
897
750
|
return lang === currentLang ? normalizedLink : `/${currentLang}${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(normalizedLink)}`;
|
|
898
751
|
};
|
|
899
752
|
const getI18nText = (key = '', currentLang = '')=>{
|
|
900
|
-
|
|
901
|
-
const text = null === (_i18nTextData_key = i18nTextData[key]) || void 0 === _i18nTextData_key ? void 0 : _i18nTextData_key[currentLang];
|
|
753
|
+
const text = i18nTextData[key]?.[currentLang];
|
|
902
754
|
return text || key;
|
|
903
755
|
};
|
|
904
756
|
const normalizeSidebar = (sidebar, currentLang = '')=>{
|
|
@@ -923,9 +775,9 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
923
775
|
const normalizedItem = normalizeLinkPrefix(item, currentLang);
|
|
924
776
|
const page = pages.find((page)=>page.routePath === (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(normalizedItem, base));
|
|
925
777
|
return {
|
|
926
|
-
text: applyReplaceRules(
|
|
778
|
+
text: applyReplaceRules(page?.title || '', replaceRules),
|
|
927
779
|
link: normalizedItem,
|
|
928
|
-
_fileKey:
|
|
780
|
+
_fileKey: page?._relativePath.replace(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(page._relativePath), '')
|
|
929
781
|
};
|
|
930
782
|
}
|
|
931
783
|
return {
|
|
@@ -971,19 +823,18 @@ function normalizeThemeConfig(docConfig, pages = []) {
|
|
|
971
823
|
}, {});
|
|
972
824
|
};
|
|
973
825
|
if (locales.length) themeConfig.locales = locales.map(({ lang: currentLang, label })=>{
|
|
974
|
-
|
|
975
|
-
const localeInThemeConfig = null === (_themeConfig_locales = themeConfig.locales) || void 0 === _themeConfig_locales ? void 0 : _themeConfig_locales.find((locale)=>locale.lang === currentLang);
|
|
826
|
+
const localeInThemeConfig = themeConfig.locales?.find((locale)=>locale.lang === currentLang);
|
|
976
827
|
return {
|
|
977
828
|
lang: currentLang,
|
|
978
829
|
label,
|
|
979
830
|
...localeInThemeConfig || {},
|
|
980
|
-
sidebar: normalizeSidebar(
|
|
981
|
-
nav: normalizeNav(
|
|
831
|
+
sidebar: normalizeSidebar(localeInThemeConfig?.sidebar ?? themeConfig.sidebar, currentLang),
|
|
832
|
+
nav: normalizeNav(localeInThemeConfig?.nav ?? themeConfig.nav, currentLang)
|
|
982
833
|
};
|
|
983
834
|
});
|
|
984
835
|
else {
|
|
985
|
-
themeConfig.sidebar = normalizeSidebar(
|
|
986
|
-
themeConfig.nav = normalizeNav(
|
|
836
|
+
themeConfig.sidebar = normalizeSidebar(themeConfig?.sidebar);
|
|
837
|
+
themeConfig.nav = normalizeNav(themeConfig?.nav);
|
|
987
838
|
}
|
|
988
839
|
return themeConfig;
|
|
989
840
|
}
|
|
@@ -996,22 +847,20 @@ function deletePrivateField(obj) {
|
|
|
996
847
|
return newObj;
|
|
997
848
|
}
|
|
998
849
|
async function siteDataVMPlugin(context) {
|
|
999
|
-
var _userConfig_themeConfig, _userConfig_multiVersion, _userConfig_multiVersion1, _userConfig_markdown, _userConfig_markdown1, _userConfig_markdown2, _siteData_pages_;
|
|
1000
850
|
const { config, alias, userDocRoot, routeService, pluginDriver } = context;
|
|
1001
851
|
const userConfig = config;
|
|
1002
852
|
const tempSearchObj = Object.assign({}, userConfig.search);
|
|
1003
853
|
if (tempSearchObj) tempSearchObj.searchHooks = void 0;
|
|
1004
854
|
const highlightLanguages = new Set();
|
|
1005
|
-
const replaceRules =
|
|
1006
|
-
const searchConfig =
|
|
1007
|
-
const domain =
|
|
855
|
+
const replaceRules = userConfig?.replaceRules || [];
|
|
856
|
+
const searchConfig = userConfig?.search || {};
|
|
857
|
+
const domain = searchConfig?.mode === 'remote' ? searchConfig.domain ?? '' : '';
|
|
1008
858
|
const searchCodeBlocks = 'codeBlocks' in searchConfig ? Boolean(searchConfig.codeBlocks) : true;
|
|
1009
859
|
const pages = await extractPageData(replaceRules, alias, domain, userDocRoot, routeService, highlightLanguages, searchCodeBlocks);
|
|
1010
860
|
await pluginDriver.modifySearchIndexData(pages);
|
|
1011
861
|
const versioned = userConfig.search && 'remote' !== userConfig.search.mode && userConfig.search.versioned;
|
|
1012
862
|
const groupedPages = (0, __WEBPACK_EXTERNAL_MODULE_lodash_es_18c59938__.groupBy)(pages, (page)=>{
|
|
1013
|
-
|
|
1014
|
-
if ((null === (_page_frontmatter = page.frontmatter) || void 0 === _page_frontmatter ? void 0 : _page_frontmatter.pageType) === 'home') return 'noindex';
|
|
863
|
+
if (page.frontmatter?.pageType === 'home') return 'noindex';
|
|
1015
864
|
const version = versioned ? page.version : '';
|
|
1016
865
|
const lang = page.lang || '';
|
|
1017
866
|
return `${version}###${lang}`;
|
|
@@ -1032,46 +881,46 @@ async function siteDataVMPlugin(context) {
|
|
|
1032
881
|
}));
|
|
1033
882
|
await Promise.all(pages.map(async (pageData)=>pluginDriver.extendPageData(pageData)));
|
|
1034
883
|
const siteData = {
|
|
1035
|
-
title:
|
|
1036
|
-
description:
|
|
1037
|
-
icon:
|
|
1038
|
-
route:
|
|
884
|
+
title: userConfig?.title || '',
|
|
885
|
+
description: userConfig?.description || '',
|
|
886
|
+
icon: userConfig?.icon || '',
|
|
887
|
+
route: userConfig?.route || {},
|
|
1039
888
|
themeConfig: normalizeThemeConfig(userConfig, pages),
|
|
1040
|
-
base:
|
|
1041
|
-
lang:
|
|
1042
|
-
locales:
|
|
1043
|
-
logo:
|
|
1044
|
-
logoText:
|
|
1045
|
-
ssg: Boolean(
|
|
889
|
+
base: userConfig?.base || '/',
|
|
890
|
+
lang: userConfig?.lang || '',
|
|
891
|
+
locales: userConfig?.locales || userConfig.themeConfig?.locales || [],
|
|
892
|
+
logo: userConfig?.logo || '',
|
|
893
|
+
logoText: userConfig?.logoText || '',
|
|
894
|
+
ssg: Boolean(userConfig?.ssg ?? true),
|
|
1046
895
|
multiVersion: {
|
|
1047
|
-
default:
|
|
1048
|
-
versions:
|
|
896
|
+
default: userConfig?.multiVersion?.default || '',
|
|
897
|
+
versions: userConfig?.multiVersion?.versions || []
|
|
1049
898
|
},
|
|
1050
899
|
search: tempSearchObj ?? {
|
|
1051
900
|
mode: 'local'
|
|
1052
901
|
},
|
|
1053
902
|
pages: pages.map((page)=>{
|
|
1054
|
-
const { content, id, domain, _filepath, _html, ...rest } = page;
|
|
903
|
+
const { content, id, domain, _filepath, _html, _flattenContent, ...rest } = page;
|
|
1055
904
|
return isProduction() ? rest : {
|
|
1056
905
|
...rest,
|
|
1057
906
|
_filepath
|
|
1058
907
|
};
|
|
1059
908
|
}),
|
|
1060
909
|
markdown: {
|
|
1061
|
-
showLineNumbers:
|
|
1062
|
-
defaultWrapCode:
|
|
1063
|
-
codeHighlighter:
|
|
910
|
+
showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
|
|
911
|
+
defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
|
|
912
|
+
codeHighlighter: userConfig?.markdown?.codeHighlighter || 'prism'
|
|
1064
913
|
}
|
|
1065
914
|
};
|
|
1066
915
|
const { highlightLanguages: defaultLanguages = [] } = config.markdown || {};
|
|
1067
|
-
if (Array.isArray(
|
|
916
|
+
if (Array.isArray(siteData.pages[0]?.extraHighlightLanguages)) siteData.pages[0].extraHighlightLanguages.forEach((lang)=>highlightLanguages.add(lang));
|
|
1068
917
|
const aliases = handleHighlightLanguages(highlightLanguages, defaultLanguages);
|
|
1069
918
|
const sortedAliases = Object.fromEntries(Object.entries(aliases).sort());
|
|
1070
919
|
const sortedHighlightLanguages = Array.from(highlightLanguages).sort();
|
|
1071
920
|
return {
|
|
1072
|
-
[`${
|
|
1073
|
-
[
|
|
1074
|
-
[
|
|
921
|
+
[`${types_RuntimeModuleID.SiteData}.mjs`]: `export default ${JSON.stringify(siteData, null, 2)}`,
|
|
922
|
+
[types_RuntimeModuleID.SearchIndexHash]: `export default ${JSON.stringify(indexHashByGroup, null, 2)}`,
|
|
923
|
+
[types_RuntimeModuleID.PrismLanguages]: `export const aliases = ${JSON.stringify(sortedAliases, null, 2)};
|
|
1075
924
|
export const languages = {
|
|
1076
925
|
${sortedHighlightLanguages.map((lang)=>`"${lang}": require(
|
|
1077
926
|
"react-syntax-highlighter/dist/cjs/languages/prism/${lang}"
|
|
@@ -1081,10 +930,7 @@ async function siteDataVMPlugin(context) {
|
|
|
1081
930
|
}
|
|
1082
931
|
const runtimeModuleFactory = [
|
|
1083
932
|
routeVMPlugin,
|
|
1084
|
-
siteDataVMPlugin
|
|
1085
|
-
globalUIComponentsVMPlugin,
|
|
1086
|
-
globalStylesVMPlugin,
|
|
1087
|
-
searchHookVMPlugin
|
|
933
|
+
siteDataVMPlugin
|
|
1088
934
|
];
|
|
1089
935
|
function rsbuildPluginDocVM(factoryContext) {
|
|
1090
936
|
const { pluginDriver } = factoryContext;
|
|
@@ -1113,24 +959,54 @@ function rsbuildPluginDocVM(factoryContext) {
|
|
|
1113
959
|
}
|
|
1114
960
|
};
|
|
1115
961
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
962
|
+
const globalStylesVMPlugin = (context)=>({
|
|
963
|
+
[types_RuntimeModuleID.GlobalStyles]: ()=>{
|
|
964
|
+
const { config, pluginDriver } = context;
|
|
965
|
+
const globalStylesByPlugins = pluginDriver.globalStyles();
|
|
966
|
+
const moduleContent = [
|
|
967
|
+
config?.globalStyles,
|
|
968
|
+
...globalStylesByPlugins
|
|
969
|
+
].filter(Boolean).map((source)=>`import ${JSON.stringify(source)};`).join('');
|
|
970
|
+
return moduleContent;
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
const globalUIComponentsVMPlugin = (context)=>({
|
|
974
|
+
[types_RuntimeModuleID.GlobalComponents]: ()=>{
|
|
975
|
+
const { config, pluginDriver } = context;
|
|
976
|
+
let index = 0;
|
|
977
|
+
const globalUIComponentsByPlugins = pluginDriver.globalUIComponents();
|
|
978
|
+
const globalComponents = [
|
|
979
|
+
...config?.globalUIComponents || [],
|
|
980
|
+
...globalUIComponentsByPlugins
|
|
981
|
+
];
|
|
982
|
+
const moduleContent = globalComponents.map((source)=>{
|
|
983
|
+
const name = `Comp_${index}`;
|
|
984
|
+
if (Array.isArray(source)) return `import ${name} from ${JSON.stringify(source[0])};
|
|
985
|
+
const Props_${index++} = ${JSON.stringify(source[1])};\n`;
|
|
986
|
+
index++;
|
|
987
|
+
return `import ${name} from ${JSON.stringify(source)};\n`;
|
|
988
|
+
}).concat(`export default [${Array.from({
|
|
989
|
+
length: index
|
|
990
|
+
}, (_, i)=>{
|
|
991
|
+
if (Array.isArray(globalComponents[i])) return `[Comp_${i}, Props_${i}]`;
|
|
992
|
+
return `Comp_${i}`;
|
|
993
|
+
}).join(', ')}];`).join('');
|
|
994
|
+
return moduleContent;
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
const searchHookVMPlugin = (context)=>({
|
|
998
|
+
[`${types_RuntimeModuleID.SearchHooks}`]: ()=>{
|
|
999
|
+
const { config } = context;
|
|
1000
|
+
let content = 'export const onSearch = () => {};';
|
|
1001
|
+
if ('object' == typeof config.search && 'string' == typeof config.search.searchHooks) content = `export * from '${config.search.searchHooks}'`;
|
|
1002
|
+
return content;
|
|
1003
|
+
}
|
|
1004
|
+
});
|
|
1128
1005
|
async function writeSearchIndex(config) {
|
|
1129
|
-
|
|
1130
|
-
if ((null == config ? void 0 : config.search) === false) return;
|
|
1006
|
+
if (config?.search === false) return;
|
|
1131
1007
|
const cwd = process.cwd();
|
|
1132
1008
|
const searchIndexFiles = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readdir(constants_TEMP_DIR);
|
|
1133
|
-
const outDir =
|
|
1009
|
+
const outDir = config?.outDir ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(cwd, OUTPUT_DIR);
|
|
1134
1010
|
const targetDir = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static');
|
|
1135
1011
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(targetDir, {
|
|
1136
1012
|
recursive: true
|
|
@@ -1146,7 +1022,7 @@ async function writeSearchIndex(config) {
|
|
|
1146
1022
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].rename(source, target);
|
|
1147
1023
|
scanning = true;
|
|
1148
1024
|
}
|
|
1149
|
-
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() &&
|
|
1025
|
+
if (isProduction() && (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isSCM)() && config?.search?.mode === 'remote') {
|
|
1150
1026
|
const { apiUrl, indexName } = config.search;
|
|
1151
1027
|
try {
|
|
1152
1028
|
await fetch(`${apiUrl}?index=${indexName}`, {
|
|
@@ -1164,30 +1040,219 @@ async function writeSearchIndex(config) {
|
|
|
1164
1040
|
}
|
|
1165
1041
|
function serveSearchIndexMiddleware(config) {
|
|
1166
1042
|
return (req, res, next)=>{
|
|
1167
|
-
var _req_url;
|
|
1168
1043
|
const searchIndexRequestMatch = `/${__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.SEARCH_INDEX_NAME}.`;
|
|
1169
|
-
if (
|
|
1044
|
+
if (req.url?.includes(searchIndexRequestMatch)) {
|
|
1170
1045
|
res.setHeader('Content-Type', 'application/json');
|
|
1171
|
-
const outDir =
|
|
1046
|
+
const outDir = config?.outDir ?? (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(process.cwd(), OUTPUT_DIR);
|
|
1172
1047
|
const searchIndexFile = req.url.split('/').pop();
|
|
1173
1048
|
(0, __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.createReadStream)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(outDir, 'static', searchIndexFile), 'utf-8').pipe(res, {
|
|
1174
1049
|
end: true
|
|
1175
1050
|
});
|
|
1176
|
-
} else
|
|
1051
|
+
} else next?.();
|
|
1177
1052
|
};
|
|
1178
1053
|
}
|
|
1054
|
+
async function renderFrontmatterHead(route) {
|
|
1055
|
+
if (!isRouteMeta(route)) return '';
|
|
1056
|
+
const content = await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].readFile(route.absolutePath, {
|
|
1057
|
+
encoding: 'utf-8'
|
|
1058
|
+
});
|
|
1059
|
+
const { frontmatter: { head } } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.loadFrontMatter)(content, route.absolutePath, '', true);
|
|
1060
|
+
if (!head || 0 === head.length) return '';
|
|
1061
|
+
return head.map(([tag, attrs])=>`<${tag} ${renderAttrs(attrs)}>`).join('');
|
|
1062
|
+
}
|
|
1063
|
+
async function renderConfigHead(config, route) {
|
|
1064
|
+
if (!isRouteMeta(route)) return '';
|
|
1065
|
+
if (!config.head || 0 === config.head.length) return '';
|
|
1066
|
+
return config.head.map((head)=>{
|
|
1067
|
+
if ('string' == typeof head) return head;
|
|
1068
|
+
if ('function' == typeof head) {
|
|
1069
|
+
const resultHead = head(route);
|
|
1070
|
+
if (!resultHead) return '';
|
|
1071
|
+
if ('string' == typeof resultHead) return resultHead;
|
|
1072
|
+
return `<${resultHead[0]} ${renderAttrs(resultHead[1])}>`;
|
|
1073
|
+
}
|
|
1074
|
+
return `<${head[0]} ${renderAttrs(head[1])}>`;
|
|
1075
|
+
}).join('');
|
|
1076
|
+
}
|
|
1077
|
+
function renderAttrs(attrs) {
|
|
1078
|
+
return Object.entries(attrs).map(([key, value])=>{
|
|
1079
|
+
if ('boolean' == typeof value) return key;
|
|
1080
|
+
if ('string' == typeof value || 'number' == typeof value) return `${key}="${value}"`;
|
|
1081
|
+
throw new Error(`Invalid value for attribute ${key}:${JSON.stringify(value)}`);
|
|
1082
|
+
}).join('');
|
|
1083
|
+
}
|
|
1084
|
+
function isRouteMeta(route) {
|
|
1085
|
+
return !!route && 'object' == typeof route && 'routePath' in route && 'absolutePath' in route;
|
|
1086
|
+
}
|
|
1087
|
+
async function renderPages(routeService, config, pluginDriver, ssrBundlePath, htmlTemplate, emitAsset) {
|
|
1088
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Rendering pages...');
|
|
1089
|
+
const startTime = Date.now();
|
|
1090
|
+
let render;
|
|
1091
|
+
try {
|
|
1092
|
+
const { default: ssrExports } = await import((0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(ssrBundlePath).toString());
|
|
1093
|
+
({ render } = ssrExports);
|
|
1094
|
+
} catch (e) {
|
|
1095
|
+
if (e instanceof Error) {
|
|
1096
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Failed to load SSG bundle: ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(ssrBundlePath)}: ${e.message}`);
|
|
1097
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
|
|
1098
|
+
hintSSGFailed();
|
|
1099
|
+
}
|
|
1100
|
+
throw e;
|
|
1101
|
+
}
|
|
1102
|
+
try {
|
|
1103
|
+
const routes = routeService.getRoutes();
|
|
1104
|
+
const base = config?.base ?? '';
|
|
1105
|
+
const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route)=>({
|
|
1106
|
+
routePath: (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.withBase)(route.path, base)
|
|
1107
|
+
}));
|
|
1108
|
+
const allRoutes = [
|
|
1109
|
+
...routes,
|
|
1110
|
+
...additionalRoutes
|
|
1111
|
+
];
|
|
1112
|
+
const is404RouteInRoutes = allRoutes.some((route)=>'/404' === route.routePath);
|
|
1113
|
+
if (!is404RouteInRoutes) allRoutes.push({
|
|
1114
|
+
routePath: '/404'
|
|
1115
|
+
});
|
|
1116
|
+
await Promise.all(allRoutes.filter((route)=>!route.routePath.includes(':')).map(async (route)=>{
|
|
1117
|
+
const helmetContext = new __WEBPACK_EXTERNAL_MODULE_react_helmet_async_048d06c6__["default"].HelmetData({});
|
|
1118
|
+
const { routePath } = route;
|
|
1119
|
+
let appHtml = '';
|
|
1120
|
+
if (render) try {
|
|
1121
|
+
({ appHtml } = await render(routePath, helmetContext.context));
|
|
1122
|
+
} catch (e) {
|
|
1123
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Page "${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(routePath)}" SSG rendering failed.`);
|
|
1124
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
|
|
1125
|
+
throw e;
|
|
1126
|
+
}
|
|
1127
|
+
const { helmet } = helmetContext.context;
|
|
1128
|
+
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, [
|
|
1129
|
+
await renderConfigHead(config, route),
|
|
1130
|
+
helmet.title.toString(),
|
|
1131
|
+
helmet.meta.toString(),
|
|
1132
|
+
helmet.link.toString(),
|
|
1133
|
+
helmet.style.toString(),
|
|
1134
|
+
helmet.script.toString(),
|
|
1135
|
+
await renderFrontmatterHead(route)
|
|
1136
|
+
].join(''));
|
|
1137
|
+
if (helmet.htmlAttributes) html = html.replace(HTML_START_TAG, `${HTML_START_TAG} ${helmet.htmlAttributes?.toString()}`);
|
|
1138
|
+
if (helmet.bodyAttributes) html = html.replace(BODY_START_TAG, `${BODY_START_TAG} ${helmet.bodyAttributes?.toString()}`);
|
|
1139
|
+
const normalizeHtmlFilePath = (path)=>{
|
|
1140
|
+
const normalizedBase = `${(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeSlash)(config?.base || '/')}/`;
|
|
1141
|
+
if (path.endsWith('/')) return `${path}index.html`.replace(normalizedBase, '');
|
|
1142
|
+
return `${path}.html`.replace(normalizedBase, '');
|
|
1143
|
+
};
|
|
1144
|
+
const fileName = normalizeHtmlFilePath(routePath);
|
|
1145
|
+
emitAsset(fileName, html);
|
|
1146
|
+
}));
|
|
1147
|
+
const totalTime = Date.now() - startTime;
|
|
1148
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.success(`Pages rendered in ${__WEBPACK_EXTERNAL_MODULE_picocolors__["default"].yellow(totalTime)} ms.`);
|
|
1149
|
+
} catch (e) {
|
|
1150
|
+
if (e instanceof Error) {
|
|
1151
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(`Pages render error: ${e.message}`);
|
|
1152
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.debug(e);
|
|
1153
|
+
hintSSGFailed();
|
|
1154
|
+
}
|
|
1155
|
+
throw e;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
const NODE_SSR_BUNDLE_NAME = 'rspress-ssg-entry.cjs';
|
|
1159
|
+
const rsbuildPluginSSG = ({ routeService, config, pluginDriver })=>({
|
|
1160
|
+
name: 'rspress-inner-rsbuild-plugin-ssg',
|
|
1161
|
+
async setup (api) {
|
|
1162
|
+
api.onBeforeBuild(()=>{
|
|
1163
|
+
let htmlTemplate = '';
|
|
1164
|
+
const indexHtmlEmittedInWeb = new Promise((resolve, reject)=>{
|
|
1165
|
+
api.processAssets({
|
|
1166
|
+
stage: 'report',
|
|
1167
|
+
targets: [
|
|
1168
|
+
'web'
|
|
1169
|
+
]
|
|
1170
|
+
}, ({ assets, compilation })=>{
|
|
1171
|
+
for (const [assetName, assetSource] of Object.entries(assets))if ('index.html' === assetName) {
|
|
1172
|
+
htmlTemplate = assetSource.source().toString();
|
|
1173
|
+
compilation.deleteAsset(assetName);
|
|
1174
|
+
resolve();
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
reject();
|
|
1178
|
+
});
|
|
1179
|
+
}).catch(()=>{
|
|
1180
|
+
const message = 'SSG requires an `index.html` as entry, but this file is not emitted successfully in the web target.';
|
|
1181
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error(message);
|
|
1182
|
+
const error = new Error(message);
|
|
1183
|
+
throw error;
|
|
1184
|
+
});
|
|
1185
|
+
api.processAssets({
|
|
1186
|
+
stage: 'optimize-transfer',
|
|
1187
|
+
targets: [
|
|
1188
|
+
'node'
|
|
1189
|
+
]
|
|
1190
|
+
}, async ({ assets, compilation, environment, compiler })=>{
|
|
1191
|
+
const distPath = environment.distPath;
|
|
1192
|
+
await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.mkdir)(distPath, {
|
|
1193
|
+
recursive: true
|
|
1194
|
+
});
|
|
1195
|
+
let mainCjsAbsolutePath = '';
|
|
1196
|
+
for (const [assetName, assetSource] of Object.entries(assets))if (assetName.includes(NODE_SSR_BUNDLE_NAME)) {
|
|
1197
|
+
mainCjsAbsolutePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, assetName);
|
|
1198
|
+
await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.writeFile)(mainCjsAbsolutePath, assetSource.source().toString());
|
|
1199
|
+
compilation.deleteAsset(assetName);
|
|
1200
|
+
break;
|
|
1201
|
+
}
|
|
1202
|
+
const emitAsset = (assetName, content)=>{
|
|
1203
|
+
compilation.emitAsset(assetName, new compiler.webpack.sources.RawSource(content));
|
|
1204
|
+
};
|
|
1205
|
+
await indexHtmlEmittedInWeb;
|
|
1206
|
+
await renderPages(routeService, config, pluginDriver, mainCjsAbsolutePath, htmlTemplate, emitAsset);
|
|
1207
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isDebugMode)()) await (0, __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__.rm)(mainCjsAbsolutePath);
|
|
1208
|
+
});
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1179
1212
|
const { CachedInputFileSystem: detectReactVersion_CachedInputFileSystem, ResolverFactory: detectReactVersion_ResolverFactory } = __WEBPACK_EXTERNAL_MODULE_enhanced_resolve_bf4706da__["default"];
|
|
1180
|
-
|
|
1181
|
-
async function detectReactVersion() {
|
|
1213
|
+
async function detectPackageMajorVersion(name) {
|
|
1182
1214
|
const cwd = process.cwd();
|
|
1183
|
-
const
|
|
1184
|
-
if (await pathExists(
|
|
1185
|
-
|
|
1186
|
-
const
|
|
1187
|
-
const version = Number(null === (_reactPkg_version = reactPkg.version) || void 0 === _reactPkg_version ? void 0 : _reactPkg_version.split('.')[0]);
|
|
1215
|
+
const pkgPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', name);
|
|
1216
|
+
if (await pathExists(pkgPath)) {
|
|
1217
|
+
const pkgJson = await readJson(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(pkgPath, 'package.json'));
|
|
1218
|
+
const version = Number(pkgJson.version?.split('.')[0]);
|
|
1188
1219
|
return version;
|
|
1189
1220
|
}
|
|
1190
|
-
|
|
1221
|
+
}
|
|
1222
|
+
const DEFAULT_REACT_VERSION = 19;
|
|
1223
|
+
async function detectReactVersion() {
|
|
1224
|
+
return await detectPackageMajorVersion('react') ?? DEFAULT_REACT_VERSION;
|
|
1225
|
+
}
|
|
1226
|
+
async function resolveReactRouterDomAlias() {
|
|
1227
|
+
const alias = {};
|
|
1228
|
+
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1229
|
+
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
1230
|
+
mainFields: [
|
|
1231
|
+
'browser',
|
|
1232
|
+
'module',
|
|
1233
|
+
'main'
|
|
1234
|
+
],
|
|
1235
|
+
extensions: [
|
|
1236
|
+
'.js'
|
|
1237
|
+
],
|
|
1238
|
+
alias
|
|
1239
|
+
});
|
|
1240
|
+
try {
|
|
1241
|
+
const pkgPath = await new Promise((resolve, reject)=>{
|
|
1242
|
+
resolver.resolve({
|
|
1243
|
+
importer: PACKAGE_ROOT
|
|
1244
|
+
}, PACKAGE_ROOT, 'react-router-dom', {}, (err, filePath)=>{
|
|
1245
|
+
if (err || !filePath) return reject(err);
|
|
1246
|
+
return resolve(filePath);
|
|
1247
|
+
});
|
|
1248
|
+
});
|
|
1249
|
+
return {
|
|
1250
|
+
'react-router-dom': pkgPath
|
|
1251
|
+
};
|
|
1252
|
+
} catch (e) {
|
|
1253
|
+
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.warn('react-router-dom not found: \n', e);
|
|
1254
|
+
}
|
|
1255
|
+
return {};
|
|
1191
1256
|
}
|
|
1192
1257
|
async function resolveReactAlias(reactVersion, isSSR) {
|
|
1193
1258
|
const basedir = reactVersion === DEFAULT_REACT_VERSION ? PACKAGE_ROOT : process.cwd();
|
|
@@ -1198,7 +1263,7 @@ async function resolveReactAlias(reactVersion, isSSR) {
|
|
|
1198
1263
|
'react-dom',
|
|
1199
1264
|
'react-dom/server'
|
|
1200
1265
|
];
|
|
1201
|
-
if (reactVersion >=
|
|
1266
|
+
if (reactVersion >= 18) libPaths.push('react-dom/client');
|
|
1202
1267
|
const alias = {};
|
|
1203
1268
|
const resolver = detectReactVersion_ResolverFactory.createResolver({
|
|
1204
1269
|
fileSystem: new detectReactVersion_CachedInputFileSystem(__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"], 0),
|
|
@@ -1272,19 +1337,15 @@ function getSocialIcons(socialLinks = []) {
|
|
|
1272
1337
|
return icons;
|
|
1273
1338
|
}
|
|
1274
1339
|
function isPluginIncluded(config, pluginName) {
|
|
1275
|
-
|
|
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)));
|
|
1340
|
+
return Boolean(config.builderPlugins?.some((plugin)=>plugin.name === pluginName) || config.builderConfig?.plugins?.some((plugin)=>plugin && plugin.name === pluginName));
|
|
1277
1341
|
}
|
|
1278
1342
|
async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir) {
|
|
1279
|
-
var _config_builderConfig_output, _config_builderConfig, _config_themeConfig, _config_themeConfig1;
|
|
1280
1343
|
const cwd = process.cwd();
|
|
1281
|
-
const CUSTOM_THEME_DIR =
|
|
1282
|
-
const
|
|
1283
|
-
const csrOutDir = baseOutDir;
|
|
1284
|
-
const ssrOutDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(baseOutDir, 'ssr');
|
|
1344
|
+
const CUSTOM_THEME_DIR = config?.themeDir ?? __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(process.cwd(), 'theme');
|
|
1345
|
+
const outDir = config?.outDir ?? OUTPUT_DIR;
|
|
1285
1346
|
const DEFAULT_THEME = require.resolve('@rspress/theme-default');
|
|
1286
|
-
const base =
|
|
1287
|
-
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(
|
|
1347
|
+
const base = config?.base ?? '';
|
|
1348
|
+
const assetPrefix = isProduction() ? (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.removeTrailingSlash)(config?.builderConfig?.output?.assetPrefix ?? base) : '';
|
|
1288
1349
|
const reactVersion = await detectReactVersion();
|
|
1289
1350
|
const normalizeIcon = (icon)=>{
|
|
1290
1351
|
if (!icon) return;
|
|
@@ -1292,10 +1353,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1292
1353
|
return icon;
|
|
1293
1354
|
};
|
|
1294
1355
|
await hintThemeBreakingChange(CUSTOM_THEME_DIR);
|
|
1295
|
-
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias] = await Promise.all([
|
|
1356
|
+
const [detectCustomIconAlias, reactCSRAlias, reactSSRAlias, reactRouterDomAlias] = await Promise.all([
|
|
1296
1357
|
detectCustomIcon(CUSTOM_THEME_DIR),
|
|
1297
1358
|
resolveReactAlias(reactVersion, false),
|
|
1298
|
-
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({})
|
|
1359
|
+
enableSSG ? resolveReactAlias(reactVersion, true) : Promise.resolve({}),
|
|
1360
|
+
resolveReactRouterDomAlias()
|
|
1299
1361
|
]);
|
|
1300
1362
|
const context = {
|
|
1301
1363
|
userDocRoot,
|
|
@@ -1312,9 +1374,19 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1312
1374
|
rsbuildPluginDocVM(context),
|
|
1313
1375
|
pluginVirtualModule({
|
|
1314
1376
|
virtualModules: {
|
|
1315
|
-
...i18nVMPlugin(context)
|
|
1377
|
+
...i18nVMPlugin(context),
|
|
1378
|
+
...globalUIComponentsVMPlugin(context),
|
|
1379
|
+
...globalStylesVMPlugin(context),
|
|
1380
|
+
...searchHookVMPlugin(context)
|
|
1316
1381
|
}
|
|
1317
|
-
})
|
|
1382
|
+
}),
|
|
1383
|
+
...enableSSG ? [
|
|
1384
|
+
rsbuildPluginSSG({
|
|
1385
|
+
routeService,
|
|
1386
|
+
config,
|
|
1387
|
+
pluginDriver
|
|
1388
|
+
})
|
|
1389
|
+
] : []
|
|
1318
1390
|
],
|
|
1319
1391
|
server: {
|
|
1320
1392
|
port: !isProduction() && process.env.PORT ? Number(process.env.PORT) : void 0,
|
|
@@ -1335,11 +1407,11 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1335
1407
|
}
|
|
1336
1408
|
},
|
|
1337
1409
|
html: {
|
|
1338
|
-
title:
|
|
1339
|
-
favicon: normalizeIcon(
|
|
1340
|
-
template:
|
|
1410
|
+
title: config?.title ?? DEFAULT_TITLE,
|
|
1411
|
+
favicon: normalizeIcon(config?.icon),
|
|
1412
|
+
template: TEMPLATE_PATH,
|
|
1341
1413
|
tags: [
|
|
1342
|
-
|
|
1414
|
+
config.themeConfig?.darkMode !== false ? {
|
|
1343
1415
|
tag: "script",
|
|
1344
1416
|
children: inlineThemeScript,
|
|
1345
1417
|
append: false
|
|
@@ -1349,7 +1421,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1349
1421
|
output: {
|
|
1350
1422
|
assetPrefix,
|
|
1351
1423
|
distPath: {
|
|
1352
|
-
root:
|
|
1424
|
+
root: outDir
|
|
1353
1425
|
}
|
|
1354
1426
|
},
|
|
1355
1427
|
resolve: {
|
|
@@ -1374,7 +1446,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1374
1446
|
define: {
|
|
1375
1447
|
'process.env.__REACT_GTE_18__': JSON.stringify(reactVersion >= 18),
|
|
1376
1448
|
'process.env.TEST': JSON.stringify(process.env.TEST),
|
|
1377
|
-
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(
|
|
1449
|
+
'process.env.RSPRESS_SOCIAL_ICONS': JSON.stringify(getSocialIcons(config.themeConfig?.socialLinks))
|
|
1378
1450
|
}
|
|
1379
1451
|
},
|
|
1380
1452
|
performance: {
|
|
@@ -1394,11 +1466,10 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1394
1466
|
},
|
|
1395
1467
|
tools: {
|
|
1396
1468
|
bundlerChain (chain, { CHAIN_ID, target }) {
|
|
1397
|
-
var _config_markdown;
|
|
1398
1469
|
const isServer = 'node' === target;
|
|
1399
1470
|
const jsModuleRule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
1400
1471
|
const swcLoaderOptions = jsModuleRule.use(CHAIN_ID.USE.SWC).get('options');
|
|
1401
|
-
const checkDeadLinks = (
|
|
1472
|
+
const checkDeadLinks = (config?.markdown?.checkDeadLinks && !isServer) ?? false;
|
|
1402
1473
|
chain.module.rule('MDX').type("javascript/auto").test(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.MDX_OR_MD_REGEXP).resolve.merge({
|
|
1403
1474
|
conditionNames: jsModuleRule.resolve.conditionNames.values(),
|
|
1404
1475
|
mainFields: jsModuleRule.resolve.mainFields.values()
|
|
@@ -1421,7 +1492,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1421
1492
|
chain.module.rule('css-virtual-module').test(/\.rspress[\\/]runtime[\\/]virtual-global-styles/).merge({
|
|
1422
1493
|
sideEffects: true
|
|
1423
1494
|
});
|
|
1424
|
-
if (isServer) chain.output.filename(
|
|
1495
|
+
if (isServer) chain.output.filename(NODE_SSR_BUNDLE_NAME);
|
|
1425
1496
|
const enableIncremental = !isProduction() && !process.env.DISABLE_RSPACK_INCREMENTAL;
|
|
1426
1497
|
if (enableIncremental) chain.merge({
|
|
1427
1498
|
experiments: {
|
|
@@ -1435,12 +1506,13 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1435
1506
|
resolve: {
|
|
1436
1507
|
alias: {
|
|
1437
1508
|
...reactCSRAlias,
|
|
1509
|
+
...reactRouterDomAlias,
|
|
1438
1510
|
__VIRTUAL_ROUTES__: 'virtual-routes'
|
|
1439
1511
|
}
|
|
1440
1512
|
},
|
|
1441
1513
|
source: {
|
|
1442
1514
|
entry: {
|
|
1443
|
-
index:
|
|
1515
|
+
index: enableSSG && isProduction() ? SSR_CLIENT_ENTRY : CSR_CLIENT_ENTRY
|
|
1444
1516
|
},
|
|
1445
1517
|
define: {
|
|
1446
1518
|
'process.env.__SSR__': JSON.stringify(false)
|
|
@@ -1449,7 +1521,7 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1449
1521
|
output: {
|
|
1450
1522
|
target: 'web',
|
|
1451
1523
|
distPath: {
|
|
1452
|
-
root:
|
|
1524
|
+
root: outDir
|
|
1453
1525
|
}
|
|
1454
1526
|
}
|
|
1455
1527
|
},
|
|
@@ -1458,26 +1530,33 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1458
1530
|
resolve: {
|
|
1459
1531
|
alias: {
|
|
1460
1532
|
...reactSSRAlias,
|
|
1533
|
+
...reactRouterDomAlias,
|
|
1461
1534
|
__VIRTUAL_ROUTES__: 'virtual-routes-ssr'
|
|
1462
1535
|
}
|
|
1463
1536
|
},
|
|
1537
|
+
tools: {
|
|
1538
|
+
rspack: {
|
|
1539
|
+
output: {
|
|
1540
|
+
asyncChunks: false
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1464
1544
|
source: {
|
|
1465
1545
|
entry: {
|
|
1466
|
-
index:
|
|
1546
|
+
index: SSR_SERVER_ENTRY
|
|
1467
1547
|
},
|
|
1468
1548
|
define: {
|
|
1469
1549
|
'process.env.__SSR__': JSON.stringify(true)
|
|
1470
1550
|
}
|
|
1471
1551
|
},
|
|
1472
1552
|
performance: {
|
|
1473
|
-
printFileSize:
|
|
1553
|
+
printFileSize: {
|
|
1554
|
+
compressed: true
|
|
1555
|
+
}
|
|
1474
1556
|
},
|
|
1475
1557
|
output: {
|
|
1476
1558
|
emitAssets: false,
|
|
1477
1559
|
target: 'node',
|
|
1478
|
-
distPath: {
|
|
1479
|
-
root: ssrOutDir
|
|
1480
|
-
},
|
|
1481
1560
|
minify: false
|
|
1482
1561
|
}
|
|
1483
1562
|
}
|
|
@@ -1486,10 +1565,9 @@ async function createInternalBuildConfig(userDocRoot, config, enableSSG, routeSe
|
|
|
1486
1565
|
};
|
|
1487
1566
|
}
|
|
1488
1567
|
async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuildConfig) {
|
|
1489
|
-
var _pluginDriver_getPlugins;
|
|
1490
1568
|
const cwd = process.cwd();
|
|
1491
|
-
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir ||
|
|
1492
|
-
const builderPlugins =
|
|
1569
|
+
const userDocRoot = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(rootDir || config?.root || cwd);
|
|
1570
|
+
const builderPlugins = config?.builderPlugins ?? [];
|
|
1493
1571
|
const runtimeTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.RSPRESS_TEMP_DIR, 'runtime');
|
|
1494
1572
|
const runtimeAbsTempDir = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(cwd, 'node_modules', runtimeTempDir);
|
|
1495
1573
|
await __WEBPACK_EXTERNAL_MODULE_node_fs_promises_153e37e0__["default"].mkdir(runtimeAbsTempDir, {
|
|
@@ -1504,7 +1582,7 @@ async function initRsbuild(rootDir, config, pluginDriver, enableSSG, extraRsbuil
|
|
|
1504
1582
|
const { createRsbuild, mergeRsbuildConfig } = await import("@rsbuild/core");
|
|
1505
1583
|
const internalRsbuildConfig = await createInternalBuildConfig(userDocRoot, config, enableSSG, routeService, pluginDriver, runtimeTempDir);
|
|
1506
1584
|
const rsbuild = await createRsbuild({
|
|
1507
|
-
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...
|
|
1585
|
+
rsbuildConfig: mergeRsbuildConfig(internalRsbuildConfig, ...pluginDriver.getPlugins()?.map((plugin)=>plugin.builderConfig ?? {}) || [], config?.builderConfig || {}, extraRsbuildConfig || {})
|
|
1508
1586
|
});
|
|
1509
1587
|
rsbuild.addPlugins(builderPlugins);
|
|
1510
1588
|
return rsbuild;
|
|
@@ -1553,19 +1631,15 @@ async function collectModuleFiles(contentPath, lang, includedDir, excludedDirs,
|
|
|
1553
1631
|
return fileLangMap;
|
|
1554
1632
|
}
|
|
1555
1633
|
async function checkLanguageParity(config) {
|
|
1556
|
-
|
|
1557
|
-
if (!(null == config ? void 0 : config.languageParity) || false === config.languageParity.enabled) return;
|
|
1634
|
+
if (!config?.languageParity || false === config.languageParity.enabled) return;
|
|
1558
1635
|
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.info('Checking language parity...');
|
|
1559
1636
|
const contentPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(config.root);
|
|
1560
|
-
const includedDirs =
|
|
1637
|
+
const includedDirs = config.languageParity.include?.length ? config.languageParity.include : [
|
|
1561
1638
|
''
|
|
1562
1639
|
];
|
|
1563
1640
|
const excludedDirs = config.languageParity.exclude ?? [];
|
|
1564
|
-
const supportedLanguages = (
|
|
1565
|
-
if (!supportedLanguages.length)
|
|
1566
|
-
__WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1567
|
-
return;
|
|
1568
|
-
}
|
|
1641
|
+
const supportedLanguages = (config.locales ?? config.themeConfig?.locales)?.map((locale)=>locale.lang) || [];
|
|
1642
|
+
if (!supportedLanguages.length) return void __WEBPACK_EXTERNAL_MODULE__rspress_shared_logger_4374e44a__.logger.error('No supported languages found in the configuration.');
|
|
1569
1643
|
const missingLanguagesFile = [];
|
|
1570
1644
|
try {
|
|
1571
1645
|
for (const includedDir of includedDirs){
|
|
@@ -1595,11 +1669,11 @@ async function dev(options) {
|
|
|
1595
1669
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1596
1670
|
try {
|
|
1597
1671
|
await pluginDriver.beforeBuild();
|
|
1598
|
-
const
|
|
1599
|
-
|
|
1672
|
+
const rsbuild = await initRsbuild(docDirectory, modifiedConfig, pluginDriver, false, extraBuilderConfig);
|
|
1673
|
+
rsbuild.onDevCompileDone(async ()=>{
|
|
1600
1674
|
await pluginDriver.afterBuild();
|
|
1601
1675
|
});
|
|
1602
|
-
const { server } = await
|
|
1676
|
+
const { server } = await rsbuild.startDevServer({
|
|
1603
1677
|
getPortSilently: true
|
|
1604
1678
|
});
|
|
1605
1679
|
return server;
|
|
@@ -1608,43 +1682,6 @@ async function dev(options) {
|
|
|
1608
1682
|
await checkLanguageParity(modifiedConfig);
|
|
1609
1683
|
}
|
|
1610
1684
|
}
|
|
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
1685
|
async function bundle(docDirectory, config, pluginDriver, enableSSG) {
|
|
1649
1686
|
try {
|
|
1650
1687
|
const rsbuild = await initRsbuild(docDirectory, config, pluginDriver, enableSSG);
|
|
@@ -1660,111 +1697,25 @@ function emptyDir(path) {
|
|
|
1660
1697
|
recursive: true
|
|
1661
1698
|
});
|
|
1662
1699
|
}
|
|
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
1700
|
async function build(options) {
|
|
1749
|
-
const { docDirectory,
|
|
1701
|
+
const { docDirectory, config } = options;
|
|
1750
1702
|
const pluginDriver = new PluginDriver(config, true);
|
|
1751
1703
|
await pluginDriver.init();
|
|
1752
1704
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1753
1705
|
await pluginDriver.beforeBuild();
|
|
1754
1706
|
const ssgConfig = modifiedConfig.ssg ?? true;
|
|
1755
1707
|
await emptyDir(constants_TEMP_DIR);
|
|
1756
|
-
await bundle(docDirectory, modifiedConfig, pluginDriver,
|
|
1757
|
-
|
|
1708
|
+
await bundle(docDirectory, modifiedConfig, pluginDriver, ssgConfig);
|
|
1709
|
+
if (!ssgConfig) hintSSGFalse();
|
|
1758
1710
|
await pluginDriver.afterBuild();
|
|
1759
1711
|
}
|
|
1760
1712
|
async function serve(options) {
|
|
1761
|
-
var _builderConfig_server, _builderConfig_server1;
|
|
1762
1713
|
const { config, port: userPort, host: userHost } = options;
|
|
1763
1714
|
const envPort = process.env.PORT;
|
|
1764
1715
|
const envHost = process.env.HOST;
|
|
1765
1716
|
const { builderConfig } = config;
|
|
1766
|
-
const port = Number(envPort || userPort ||
|
|
1767
|
-
const host = envHost || userHost ||
|
|
1717
|
+
const port = Number(envPort || userPort || builderConfig?.server?.port || 4173);
|
|
1718
|
+
const host = envHost || userHost || builderConfig?.server?.host || 'localhost';
|
|
1768
1719
|
config.builderConfig = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__.mergeRsbuildConfig)(builderConfig, {
|
|
1769
1720
|
server: {
|
|
1770
1721
|
port,
|
|
@@ -1774,8 +1725,127 @@ async function serve(options) {
|
|
|
1774
1725
|
const pluginDriver = new PluginDriver(config, true);
|
|
1775
1726
|
await pluginDriver.init();
|
|
1776
1727
|
const modifiedConfig = await pluginDriver.modifyConfig();
|
|
1777
|
-
const
|
|
1778
|
-
return
|
|
1728
|
+
const rsbuild = await initRsbuild(config.root, modifiedConfig, pluginDriver, false);
|
|
1729
|
+
return rsbuild.preview();
|
|
1730
|
+
}
|
|
1731
|
+
const getASTNodeImport = (name, from)=>({
|
|
1732
|
+
type: 'mdxjsEsm',
|
|
1733
|
+
value: `import ${name} from ${JSON.stringify(from)}`,
|
|
1734
|
+
data: {
|
|
1735
|
+
estree: {
|
|
1736
|
+
type: 'Program',
|
|
1737
|
+
sourceType: 'module',
|
|
1738
|
+
body: [
|
|
1739
|
+
{
|
|
1740
|
+
type: 'ImportDeclaration',
|
|
1741
|
+
specifiers: [
|
|
1742
|
+
{
|
|
1743
|
+
type: 'ImportDefaultSpecifier',
|
|
1744
|
+
local: {
|
|
1745
|
+
type: 'Identifier',
|
|
1746
|
+
name
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
],
|
|
1750
|
+
source: {
|
|
1751
|
+
type: 'Literal',
|
|
1752
|
+
value: from,
|
|
1753
|
+
raw: `${JSON.stringify(from)}`
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
]
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
function normalizeLink(nodeUrl, routeService, relativePath, cleanUrls) {
|
|
1761
|
+
if (!nodeUrl) return '';
|
|
1762
|
+
if (nodeUrl.startsWith('#')) return `#${nodeUrl.slice(1)}`;
|
|
1763
|
+
let { url, hash } = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.parseUrl)(nodeUrl);
|
|
1764
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(url)) return url + (hash ? `#${hash}` : '');
|
|
1765
|
+
const extname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(url);
|
|
1766
|
+
if ((routeService?.extensions ?? __WEBPACK_EXTERNAL_MODULE__rspress_shared_constants_70084e62__.DEFAULT_PAGE_EXTENSIONS).includes(extname)) url = url.replace(new RegExp(`\\${extname}$`), '');
|
|
1767
|
+
if (url.startsWith('.')) url = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].posix.join((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(relativePath)), url);
|
|
1768
|
+
else if (routeService) {
|
|
1769
|
+
const [pathVersion, pathLang] = routeService.getRoutePathParts((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.slash)(relativePath));
|
|
1770
|
+
const [urlVersion, urlLang, urlPath] = routeService.getRoutePathParts(url);
|
|
1771
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.addLeadingSlash)(urlPath);
|
|
1772
|
+
if (pathLang && urlLang !== pathLang) url = `/${pathLang}${url}`;
|
|
1773
|
+
if (pathVersion && urlVersion !== pathVersion) url = `/${pathVersion}${url}`;
|
|
1774
|
+
}
|
|
1775
|
+
if ('boolean' == typeof cleanUrls) url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, cleanUrls);
|
|
1776
|
+
else {
|
|
1777
|
+
url = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.normalizeHref)(url, false);
|
|
1778
|
+
url = url.replace(/\.html$/, cleanUrls);
|
|
1779
|
+
}
|
|
1780
|
+
if (hash) url += `#${hash}`;
|
|
1781
|
+
return url;
|
|
1779
1782
|
}
|
|
1783
|
+
const normalizeImageUrl = (imageUrl)=>{
|
|
1784
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_baa012d0__.isExternalUrl)(imageUrl) || imageUrl.startsWith('/')) return '';
|
|
1785
|
+
return imageUrl;
|
|
1786
|
+
};
|
|
1787
|
+
const remarkPluginNormalizeLink = ({ root, cleanUrls, routeService })=>(tree, file)=>{
|
|
1788
|
+
const images = [];
|
|
1789
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'link', (node)=>{
|
|
1790
|
+
const { url: nodeUrl } = node;
|
|
1791
|
+
const relativePath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].relative(root, file.path);
|
|
1792
|
+
node.url = normalizeLink(nodeUrl, routeService, relativePath, cleanUrls);
|
|
1793
|
+
});
|
|
1794
|
+
const getMdxSrcAttribute = (tempVar)=>({
|
|
1795
|
+
type: 'mdxJsxAttribute',
|
|
1796
|
+
name: 'src',
|
|
1797
|
+
value: {
|
|
1798
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
1799
|
+
value: tempVar,
|
|
1800
|
+
data: {
|
|
1801
|
+
estree: {
|
|
1802
|
+
type: 'Program',
|
|
1803
|
+
sourceType: 'module',
|
|
1804
|
+
body: [
|
|
1805
|
+
{
|
|
1806
|
+
type: 'ExpressionStatement',
|
|
1807
|
+
expression: {
|
|
1808
|
+
type: 'Identifier',
|
|
1809
|
+
name: tempVar
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
]
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
});
|
|
1817
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, 'image', (node)=>{
|
|
1818
|
+
const { alt, url } = node;
|
|
1819
|
+
if (!url) return;
|
|
1820
|
+
const imagePath = normalizeImageUrl(url);
|
|
1821
|
+
if (!imagePath) return;
|
|
1822
|
+
const tempVariableName = `image${images.length}`;
|
|
1823
|
+
Object.assign(node, {
|
|
1824
|
+
type: 'mdxJsxFlowElement',
|
|
1825
|
+
name: 'img',
|
|
1826
|
+
children: [],
|
|
1827
|
+
attributes: [
|
|
1828
|
+
alt && {
|
|
1829
|
+
type: 'mdxJsxAttribute',
|
|
1830
|
+
name: 'alt',
|
|
1831
|
+
value: alt
|
|
1832
|
+
},
|
|
1833
|
+
getMdxSrcAttribute(tempVariableName)
|
|
1834
|
+
].filter(Boolean)
|
|
1835
|
+
});
|
|
1836
|
+
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
1837
|
+
});
|
|
1838
|
+
(0, __WEBPACK_EXTERNAL_MODULE_unist_util_visit_555e002a__.visit)(tree, (node)=>{
|
|
1839
|
+
if ('mdxJsxFlowElement' !== node.type && 'mdxJsxTextElement' !== node.type || 'img' !== node.name) return;
|
|
1840
|
+
const srcAttr = (0, __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.getNodeAttribute)(node, 'src', true);
|
|
1841
|
+
if ('string' != typeof srcAttr?.value) return;
|
|
1842
|
+
const imagePath = normalizeImageUrl(srcAttr.value);
|
|
1843
|
+
if (!imagePath) return;
|
|
1844
|
+
const tempVariableName = `image${images.length}`;
|
|
1845
|
+
Object.assign(srcAttr, getMdxSrcAttribute(tempVariableName));
|
|
1846
|
+
images.push(getASTNodeImport(tempVariableName, imagePath));
|
|
1847
|
+
});
|
|
1848
|
+
tree.children.unshift(...images);
|
|
1849
|
+
};
|
|
1780
1850
|
var __webpack_exports__mergeDocConfig = __WEBPACK_EXTERNAL_MODULE__rspress_shared_node_utils_78947ce6__.mergeDocConfig;
|
|
1781
|
-
export { build, dev, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|
|
1851
|
+
export { build, dev, remarkPluginNormalizeLink, serve, __webpack_exports__mergeDocConfig as mergeDocConfig };
|