Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(theme-default): use Rslib to build the package #1830

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions e2e/tests/auto-nav-sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test.describe('Auto nav and sidebar test', async () => {
['Config', 'Client API', 'Commands', 'Single'].join(','),
);

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(
[
Expand All @@ -60,7 +60,7 @@ test.describe('Auto nav and sidebar test', async () => {
].join(','),
);

const a = await page.$$('.overview-group_8f375 ul a');
const a = await page.$$('.overview-group_f8331 ul a');
const aTexts = await Promise.all(a.map(element => element.textContent()));
expect(aTexts.join(',')).toEqual(
[
Expand Down Expand Up @@ -100,7 +100,7 @@ test.describe('Auto nav and sidebar test', async () => {
].join(','),
);

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(
[
Expand All @@ -113,7 +113,7 @@ test.describe('Auto nav and sidebar test', async () => {
].join(','),
);

const a = await page.$$('.overview-group_8f375 ul a');
const a = await page.$$('.overview-group_f8331 ul a');
const aTexts = await Promise.all(a.map(element => element.textContent()));
expect(aTexts.join(',')).toEqual(
[
Expand Down Expand Up @@ -141,11 +141,11 @@ test.describe('Auto nav and sidebar test', async () => {
const h2Texts = await Promise.all(h2.map(element => element.textContent()));
expect(h2Texts.join(',')).toEqual(['Client API'].join(','));

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(['Runtime API', 'Components'].join(','));

const a = await page.$$('.overview-group_8f375 ul a');
const a = await page.$$('.overview-group_f8331 ul a');
const aTexts = await Promise.all(a.map(element => element.textContent()));
expect(aTexts.join(',')).toEqual(['Usage', 'Example'].join(','));
});
Expand All @@ -171,11 +171,11 @@ test.describe('Auto nav and sidebar test', async () => {
const h2Texts = await Promise.all(h2.map(element => element.textContent()));
expect(h2Texts.join(',')).toEqual(['Nested'].join(','));

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(['Nested config'].join(','));

const a = await page.$$('.overview-group_8f375 ul a');
const a = await page.$$('.overview-group_f8331 ul a');
const aTexts = await Promise.all(a.map(element => element.textContent()));
expect(aTexts.join(',')).toEqual(['Nested H2'].join(','));
});
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/inline-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ test.describe('Inline markdown test', async () => {
].join(','),
);

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(
[
Expand Down Expand Up @@ -128,7 +128,7 @@ test.describe('Inline markdown test', async () => {
expect(html).toContain(expectedH3InnerHtml[index]);
}

const a = await page.$$('.overview-group_8f375 ul a');
const a = await page.$$('.overview-group_f8331 ul a');
const aTexts = await Promise.all(a.map(element => element.textContent()));
expect(aTexts.join(',')).toEqual(
[
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/nested-overview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test.describe('Nested overview page', async () => {
const h2Texts = await Promise.all(h2.map(element => element.textContent()));
expect(h2Texts.join(',')).toEqual(['Level 2'].join(','));

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(['Level 2', 'two', 'Level 3'].join(','));
});
Expand All @@ -52,7 +52,7 @@ test.describe('Nested overview page', async () => {
const h2Texts = await Promise.all(h2.map(element => element.textContent()));
expect(h2Texts.join(',')).toEqual(['two', 'Level 3'].join(','));

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(['two', 'Level 3', 'three'].join(','));
});
Expand All @@ -71,7 +71,7 @@ test.describe('Nested overview page', async () => {
const h2Texts = await Promise.all(h2.map(element => element.textContent()));
expect(h2Texts.join(',')).toEqual(['three'].join(','));

const h3 = await page.$$('.overview-group_8f375 h3');
const h3 = await page.$$('.overview-group_f8331 h3');
const h3Texts = await Promise.all(h3.map(element => element.textContent()));
expect(h3Texts.join(',')).toEqual(['three'].join(','));
});
Expand Down
102 changes: 0 additions & 102 deletions packages/theme-default/modern.config.ts

This file was deleted.

9 changes: 7 additions & 2 deletions packages/theme-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"src"
],
"scripts": {
"build": "modern build",
"dev": "modern build -w",
"build": "rslib build",
"dev": "rslib build -w",
"reset": "rimraf ./**/node_modules"
},
"dependencies": {
Expand All @@ -60,8 +60,13 @@
"react-syntax-highlighter": "^15.6.1"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.49.2",
"@modern-js/plugin-tailwindcss": "2.64.0",
"@modern-js/tsconfig": "2.64.0",
"@rsbuild/plugin-react": "~1.1.0",
"@rsbuild/plugin-sass": "~1.2.0",
"@rsbuild/plugin-svgr": "^1.0.6",
"@rslib/core": "0.4.0",
"@types/body-scroll-lock": "^3.1.2",
"@types/hast": "3.0.4",
"@types/jest": "~29.5.14",
Expand Down
9 changes: 9 additions & 0 deletions packages/theme-default/postcss.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import path from 'node:path';

export default {
plugins: {
tailwindcss: {
config: path.join(__dirname, './tailwind.config.ts'),
},
},
};
92 changes: 92 additions & 0 deletions packages/theme-default/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { defineConfig } from '@rslib/core';

const COMMON_EXTERNALS = [
'virtual-routes-ssr',
'virtual-routes',
'virtual-search-index-hash',
'virtual-site-data',
'virtual-global-styles',
'virtual-global-components',
'virtual-search-hooks',
'@rspress/runtime',
'@theme',
/@theme-assets\//,
'virtual-i18n-text',
'virtual-prism-languages',
// To be externalized when bundling d.ts.
'@types/react',
];

export default defineConfig({
lib: [
{
format: 'esm',
dts: { bundle: true },
plugins: [pluginReact(), pluginSvgr(), pluginSass()],
source: {
define: {
__WEBPACK_PUBLIC_PATH__: '__webpack_public_path__',
},
entry: {
bundle: './src/index.ts',
},
},
output: {
target: 'web',
externals: COMMON_EXTERNALS,
cssModules: {
localIdentName: '[local]_[hash:hex:5]',
},
copy: {
patterns: [
{
from: './.theme-entry.js',
to: './index.js',
context: __dirname,
},
{
from: './.theme-entry.d.ts',
to: './index.d.ts',
context: __dirname,
},
],
},
},
},
{
source: {
entry: {
'source-build-plugin': './src/node/source-build-plugin.ts',
},
},
format: 'esm',
syntax: 'es2020',
output: {
distPath: {
root: 'dist/node',
},
externals: ['tailwindcss'],
},
},
// pre-built svg files
{
format: 'esm',
syntax: 'es2020',
bundle: false,
plugins: [pluginReact(), pluginSvgr({ query: /.*/ })],
source: {
entry: {
assets: ['src/assets'],
},
},
output: {
distPath: {
root: 'dist/assets',
},
},
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class LocalProvider implements Provider {
const searchIndexGroupID = `${version}###${lang}`;
const searchIndexVersion = version ? `.${version.replace('.', '_')}` : '';
const searchIndexLang = lang ? `.${lang}` : '';
const searchIndexURL = `${removeTrailingSlash(__webpack_public_path__)}/static/${SEARCH_INDEX_NAME}${searchIndexVersion}${searchIndexLang}.${searchIndexHash[searchIndexGroupID]}.json`;
const searchIndexURL = `${removeTrailingSlash(__WEBPACK_PUBLIC_PATH__)}/static/${SEARCH_INDEX_NAME}${searchIndexVersion}${searchIndexLang}.${searchIndexHash[searchIndexGroupID]}.json`;

const handleError = (result: unknown) => {
console.error(
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-default/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ declare module 'virtual-search-index-hash' {
export default hash;
}

declare const __webpack_public_path__: string;
declare const __WEBPACK_PUBLIC_PATH__: string;

declare module '@theme';
2 changes: 1 addition & 1 deletion packages/theme-default/src/node/source-build-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import type { RspressPlugin } from '@rspress/shared';
import { tailwindConfig } from '../../tailwind.config';
import tailwindConfig from '../../tailwind.config';

const require = createRequire(import.meta.url);
const ROOT_DIR = fileURLToPath(new URL('../..', import.meta.url).href);
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-default/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Config } from 'tailwindcss';

export const tailwindConfig = {
export default {
content: ['./src/**/*.{js,ts,jsx,tsx}'],
darkMode: 'class',
theme: {
Expand Down
2 changes: 1 addition & 1 deletion packages/theme-default/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"include": [
"src",
"vitest.config.ts",
"./modern.config.ts",
"./rslib.config.ts",
"./tailwind.config.ts"
],
"references": [
Expand Down
Loading