Skip to content

Commit 755bbe7

Browse files
authored
build(core): use Rslib to build the package (#1831)
1 parent f42bd1f commit 755bbe7

File tree

16 files changed

+124
-200
lines changed

16 files changed

+124
-200
lines changed

e2e/fixtures/modern-js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@arco-design/web-react": "^2.65.0"
2626
},
2727
"devDependencies": {
28+
"@modern-js/module-tools": "2.64.0",
2829
"@rspress/modern-js-plugin": "workspace:*",
2930
"@types/node": "^18.11.17",
3031
"@types/react": "^18.3.18",

nx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"{projectRoot}/src/**/*",
1414
"{projectRoot}/tsconfig.json",
1515
"{projectRoot}/package.json",
16-
"{projectRoot}/modern.config.*"
16+
"{projectRoot}/rslib.config.*"
1717
],
1818
"dev": ["default"],
1919
"build": ["default"],

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"devDependencies": {
3535
"@biomejs/biome": "1.9.4",
3636
"@changesets/cli": "^2.27.12",
37-
"@modern-js/module-tools": "2.64.0",
3837
"@modern-js/tsconfig": "2.64.0",
3938
"@playwright/test": "1.47.2",
4039
"@types/cross-spawn": "^6.0.6",

packages/core/modern.config.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

packages/core/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"theme.ts"
4848
],
4949
"scripts": {
50-
"build": "modern build",
51-
"dev": "modern build -w",
50+
"build": "rslib build",
51+
"dev": "rslib build -w",
5252
"reset": "rimraf ./**/node_modules"
5353
},
5454
"dependencies": {
@@ -92,8 +92,9 @@
9292
"unist-util-visit-children": "^3.0.0"
9393
},
9494
"devDependencies": {
95-
"@modern-js/plugin-tailwindcss": "2.64.0",
95+
"@microsoft/api-extractor": "^7.49.2",
9696
"@modern-js/tsconfig": "2.64.0",
97+
"@rslib/core": "0.4.0",
9798
"@types/hast": "3.0.4",
9899
"@types/html-to-text": "^9.0.4",
99100
"@types/jest": "~29.5.14",

packages/core/postcss.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import path from 'node:path';
2+
3+
export default {
4+
plugins: {
5+
tailwindcss: {
6+
config: path.join(__dirname, './tailwind.config.ts'),
7+
},
8+
},
9+
};

packages/core/rslib.config.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { pluginReact } from '@rsbuild/plugin-react';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
{
7+
format: 'esm',
8+
dts: {
9+
bundle: true,
10+
},
11+
syntax: 'es2020',
12+
shims: {
13+
esm: {
14+
require: true,
15+
},
16+
},
17+
source: {
18+
define: {
19+
REQUIRE_CACHE: 'require.cache',
20+
},
21+
},
22+
output: {
23+
distPath: {
24+
root: './dist',
25+
},
26+
externals: [
27+
{
28+
'react-syntax-highlighter/dist/cjs/languages/prism/supported-languages':
29+
'commonjs react-syntax-highlighter/dist/cjs/languages/prism/supported-languages',
30+
},
31+
'react-syntax-highlighter/dist/cjs/languages/prism/supported-languages',
32+
'@rspress/mdx-rs',
33+
'jsdom',
34+
'tailwindcss',
35+
'@rspress/plugin-container-syntax',
36+
],
37+
},
38+
},
39+
{
40+
format: 'esm',
41+
syntax: 'es2020',
42+
dts: {
43+
bundle: true,
44+
},
45+
shims: {
46+
esm: {
47+
require: true,
48+
},
49+
},
50+
output: {
51+
distPath: {
52+
root: './dist',
53+
},
54+
externals: {
55+
'@rspress/mdx-rs': 'commonjs @rspress/mdx-rs',
56+
},
57+
},
58+
source: {
59+
entry: {
60+
loader: './src/node/mdx/loader.ts',
61+
},
62+
},
63+
},
64+
{
65+
bundle: false,
66+
dts: true,
67+
format: 'esm',
68+
syntax: 'es2020',
69+
source: {
70+
entry: {
71+
index: './src/runtime/*',
72+
},
73+
tsconfigPath: './src/runtime/tsconfig.json',
74+
},
75+
output: {
76+
distPath: {
77+
root: './dist/runtime',
78+
},
79+
},
80+
plugins: [pluginReact()],
81+
},
82+
],
83+
});

packages/core/src/node/runtimeModule/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const DEFAULT_I18N_SOURCE = join(process.cwd(), 'i18n.json');
77
export function getI18nData(docConfig: UserConfig) {
88
const { i18nSourcePath = DEFAULT_I18N_SOURCE } = docConfig;
99
try {
10-
delete require.cache[i18nSourcePath];
10+
// @ts-expect-error require.cache is an API in Rslib.
11+
delete REQUIRE_CACHE[i18nSourcePath];
1112
// eslint-disable-next-line import/no-dynamic-require
1213
const i18nSource = require(i18nSourcePath);
1314
return i18nSource;

packages/core/src/runtime/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ type PageMeta = {
3232

3333
export async function initPageData(routePath: string): Promise<PageData> {
3434
const { routes } = process.env.__SSR__
35-
? (require('virtual-routes-ssr') as typeof import('virtual-routes-ssr'))
36-
: (require('virtual-routes') as typeof import('virtual-routes'));
35+
? // biome-ignore format: Biome format will add an extra comma.
36+
((await import('virtual-routes-ssr')) as typeof import(
37+
'virtual-routes-ssr'
38+
))
39+
: ((await import('virtual-routes')) as typeof import('virtual-routes'));
3740
const matched = matchRoutes(routes, routePath)!;
3841
if (matched) {
3942
// Preload route component

packages/core/tailwind.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Config } from 'tailwindcss';
22

3-
export const tailwindConfig: Config = {
3+
export default {
44
content: [],
55
darkMode: 'class',
66
theme: {
@@ -66,4 +66,4 @@ export const tailwindConfig: Config = {
6666
},
6767
},
6868
},
69-
};
69+
} satisfies Config;

0 commit comments

Comments
 (0)