@rspress/core 1.6.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4323,7 +4323,8 @@ async function siteDataVMPlugin(context) {
4323
4323
  }),
4324
4324
  markdown: {
4325
4325
  showLineNumbers: userConfig?.markdown?.showLineNumbers ?? false,
4326
- defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false
4326
+ defaultWrapCode: userConfig?.markdown?.defaultWrapCode ?? false,
4327
+ codeHighlighter: userConfig?.markdown?.codeHighlighter || "prism"
4327
4328
  }
4328
4329
  };
4329
4330
  return {
@@ -4406,27 +4407,12 @@ async function searchHookVMPlugin(context) {
4406
4407
 
4407
4408
  // src/node/runtimeModule/prismLanguages.ts
4408
4409
  import { uniqBy } from "lodash-es";
4409
- var DEFAULT_LANGUAGES = [
4410
- ["js", "javascript"],
4411
- ["ts", "typescript"],
4412
- ["jsx", "tsx"],
4413
- "tsx",
4414
- "json",
4415
- "css",
4416
- "scss",
4417
- "less",
4418
- ["xml", "xml-doc"],
4419
- "diff",
4420
- "yaml",
4421
- ["md", "markdown"],
4422
- ["mdx", "tsx"],
4423
- "bash"
4424
- ];
4410
+ import { DEFAULT_HIGHLIGHT_LANGUAGES } from "@rspress/shared";
4425
4411
  async function prismLanguageVMPlugin(context) {
4426
4412
  const { config } = context;
4427
4413
  const { highlightLanguages = [] } = config.markdown || {};
4428
4414
  const languageMeta = uniqBy(
4429
- [...DEFAULT_LANGUAGES, ...highlightLanguages].map((language) => {
4415
+ [...DEFAULT_HIGHLIGHT_LANGUAGES, ...highlightLanguages].map((language) => {
4430
4416
  const [alias, name] = Array.isArray(language) ? language : [language, language];
4431
4417
  return { alias, name };
4432
4418
  }),
@@ -4756,7 +4742,7 @@ var RouteService = class {
4756
4742
  import React from 'react';
4757
4743
  import { lazyWithPreload } from "react-lazy-with-preload";
4758
4744
  ${routeMeta.map((route, index) => {
4759
- return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import(/* webpackChunkName: "${route.pageName}" */'${route.absolutePath}'))`;
4745
+ return isStaticImport ? `import * as Route${index} from '${route.absolutePath}';` : `const Route${index} = lazyWithPreload(() => import('${route.absolutePath}'))`;
4760
4746
  }).join("\n")}
4761
4747
  export const routes = [
4762
4748
  ${routeMeta.map((route, index) => {
@@ -4857,18 +4843,29 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4857
4843
  return {
4858
4844
  dev: {
4859
4845
  port: process.env.PORT ? Number(process.env.PORT) : void 0,
4860
- progressBar: false
4846
+ progressBar: false,
4847
+ // Serve static files
4848
+ setupMiddlewares: [
4849
+ (middlewares) => {
4850
+ if (isPublicDirExist) {
4851
+ middlewares.push(sirv(publicDir));
4852
+ }
4853
+ middlewares.push(serveSearchIndexMiddleware(config));
4854
+ }
4855
+ ],
4856
+ historyApiFallback: {
4857
+ // not support fallback the requested path which contain a . (DOT) character by default
4858
+ rewrites: [{ from: /.*\.html/, to: "/" }]
4859
+ }
4861
4860
  },
4862
4861
  html: {
4863
4862
  favicon: normalizeIcon(config?.icon),
4864
- template: path10.join(PACKAGE_ROOT, "index.html"),
4865
- outputStructure: "nested"
4863
+ template: path10.join(PACKAGE_ROOT, "index.html")
4866
4864
  },
4867
4865
  output: {
4868
4866
  distPath: {
4869
4867
  // `root` must be a relative path in Rsbuild
4870
- root: path10.isAbsolute(outDir) ? path10.relative(cwd, outDir) : outDir,
4871
- html: "html"
4868
+ root: path10.isAbsolute(outDir) ? path10.relative(cwd, outDir) : outDir
4872
4869
  },
4873
4870
  // Disable production source map, it is useless for doc site
4874
4871
  disableSourceMap: isProduction(),
@@ -4876,6 +4873,9 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4876
4873
  assetPrefix
4877
4874
  },
4878
4875
  source: {
4876
+ entry: {
4877
+ index: isSSR ? SSR_ENTRY : CLIENT_ENTRY
4878
+ },
4879
4879
  alias: {
4880
4880
  "@mdx-js/react": __require.resolve("@mdx-js/react"),
4881
4881
  "@theme": themeDir,
@@ -4887,11 +4887,7 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4887
4887
  ),
4888
4888
  ...await resolveReactAlias(reactVersion)
4889
4889
  },
4890
- include: [
4891
- PACKAGE_ROOT,
4892
- path10.join(cwd, "node_modules", RSPRESS_TEMP_DIR2),
4893
- /(.*?)\.tsx?$/
4894
- ],
4890
+ include: [PACKAGE_ROOT, path10.join(cwd, "node_modules", RSPRESS_TEMP_DIR2)],
4895
4891
  define: {
4896
4892
  "process.env.__ASSET_PREFIX__": JSON.stringify(assetPrefix),
4897
4893
  "process.env.__SSR__": JSON.stringify(isSSR),
@@ -4904,14 +4900,6 @@ async function createInternalBuildConfig(userDocRoot, config, isSSR, routeServic
4904
4900
  printFileSize: !isSSR
4905
4901
  },
4906
4902
  tools: {
4907
- devServer: {
4908
- // Serve static files
4909
- after: [
4910
- ...isPublicDirExist ? [sirv(publicDir)] : [],
4911
- serveSearchIndexMiddleware(config)
4912
- ],
4913
- historyApiFallback: true
4914
- },
4915
4903
  postcss(config2) {
4916
4904
  if (isDebugMode()) {
4917
4905
  config2.postcssOptions.plugins.push(
@@ -4977,9 +4965,6 @@ async function initRsbuild(rootDir, config, pluginDriver, isSSR = false, extraRs
4977
4965
  );
4978
4966
  const rsbuild = await createRsbuild({
4979
4967
  target: isSSR ? "node" : "web",
4980
- entry: {
4981
- main: isSSR ? SSR_ENTRY : CLIENT_ENTRY
4982
- },
4983
4968
  rsbuildConfig: mergeRsbuildConfig(
4984
4969
  internalRsbuildConfig,
4985
4970
  ...config?.plugins?.map((plugin) => plugin.builderConfig ?? {}) || [],
@@ -5216,7 +5201,8 @@ import fs10 from "@modern-js/utils/fs-extra";
5216
5201
  import {
5217
5202
  APPEARANCE_KEY,
5218
5203
  normalizeSlash,
5219
- withBase as withBase3
5204
+ withBase as withBase3,
5205
+ isDebugMode as isDebugMode2
5220
5206
  } from "@rspress/shared";
5221
5207
  import { logger as logger5 } from "@rspress/shared/logger";
5222
5208
  var CHECK_DARK_LIGHT_SCRIPT = `
@@ -5241,6 +5227,11 @@ async function bundle(docDirectory, config, pluginDriver, enableSSG) {
5241
5227
  distPath: {
5242
5228
  root: `${outputDir}/ssr`
5243
5229
  }
5230
+ },
5231
+ tools: {
5232
+ rspack(options2) {
5233
+ options2.output.filename = "main.cjs";
5234
+ }
5244
5235
  }
5245
5236
  })
5246
5237
  ]);
@@ -5266,7 +5257,7 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5266
5257
  logger5.info("Rendering pages...");
5267
5258
  const startTime = Date.now();
5268
5259
  const outputPath = config?.outDir ?? join3(appDirectory, OUTPUT_DIR);
5269
- const ssrBundlePath = join3(outputPath, "ssr", "bundles", "main.js");
5260
+ const ssrBundlePath = join3(outputPath, "ssr", "main.cjs");
5270
5261
  try {
5271
5262
  const { default: fs11 } = await import("@modern-js/utils/fs-extra");
5272
5263
  let render = null;
@@ -5283,7 +5274,7 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5283
5274
  }
5284
5275
  const routes = routeService.getRoutes();
5285
5276
  const base = config?.base ?? "";
5286
- const htmlTemplatePath = join3(outputPath, "html", "main", "index.html");
5277
+ const htmlTemplatePath = join3(outputPath, "index.html");
5287
5278
  const htmlTemplate = await fs11.readFile(htmlTemplatePath, "utf-8");
5288
5279
  const additionalRoutes = (await pluginDriver.addSSGRoutes()).map((route) => ({
5289
5280
  routePath: withBase3(route.path, base)
@@ -5342,7 +5333,9 @@ async function renderPages(appDirectory, config, pluginDriver, enableSSG) {
5342
5333
  await fs11.writeFile(join3(outputPath, fileName), html);
5343
5334
  })
5344
5335
  );
5345
- await fs11.remove(join3(outputPath, "ssr"));
5336
+ if (!isDebugMode2()) {
5337
+ await fs11.remove(join3(outputPath, "ssr"));
5338
+ }
5346
5339
  await fs11.remove(join3(outputPath, "html"));
5347
5340
  const totalTime = Date.now() - startTime;
5348
5341
  logger5.success(`Pages rendered in ${chalk2.yellow(totalTime)} ms.`);