Skip to content

Commit 9f43aed

Browse files
author
wfc
committed
feat: use @coze-infra/rslib-config
feat: use @coze-infra/rslib-config feat: rush update feat: comments feat: tsconfig.json feat: src feat: add target web feat: output target feat: default tsconfig path feat: rush update
1 parent adaf819 commit 9f43aed

File tree

10 files changed

+173
-70
lines changed

10 files changed

+173
-70
lines changed

common/config/subspaces/default/pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = [];

config/rslib-config/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@coze-infra/rslib-config",
3+
"version": "0.0.1",
4+
"author": "[email protected]",
5+
"maintainers": [],
6+
"main": "src/index.ts",
7+
"types": "src/index.ts",
8+
"scripts": {
9+
"build": "exit",
10+
"lint": "exit",
11+
"test": "exit",
12+
"test:cov": "exit 0"
13+
},
14+
"dependencies": {
15+
"@rslib/core": "0.0.18"
16+
},
17+
"devDependencies": {
18+
"@coze-infra/eslint-config": "workspace:*",
19+
"@coze-infra/ts-config": "workspace:*",
20+
"@types/node": "^20",
21+
"@vitejs/plugin-react": "~4.3.3",
22+
"@vitest/coverage-v8": "~2.1.4",
23+
"happy-dom": "~15.11.0",
24+
"sucrase": "^3.32.0",
25+
"typescript": "^5.5.3",
26+
"vitest": "~2.1.4"
27+
}
28+
}

config/rslib-config/src/index.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {
2+
defineConfig,
3+
LibConfig,
4+
RsbuildConfigOutputTarget,
5+
} from '@rslib/core';
6+
7+
type LibFormat = LibConfig['format'];
8+
export type BundleType = boolean | 'excludeExternal';
9+
10+
interface Options {
11+
format?: LibFormat[];
12+
bundle?: BundleType;
13+
tsconfigPath?: string;
14+
umdName?: string;
15+
target?: RsbuildConfigOutputTarget;
16+
}
17+
const defaultOptions = {
18+
format: ['esm', 'cjs'] as LibFormat[],
19+
bundle: true,
20+
target: 'web' as RsbuildConfigOutputTarget,
21+
tsconfigPath: './tsconfig.build.json',
22+
};
23+
24+
function getRslibConfig(options: Options) {
25+
const { format, bundle, umdName, tsconfigPath, target } = {
26+
...defaultOptions,
27+
...options,
28+
};
29+
30+
const libs = format.map(libFormat => {
31+
const lib = getLibShared(libFormat, bundle);
32+
if (libFormat === 'umd') {
33+
if (!umdName) {
34+
throw new Error(
35+
'getRslibConfig: umdName is required when using UMD format',
36+
);
37+
}
38+
lib.umdName = umdName;
39+
lib.bundle = true;
40+
}
41+
return lib;
42+
});
43+
44+
libs[0].dts = {
45+
distPath: './dist/types',
46+
};
47+
48+
return defineConfig({
49+
source: {
50+
tsconfigPath,
51+
},
52+
output: {
53+
target,
54+
},
55+
lib: libs,
56+
});
57+
}
58+
59+
function getLibShared(format: LibFormat, bundleType: BundleType) {
60+
const shared: LibConfig = {
61+
output: {
62+
distPath: {
63+
root: `./dist/${format}`,
64+
},
65+
},
66+
format,
67+
syntax: 'es6',
68+
bundle: !!bundleType,
69+
autoExternal: bundleType === 'excludeExternal',
70+
};
71+
return shared;
72+
}
73+
74+
export default getRslibConfig;

config/rslib-config/tsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../ts-config/tsconfig.node.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"include": ["src/**/*", "eslint.*.js"]
7+
}

packages/coze-js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@coze-infra/eslint-config": "workspace:*",
59+
"@coze-infra/rslib-config": "workspace:*",
5960
"@coze-infra/ts-config": "workspace:*",
6061
"@coze-infra/vitest-config": "workspace:*",
6162
"@rslib/core": "0.0.18",

packages/coze-js/rslib.config.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1-
import { defineConfig, type LibConfig } from '@rslib/core';
2-
3-
function getLibShared(format: LibConfig['format']) {
4-
const shared: LibConfig = {
5-
output: {
6-
distPath: {
7-
root: `./dist/${format}`,
8-
},
9-
},
10-
format,
11-
syntax: 'es6',
12-
};
13-
return shared;
14-
}
15-
16-
export default defineConfig({
17-
source: {
18-
tsconfigPath: './tsconfig.build.json',
19-
},
20-
lib: [
21-
{
22-
...getLibShared('esm'),
23-
dts: {
24-
distPath: './dist/types',
25-
},
26-
},
27-
{
28-
...getLibShared('umd'),
29-
umdName: 'CozeJs',
30-
},
31-
getLibShared('cjs'),
32-
],
33-
});
1+
import { defineConfig } from '@rslib/core';
2+
import getRslibConfig from '@coze-infra/rslib-config';
3+
export default defineConfig(
4+
getRslibConfig({
5+
format: ['esm', 'cjs', 'umd'],
6+
bundle: 'excludeExternal',
7+
umdName: 'CozeJs',
8+
}),
9+
);

packages/realtime-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"devDependencies": {
5656
"@coze-infra/eslint-config": "workspace:*",
57+
"@coze-infra/rslib-config": "workspace:*",
5758
"@coze-infra/ts-config": "workspace:*",
5859
"@coze-infra/vitest-config": "workspace:*",
5960
"@rslib/core": "0.0.18",
Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
1-
import { defineConfig, type LibConfig } from '@rslib/core';
2-
3-
function getLibShared(format: LibConfig['format']) {
4-
const shared: LibConfig = {
5-
output: {
6-
distPath: {
7-
root: `./dist/${format}`,
8-
},
9-
},
10-
format,
11-
syntax: 'es6',
12-
autoExternal: false,
13-
};
14-
return shared;
15-
}
16-
17-
export default defineConfig({
18-
source: {
19-
tsconfigPath: './tsconfig.build.json',
20-
},
21-
output: {
22-
target: 'web',
23-
},
24-
lib: [
25-
{
26-
...getLibShared('esm'),
27-
dts: {
28-
distPath: './dist/types',
29-
},
30-
},
31-
{
32-
...getLibShared('umd'),
33-
umdName: 'CozeRealtimeApi',
34-
},
35-
getLibShared('cjs'),
36-
],
37-
});
1+
import { defineConfig } from '@rslib/core';
2+
import getRslibConfig from '@coze-infra/rslib-config';
3+
export default defineConfig(
4+
getRslibConfig({
5+
format: ['esm', 'cjs', 'umd'],
6+
umdName: 'CozeRealtimeApi',
7+
}),
8+
);

rush.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@
402402
"packageName": "@coze-infra/package-audit",
403403
"projectFolder": "infra/package-audit"
404404
},
405+
{
406+
"packageName": "@coze-infra/rslib-config",
407+
"projectFolder": "config/rslib-config"
408+
},
405409
{
406410
"packageName": "@coze/api",
407411
"projectFolder": "packages/coze-js"

0 commit comments

Comments
 (0)