Skip to content

Commit 33d4389

Browse files
authored
feat: init @lynx-js/config-rsbuild-plugin for Lynx Configs (#2052)
<!-- Thank you for submitting a pull request! We appreciate the time and effort you have invested in making these changes. Please ensure that you provide enough information to allow others to review your pull request. Upon submission, your pull request will be automatically assigned with reviewers. If you want to learn more about contributing to this project, please visit: https://github.com/lynx-family/lynx-stack/blob/main/CONTRIBUTING.md. --> See docs at: lynx-family/lynx-website#673, [Preview](https://deploy-preview-673--lynx-doc.netlify.app/next/api/lynx-config/index.html) <!-- The AI summary below will be auto-generated - feel free to replace it with your own. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Adds a new RSBuild plugin surfaced to users, including an option to enable inline CSS variables. * **Documentation** * Publishes package README, API report, and adds site navigation entries with usage examples. * **Tests** * Adds unit, type-level, and integration tests covering validation, overrides and unknown keys. * **Chores** * Adds package/build/test configs and updates dev-dependencies for examples and the website. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Checklist <!--- Check and mark with an "x" --> - [x] Tests updated (or not required). - [ ] Documentation updated (or not required). - [x] Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).
1 parent fc9e863 commit 33d4389

32 files changed

+1120
-1
lines changed

.changeset/rotten-pears-follow.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"@lynx-js/config-rsbuild-plugin": patch
3+
---
4+
5+
Init `@lynx-js/config-rsbuild-plugin` for configuring Lynx Configs that are not exposed by DSL plugins.
6+
7+
For example:
8+
9+
```ts
10+
// lynx.config.ts
11+
import { pluginLynxConfig } from '@lynx-js/config-rsbuild-plugin';
12+
import { defineConfig } from '@lynx-js/rspeedy';
13+
14+
export default defineConfig({
15+
plugins: [
16+
pluginLynxConfig({
17+
enableCheckExposureOptimize: false,
18+
}),
19+
],
20+
});
21+
```

examples/tailwindcss/lynx.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { pluginTailwindCSS } from 'rsbuild-plugin-tailwindcss';
22

3+
import { pluginLynxConfig } from '@lynx-js/config-rsbuild-plugin';
34
import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin';
45
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
56
import { defineConfig } from '@lynx-js/rspeedy';
@@ -17,5 +18,8 @@ export default defineConfig({
1718
config: 'tailwind.config.ts',
1819
exclude: [/[\\/]node_modules[\\/]/],
1920
}),
21+
pluginLynxConfig({
22+
enableCSSInlineVariables: true,
23+
}),
2024
],
2125
});

