Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
340 changes: 231 additions & 109 deletions common/config/subspaces/default/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/rsbuild-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [];
30 changes: 30 additions & 0 deletions config/rsbuild-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@coze-infra/rsbuild-config",
"version": "0.0.1",
"author": "wangfocheng@bytedance.com",
"maintainers": [],
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "exit",
"lint": "exit",
"test": "exit",
"test:cov": "exit 0"
},
"dependencies": {
"@rsbuild/core": "1.1.10",
"@rsbuild/plugin-react": "1.1.0",
"process": "~0.11.10"
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@types/node": "^20",
"@vitejs/plugin-react": "~4.3.3",
"@vitest/coverage-v8": "~2.1.4",
"happy-dom": "~15.11.0",
"sucrase": "^3.32.0",
"typescript": "^5.5.3",
"vitest": "~2.1.4"
}
}
16 changes: 16 additions & 0 deletions config/rsbuild-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

const baseRsbuildConfig = defineConfig({
plugins: [pluginReact()],
tools: {
rspack: (_, { rspack, appendPlugins }) => {
appendPlugins([
new rspack.ProvidePlugin({
process: [require.resolve('process/browser')],
}),
]);
},
},
});
export default baseRsbuildConfig;
7 changes: 7 additions & 0 deletions config/rsbuild-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../ts-config/tsconfig.node.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*", "eslint.*.js"]
}
1 change: 1 addition & 0 deletions config/rslib-config/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = [];
28 changes: 28 additions & 0 deletions config/rslib-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@coze-infra/rslib-config",
"version": "0.0.1",
"author": "wangfocheng@bytedance.com",
"maintainers": [],
"main": "src/index.ts",
"types": "src/index.ts",
"scripts": {
"build": "exit",
"lint": "exit",
"test": "exit",
"test:cov": "exit 0"
},
"dependencies": {
"@rslib/core": "0.0.18"
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@types/node": "^20",
"@vitejs/plugin-react": "~4.3.3",
"@vitest/coverage-v8": "~2.1.4",
"happy-dom": "~15.11.0",
"sucrase": "^3.32.0",
"typescript": "^5.5.3",
"vitest": "~2.1.4"
}
}
74 changes: 74 additions & 0 deletions config/rslib-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
defineConfig,
LibConfig,
RsbuildConfigOutputTarget,
} from '@rslib/core';

type LibFormat = LibConfig['format'];
export type BundleType = boolean | 'excludeExternal';

interface Options {
format?: LibFormat[];
bundle?: BundleType;
tsconfigPath?: string;
umdName?: string;
target?: RsbuildConfigOutputTarget;
}
const defaultOptions = {
format: ['esm', 'cjs'] as LibFormat[],
bundle: true,
target: 'web' as RsbuildConfigOutputTarget,
tsconfigPath: './tsconfig.build.json',
};

function getRslibConfig(options: Options) {
const { format, bundle, umdName, tsconfigPath, target } = {
...defaultOptions,
...options,
};

const libs = format.map(libFormat => {
const lib = getLibShared(libFormat, bundle);
if (libFormat === 'umd') {
if (!umdName) {
throw new Error(
'getRslibConfig: umdName is required when using UMD format',
);
}
lib.umdName = umdName;
lib.bundle = true;
}
return lib;
});

libs[0].dts = {
distPath: './dist/types',
};

return defineConfig({
source: {
tsconfigPath,
},
output: {
target,
},
lib: libs,
});
}

function getLibShared(format: LibFormat, bundleType: BundleType) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
bundle: !!bundleType,
autoExternal: bundleType === 'excludeExternal',
};
return shared;
}

export default getRslibConfig;
7 changes: 7 additions & 0 deletions config/rslib-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../ts-config/tsconfig.node.json",
"compilerOptions": {
"noEmit": true
},
"include": ["src/**/*", "eslint.*.js"]
}
6 changes: 4 additions & 2 deletions examples/coze-js-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "node scripts/build.js",
"build": "rsbuild build",
"lint": "eslint --cache --quiet",
"start": "node scripts/start.js"
"start": "rsbuild dev"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -76,6 +76,8 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rsbuild-config": "workspace:*",
"@rsbuild/core": "1.1.10",
"@types/jest": "^29.2.2",
"@types/node": "^20",
"@types/react": "^18.3.11",
Expand Down
3 changes: 3 additions & 0 deletions examples/coze-js-web/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@rsbuild/core';
import baseRsbuildConfig from '@coze-infra/rsbuild-config/src';
export default defineConfig(baseRsbuildConfig);
2 changes: 1 addition & 1 deletion examples/coze-js-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ChatX from './pages/chat-x';

function App() {
return (
<Router basename={`${process.env.PUBLIC_URL}`}>
<Router basename={`${process.env.PUBLIC_URL || ''}`}>
<div className="App">
<Routes>
<Route path="/chat" element={<Chat />} />
Expand Down
2 changes: 1 addition & 1 deletion examples/coze-js-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
"include": ["src", "rsbuild.config.ts"]
}
1 change: 1 addition & 0 deletions packages/coze-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rslib-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@coze-infra/vitest-config": "workspace:*",
"@rslib/core": "0.0.18",
Expand Down
42 changes: 9 additions & 33 deletions packages/coze-js/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
import { defineConfig, type LibConfig } from '@rslib/core';

function getLibShared(format: LibConfig['format']) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
};
return shared;
}

export default defineConfig({
source: {
tsconfigPath: './tsconfig.build.json',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeJs',
},
getLibShared('cjs'),
],
});
import { defineConfig } from '@rslib/core';
import getRslibConfig from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
bundle: 'excludeExternal',
umdName: 'CozeJs',
}),
);
1 change: 1 addition & 0 deletions packages/realtime-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"devDependencies": {
"@coze-infra/eslint-config": "workspace:*",
"@coze-infra/rslib-config": "workspace:*",
"@coze-infra/ts-config": "workspace:*",
"@coze-infra/vitest-config": "workspace:*",
"@rslib/core": "0.0.18",
Expand Down
45 changes: 8 additions & 37 deletions packages/realtime-api/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
import { defineConfig, type LibConfig } from '@rslib/core';

function getLibShared(format: LibConfig['format']) {
const shared: LibConfig = {
output: {
distPath: {
root: `./dist/${format}`,
},
},
format,
syntax: 'es6',
autoExternal: false,
};
return shared;
}

export default defineConfig({
source: {
tsconfigPath: './tsconfig.build.json',
},
output: {
target: 'web',
},
lib: [
{
...getLibShared('esm'),
dts: {
distPath: './dist/types',
},
},
{
...getLibShared('umd'),
umdName: 'CozeRealtimeApi',
},
getLibShared('cjs'),
],
});
import { defineConfig } from '@rslib/core';
import getRslibConfig from '@coze-infra/rslib-config';
export default defineConfig(
getRslibConfig({
format: ['esm', 'cjs', 'umd'],
umdName: 'CozeRealtimeApi',
}),
);
8 changes: 8 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@
"packageName": "@coze-infra/package-audit",
"projectFolder": "infra/package-audit"
},
{
"packageName": "@coze-infra/rslib-config",
"projectFolder": "config/rslib-config"
},
{
"packageName": "@coze-infra/rsbuild-config",
"projectFolder": "config/rsbuild-config"
},
{
"packageName": "@coze/api",
"projectFolder": "packages/coze-js"
Expand Down
Loading