Skip to content

Commit 17de69d

Browse files
author
wfc
committed
feat: use @coze-infra/rslib-config
feat: use @coze-infra/rslib-config
1 parent b2aec1c commit 17de69d

File tree

9 files changed

+151
-68
lines changed

9 files changed

+151
-68
lines changed

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

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/rslib-config/eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = [];

config/rslib-config/index.ts

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { defineConfig, LibConfig } from '@rslib/core';
2+
3+
type LibFormat = LibConfig['format'];
4+
export type BundleType = Boolean | 'excludeExternal';
5+
6+
interface Options {
7+
format?: LibFormat[];
8+
bundle?: BundleType;
9+
tsconfigPath?: string;
10+
umdName?: string;
11+
}
12+
const defaultOptions = {
13+
format: ['esm', 'cjs'] as LibFormat[],
14+
bundle: true,
15+
};
16+
17+
function getRslibConfig(options: Options) {
18+
const { format, bundle, umdName, tsconfigPath } = {
19+
...defaultOptions,
20+
...options,
21+
};
22+
23+
const libs = format.map(libFormat => {
24+
const lib = getLibShared(libFormat, bundle!);
25+
if (libFormat === 'umd') {
26+
lib.umdName = umdName;
27+
lib.bundle = true;
28+
}
29+
return lib;
30+
});
31+
32+
libs[0].dts = {
33+
distPath: './dist/types',
34+
};
35+
36+
return defineConfig({
37+
source: {
38+
tsconfigPath,
39+
},
40+
lib: libs,
41+
});
42+
}
43+
44+
function getLibShared(format: LibFormat, bundleType: BundleType) {
45+
const shared: LibConfig = {
46+
output: {
47+
distPath: {
48+
root: `./dist/${format}`,
49+
},
50+
},
51+
format,
52+
syntax: 'es6',
53+
bundle: !!bundleType,
54+
autoExternal: bundleType === 'excludeExternal',
55+
};
56+
return shared;
57+
}
58+
59+
export default getRslibConfig;

config/rslib-config/package.json

+28
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+
}

packages/coze-js/package.json

+1
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

+9-32
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,10 @@
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: {
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',
188
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-
});
9+
}),
10+
);

packages/realtime-api/package.json

+1
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",

packages/realtime-api/rslib.config.ts

+8-36
Original file line numberDiff line numberDiff line change
@@ -1,37 +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-
autoExternal: false,
13-
};
14-
return shared;
15-
}
16-
17-
export default defineConfig({
18-
source: {
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',
197
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-
});
8+
}),
9+
);

rush.json

+4
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@
381381
"packageName": "@coze-infra/vitest-config",
382382
"projectFolder": "config/vitest-config"
383383
},
384+
{
385+
"packageName": "@coze-infra/rslib-config",
386+
"projectFolder": "config/rslib-config"
387+
},
384388
{
385389
"packageName": "@coze/api",
386390
"projectFolder": "packages/coze-js"

0 commit comments

Comments
 (0)