Skip to content

Commit ae4d91c

Browse files
committed
feat: add basic implementation
1 parent 4c58542 commit ae4d91c

File tree

12 files changed

+47
-77
lines changed

12 files changed

+47
-77
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ on:
55
# Triggers the workflow on pull request events but only for the main branch
66
pull_request:
77
branches: [main]
8-
98
push:
109
branches: [main]
11-
1210
# Allows you to run this workflow manually from the Actions tab
1311
workflow_dispatch:
1412

README.md

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# rsbuild-plugin-example
1+
# @rsbuild/plugin-toml
22

3-
rsbuild-plugin-example is a Rsbuild plugin to do something.
3+
An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
44

55
<p>
6-
<a href="https://npmjs.com/package/rsbuild-plugin-example">
7-
<img src="https://img.shields.io/npm/v/rsbuild-plugin-example?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
6+
<a href="https://npmjs.com/package/@rsbuild/plugin-toml">
7+
<img src="https://img.shields.io/npm/v/@rsbuild/plugin-toml?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
88
</a>
99
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
1010
</p>
@@ -14,36 +14,20 @@ rsbuild-plugin-example is a Rsbuild plugin to do something.
1414
Install:
1515

1616
```bash
17-
npm add rsbuild-plugin-example -D
17+
npm add @rsbuild/plugin-toml -D
1818
```
1919

2020
Add plugin to your `rsbuild.config.ts`:
2121

2222
```ts
2323
// rsbuild.config.ts
24-
import { pluginExample } from "rsbuild-plugin-example";
24+
import { pluginToml } from "@rsbuild/plugin-toml";
2525

2626
export default {
27-
plugins: [pluginExample()],
27+
plugins: [pluginToml()],
2828
};
2929
```
3030

31-
## Options
32-
33-
### foo
34-
35-
Some description.
36-
37-
- Type: `string`
38-
- Default: `undefined`
39-
- Example:
40-
41-
```js
42-
pluginExample({
43-
foo: "bar",
44-
});
45-
```
46-
4731
## License
4832

4933
[MIT](./LICENSE).

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "rsbuild-plugin-example",
2+
"name": "@rsbuild/plugin-toml",
33
"version": "0.0.0",
44
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-template",
55
"license": "MIT",
@@ -14,7 +14,9 @@
1414
"main": "./dist/index.js",
1515
"module": "./dist/index.mjs",
1616
"types": "./dist/index.d.ts",
17-
"files": ["dist"],
17+
"files": [
18+
"dist"
19+
],
1820
"scripts": {
1921
"build": "tsup",
2022
"dev": "tsup --watch",
@@ -32,6 +34,9 @@
3234
"biome check --write --no-errors-on-unmatched"
3335
]
3436
},
37+
"dependencies": {
38+
"toml": "^3.0.0"
39+
},
3540
"devDependencies": {
3641
"@biomejs/biome": "^1.8.3",
3742
"@playwright/test": "^1.44.1",

playground/rsbuild.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from '@rsbuild/core';
2-
import { pluginExample } from '../src';
2+
import { pluginToml } from '../src';
33

44
export default defineConfig({
5-
plugins: [pluginExample()],
5+
plugins: [pluginToml()],
66
});

playground/src/a.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
foo = "bar"
2+
age = 1

playground/src/b.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
list = [1, 2]

playground/src/index.css

Lines changed: 0 additions & 26 deletions
This file was deleted.

playground/src/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import './index.css';
1+
import { age } from './a.toml';
2+
import b from './b.toml';
23

3-
document.querySelector('#root').innerHTML = `
4-
<div class="content">
5-
<h1>Vanilla Rsbuild</h1>
6-
<p>Start building amazing things with Rsbuild.</p>
7-
</div>
8-
`;
4+
window.age = age;
5+
window.b = JSON.stringify(b);
6+
7+
console.log(age, b);

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { RsbuildPlugin } from '@rsbuild/core';
22

3-
export type PluginExampleOptions = {
4-
foo?: string;
5-
bar?: boolean;
6-
};
3+
export const PLUGIN_TOML_NAME = 'rsbuild:toml';
74

8-
export const pluginExample = (
9-
options: PluginExampleOptions = {},
10-
): RsbuildPlugin => ({
11-
name: 'plugin-example',
5+
export const pluginToml = (): RsbuildPlugin => ({
6+
name: PLUGIN_TOML_NAME,
127

13-
setup() {
14-
console.log('Hello Rsbuild!', options);
8+
async setup(api) {
9+
const { parse } = await import('toml');
10+
11+
api.transform({ test: /\.toml$/ }, ({ code }) => {
12+
const parsed = parse(code);
13+
return `module.exports = ${JSON.stringify(parsed, undefined, '\t')};`;
14+
});
1515
},
1616
});

0 commit comments

Comments
 (0)