-
Notifications
You must be signed in to change notification settings - Fork 82
feat: use @coze-infra/rslib-config #41
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
Open
wfc-web
wants to merge
6
commits into
coze-dev:main
Choose a base branch
from
wfc-web:feat-rslib-share
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,7 @@ common/autoinstallers/*/.npmrc | |
.vercel/output | ||
rush-logs | ||
dist | ||
lib-ts | ||
|
||
*.tsbuildinfo | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
BASE_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | ||
|
||
# 某些系统可能没有 realpath 命令, | ||
if ! command -v realpath &>/dev/null; then | ||
echo "未找到 realpath 命令" | ||
echo "请执行以下命令安装必要依赖" | ||
echo " brew install coreutils" | ||
exit 1 | ||
fi | ||
ROOT_DIR=$(realpath "$BASE_DIR/../") | ||
|
||
bash "$ROOT_DIR/node_modules/.bin/rsbuild" "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { defineConfig } = require('@coze-infra/eslint-config'); | ||
|
||
module.exports = defineConfig({ | ||
preset: 'node', | ||
packageRoot: __dirname, | ||
ignores: ['lib-ts'], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@coze-infra/rsbuild-config", | ||
"version": "0.0.1", | ||
"author": "[email protected]", | ||
"maintainers": [], | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"bin": { | ||
"rersbuild": "./bin/index.sh", | ||
"rsbuild": "./bin/index.sh" | ||
}, | ||
"scripts": { | ||
"build": "npx tsc -b tsconfig.build.json", | ||
"lint": "eslint ./ --cache --quiet" | ||
}, | ||
"dependencies": { | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@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", | ||
"sucrase": "^3.32.0", | ||
"typescript": "^5.5.3" | ||
} | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { pluginReact } from '@rsbuild/plugin-react'; | ||
import { defineConfig } from '@rsbuild/core'; | ||
|
||
const baseRsbuildConfig = defineConfig({ | ||
plugins: [pluginReact()], | ||
tools: { | ||
rspack: (_, { rspack, appendPlugins }) => { | ||
appendPlugins([ | ||
new rspack.ProvidePlugin({ | ||
process: [require.resolve('process/browser')], | ||
}), | ||
]); | ||
}, | ||
}, | ||
}); | ||
export { defineConfig, baseRsbuildConfig }; | ||
export default baseRsbuildConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "lib-ts", | ||
"noEmit": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
BASE_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") | ||
|
||
# 某些系统可能没有 realpath 命令, | ||
if ! command -v realpath &>/dev/null; then | ||
echo "未找到 realpath 命令" | ||
echo "请执行以下命令安装必要依赖" | ||
echo " brew install coreutils" | ||
exit 1 | ||
fi | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ROOT_DIR=$(realpath "$BASE_DIR/../") | ||
|
||
bash "$ROOT_DIR/node_modules/.bin/rslib" "$@" | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { defineConfig } = require('@coze-infra/eslint-config'); | ||
|
||
module.exports = defineConfig({ | ||
preset: 'node', | ||
packageRoot: __dirname, | ||
ignores: ['lib-ts'], | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@coze-infra/rslib-config", | ||
"version": "0.0.1", | ||
"author": "[email protected]", | ||
"maintainers": [], | ||
"type": "module", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"bin": { | ||
"rerslib": "./bin/index.sh", | ||
"rslib": "./bin/index.sh" | ||
}, | ||
"scripts": { | ||
"build": "npx tsc -b tsconfig.build.json", | ||
"lint": "eslint ./ --cache --quiet" | ||
}, | ||
"dependencies": { | ||
"@rslib/core": "0.0.18" | ||
}, | ||
"devDependencies": { | ||
"@coze-infra/eslint-config": "workspace:*", | ||
"@coze-infra/ts-config": "workspace:*", | ||
"@types/node": "^20", | ||
"sucrase": "^3.32.0", | ||
"typescript": "^5.5.3" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
defineConfig as _defineConfig, | ||
type LibConfig, | ||
type RsbuildConfigOutputTarget, | ||
} from '@rslib/core'; | ||
|
||
type LibFormat = LibConfig['format']; | ||
export type BundleType = boolean | 'excludeExternal'; | ||
|
||
const defineConfig: typeof _defineConfig = _defineConfig; | ||
|
||
export { defineConfig }; | ||
|
||
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', | ||
}; | ||
|
||
export 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; | ||
}); | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
libs[0].dts = { | ||
distPath: './dist/types', | ||
}; | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 defineConfig(getRslibConfig({})); | ||
wfc-web marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "lib-ts", | ||
"noEmit": false | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
"noEmit": true, | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src"] | ||
"include": ["src", "rsbuild.config.ts"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +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', | ||
}; | ||
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, getRslibConfig } from '@coze-infra/rslib-config'; | ||
export default defineConfig( | ||
getRslibConfig({ | ||
format: ['esm', 'cjs', 'umd'], | ||
bundle: 'excludeExternal', | ||
umdName: 'CozeJs', | ||
}), | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,7 @@ | ||
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, getRslibConfig } from '@coze-infra/rslib-config'; | ||
export default defineConfig( | ||
getRslibConfig({ | ||
format: ['esm', 'cjs', 'umd'], | ||
umdName: 'CozeRealtimeApi', | ||
}), | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.