examples/tailwindcss/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"tailwind-merge": "^3.4.0"
1515
},
1616
"devDependencies": {
17+
"@lynx-js/config-rsbuild-plugin": "workspace:*",
1718
"@lynx-js/qrcode-rsbuild-plugin": "workspace:*",
1819
"@lynx-js/react-rsbuild-plugin": "workspace:*",
1920
"@lynx-js/rspeedy": "workspace:*",

examples/tailwindcss/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
{ "path": "../../packages/rspeedy/core/tsconfig.build.json" },
1919
{ "path": "../../packages/rspeedy/plugin-qrcode/tsconfig.build.json" },
2020
{ "path": "../../packages/rspeedy/plugin-react/tsconfig.build.json" },
21+
{ "path": "../../packages/rspeedy/plugin-config/tsconfig.build.json" },
2122
],
2223
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<p align="center">
2+
<a href="https://lynxjs.org/rspeedy" target="blank"><img src="https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/rspeedy-banner.png" alt="Rspeedy Logo" /></a>
3+
</p>
4+
5+
<p>
6+
<a aria-label="NPM version" href="https://www.npmjs.com/package/@lynx-js/config-rsbuild-plugin">
7+
<img alt="" src="https://img.shields.io/npm/v/@lynx-js/config-rsbuild-plugin?logo=npm">
8+
</a>
9+
<a aria-label="License" href="https://www.npmjs.com/package/@lynx-js/config-rsbuild-plugin">
10+
<img src="https://img.shields.io/badge/License-Apache--2.0-blue" alt="license" />
11+
</a>
12+
</p>
13+
14+
## Getting Started
15+
16+
```bash
17+
npm install -D @lynx-js/config-rsbuild-plugin
18+
```
19+
20+
## Usage
21+
22+
```ts
23+
// lynx.config.ts
24+
import { pluginLynxConfig } from '@lynx-js/config-rsbuild-plugin'
25+
import { defineConfig } from '@lynx-js/rspeedy'
26+
27+
export default defineConfig({
28+
plugins: [
29+
pluginLynxConfig({
30+
enableCheckExposureOptimize: false,
31+
}),
32+
],
33+
})
34+
```
35+
36+
## Contributing
37+
38+
Contributions to Rspeedy are welcome and highly appreciated. However, before you jump right into it, we would like you to review our [Contribution Guidelines](/CONTRIBUTING.md) to make sure you have a smooth experience contributing to this project.
39+
40+
## License
41+
42+
Rspeedy is Apache-2.0 licensed.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Config file for API Extractor. For more info, please visit: https://api-extractor.com
3+
*/
4+
{
5+
"extends": "../../../api-extractor.json",
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## API Report File for "@lynx-js/config-rsbuild-plugin"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import type { CompilerOptions } from '@lynx-js/type-config';
8+
import type { Config as Config_2 } from '@lynx-js/type-config';
9+
import type { RsbuildPlugin } from '@lynx-js/rspeedy';
10+
11+
// @public
12+
export interface Config extends Config_2, CompilerOptions {
13+
}
14+
15+
// @public
16+
export interface Options {
17+
compilerOptionsKeys?: string[];
18+
configKeys?: string[];
19+
dslPluginName2PkgName?: Record<string, string>;
20+
upgradeRspeedyLink?: string;
21+
validate?: (input: unknown) => Config;
22+
}
23+
24+
// @public
25+
export function pluginLynxConfig(config: Config, options?: Options): RsbuildPlugin;
26+
27+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@lynx-js/config-rsbuild-plugin",
3+
"version": "0.0.0",
4+
"description": "An rsbuild plugin for config Lynx Config defined by @lynx-js/type-config.",
5+
"keywords": [
6+
"rsbuild",
7+
"Lynx",
8+
"Config"
9+
],
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/lynx-family/lynx-stack.git",
13+
"directory": "packages/rspeedy/plugin-config"
14+
},
15+
"license": "Apache-2.0",
16+
"author": {
17+
"name": "Yiming Li",
18+
"email": "yimingli.cs@gmail.com"
19+
},
20+
"type": "module",
21+
"exports": {
22+
".": {
23+
"types": "./lib/index.d.ts",
24+
"default": "./lib/index.js"
25+
},
26+
"./package.json": "./package.json"
27+
},
28+
"types": "./lib/index.d.ts",
29+
"files": [
30+
"dist",
31+
"CHANGELOG.md",
32+
"README.md"
33+
],
34+
"scripts": {
35+
"api-extractor": "api-extractor run --verbose",
36+
"build": "rslib build",
37+
"test": "vitest"
38+
},
39+
"dependencies": {
40+
"@lynx-js/type-config": "3.6.0"
41+
},
42+
"devDependencies": {
43+
"@lynx-js/rspeedy": "workspace:*",
44+
"@lynx-js/template-webpack-plugin": "workspace:*",
45+
"@lynx-js/test-tools": "workspace:*",
46+
"@rollup/plugin-typescript": "^12.3.0",
47+
"@rsbuild/core": "catalog:rsbuild",
48+
"@types/object.pick": "^1.3.4",
49+
"object.pick": "^1.3.0",
50+
"picocolors": "^1.1.1",
51+
"terminal-link": "^4.0.0",
52+
"typia": "10.1.0",
53+
"typia-rspack-plugin": "2.2.2",
54+
"webpack": "^5.104.1"
55+
},
56+
"peerDependencies": {
57+
"@lynx-js/rspeedy": "^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0"
58+
},
59+
"engines": {
60+
"node": ">=18"
61+
},
62+
"publishConfig": {
63+
"exports": {
64+
".": {
65+
"types": "./dist/index.d.ts",
66+
"default": "./dist/index.js"
67+
},
68+
"./package.json": "./package.json"
69+
},
70+
"types": "./dist/index.d.ts"
71+
}
72+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig } from '@rslib/core'
2+
import { TypiaRspackPlugin } from 'typia-rspack-plugin'
3+
4+
export default defineConfig({
5+
lib: [
6+
{ format: 'esm', syntax: 'es2022', dts: { bundle: true } },
7+
],
8+
source: {
9+
tsconfigPath: './tsconfig.build.json',
10+
},
11+
tools: {
12+
rspack: {
13+
plugins: [
14+
new TypiaRspackPlugin({ log: false }),
15+
],
16+
},
17+
},
18+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2025 The Lynx Authors. All rights reserved.
2+
// Licensed under the Apache License Version 2.0 that can be found in the
3+
// LICENSE file in the root directory of this source tree.
4+
5+
import pick from 'object.pick'
6+
import type { Compiler } from 'webpack'
7+
8+
import type { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin'
9+
10+
export class LynxConfigWebpackPlugin<Config extends object> {
11+
constructor(
12+
private options: {
13+
LynxTemplatePlugin: typeof LynxTemplatePlugin
14+
config: Config
15+
compilerOptionsKeys: string[]
16+
configKeys: string[]
17+
},
18+
) {}
19+
20+
name = 'LynxConfigWebpackPlugin'
21+
22+
apply(compiler: Compiler): void {
23+
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
24+
const hooks = this.options.LynxTemplatePlugin.getLynxTemplatePluginHooks(
25+
compilation,
26+
)
27+
28+
hooks.beforeEncode.tap(this.name, (args) => {
29+
const { config } = this.options
30+
31+
args.encodeData.compilerOptions = {
32+
...args.encodeData.compilerOptions,
33+
...pick(config, this.options.compilerOptionsKeys as (keyof Config)[]),
34+
}
35+
36+
args.encodeData.sourceContent.config = {
37+
...args.encodeData.sourceContent.config,
38+
...pick(config, this.options.configKeys as (keyof Config)[]),
39+
}
40+
41+
return args
42+
})
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)