Skip to content

Commit 0965cd5

Browse files
committed
test: basic test
1 parent 4f0fc00 commit 0965cd5

File tree

10 files changed

+91
-25
lines changed

10 files changed

+91
-25
lines changed

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,57 @@
1-
# rsbuild-plugin-example
1+
# rsbuild-plugin-unplugin-vue
22

3-
Example plugin for Rsbuild.
3+
Rsbuild and Rslib plugin for [unplugin-vue](https://github.com/unplugin/unplugin-vue).
4+
5+
This plugin could be used with Rsbuild project as an alternative to [@rsbuild/plugin-vue](https://rsbuild.dev/guide/framework/vue).
6+
7+
This plugin is recommended for projects using Rslib to build Vue components.
8+
9+
> [!CAUTION]
10+
> HMR is not supported with Rsbuild yet. Track the issue [here](https://github.com/unplugin/unplugin-vue/issues/162). This plugin is mainly used for building Vue components with Rslib as of now.
411
512
<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" />
13+
<a href="https://npmjs.com/package/rsbuild-plugin-unplugin-vue">
14+
<img src="https://img.shields.io/npm/v/rsbuild-plugin-unplugin-vue?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
815
</a>
916
<img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
10-
<a href="https://npmcharts.com/compare/rsbuild-plugin-example?minimal=true"><img src="https://img.shields.io/npm/dm/rsbuild-plugin-example.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
17+
<a href="https://npmcharts.com/compare/rsbuild-plugin-unplugin-vue?minimal=true"><img src="https://img.shields.io/npm/dm/rsbuild-plugin-unplugin-vue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
1118
</p>
1219

1320
## Usage
1421

1522
Install:
1623

1724
```bash
18-
npm add rsbuild-plugin-example -D
25+
npm add rsbuild-plugin-unplugin-vue -D
1926
```
2027

2128
Add plugin to your `rsbuild.config.ts`:
2229

2330
```ts
24-
// rsbuild.config.ts
25-
import { pluginExample } from "rsbuild-plugin-example";
31+
// rsbuild.config.ts / rslib.config.ts
32+
import { pluginUnpluginVue } from 'rsbuild-plugin-unplugin-vue'
2633

2734
export default {
28-
plugins: [pluginExample()],
29-
};
35+
plugins: [pluginUnpluginVue()],
36+
}
3037
```
3138

3239
## Options
3340

34-
### foo
41+
### unpluginVueOptions
3542

3643
Some description.
3744

38-
- Type: `string`
45+
- Type: `import('unplugin-vue/api').Options`
3946
- Default: `undefined`
4047
- Example:
4148

4249
```js
43-
pluginExample({
44-
foo: "bar",
45-
});
50+
pluginUnpluginVue({
51+
unpluginVueOptions: {
52+
include: ['**/*.vue'],
53+
},
54+
})
4655
```
4756

4857
## License

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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": "rslib build",
2022
"dev": "rslib build --watch",
@@ -35,7 +37,8 @@
3537
"@types/node": "^22.15.3",
3638
"playwright": "^1.52.0",
3739
"simple-git-hooks": "^2.13.0",
38-
"typescript": "^5.8.3"
40+
"typescript": "^5.8.3",
41+
"vue": "^3.5.13"
3942
},
4043
"peerDependencies": {
4144
"@rsbuild/core": ">= 1.3.19"

pnpm-lock.yaml

Lines changed: 3 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: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { Options } from 'unplugin-vue/api';
33
import { parseVueRequest } from 'unplugin-vue/api';
44
import RspackPluginVue from 'unplugin-vue/rspack';
55

6-
// const require = createRequire(import.meta.url);
7-
86
export type PluginUnpluginVueOptions = {
97
unpluginVueOptions?: Options;
108
};

test/basic/index.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { dirname } from 'node:path';
22
import { fileURLToPath } from 'node:url';
33
import { expect, test } from '@playwright/test';
44
import { createRsbuild } from '@rsbuild/core';
5-
import { pluginExample } from '../../src';
5+
import { pluginUnpluginVue } from '../../src';
66
import { getRandomPort } from '../helper';
77

88
const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -11,7 +11,7 @@ test('should render page as expected', async ({ page }) => {
1111
const rsbuild = await createRsbuild({
1212
cwd: __dirname,
1313
rsbuildConfig: {
14-
plugins: [pluginExample()],
14+
plugins: [pluginUnpluginVue()],
1515
server: {
1616
port: getRandomPort(),
1717
},
@@ -21,7 +21,8 @@ test('should render page as expected', async ({ page }) => {
2121
const { server, urls } = await rsbuild.startDevServer();
2222

2323
await page.goto(urls[0]);
24-
expect(await page.evaluate('window.test')).toBe(1);
24+
const h1 = page.locator('h1');
25+
await expect(h1).toHaveText('Rsbuild with Vue');
2526

2627
await server.close();
2728
});
@@ -30,15 +31,19 @@ test('should build succeed', async ({ page }) => {
3031
const rsbuild = await createRsbuild({
3132
cwd: __dirname,
3233
rsbuildConfig: {
33-
plugins: [pluginExample()],
34+
plugins: [pluginUnpluginVue()],
35+
server: {
36+
port: getRandomPort(),
37+
},
3438
},
3539
});
3640

3741
await rsbuild.build();
3842
const { server, urls } = await rsbuild.preview();
3943

4044
await page.goto(urls[0]);
41-
expect(await page.evaluate('window.test')).toBe(1);
45+
const h1 = page.locator('h1');
46+
await expect(h1).toHaveText('Rsbuild with Vue');
4247

4348
await server.close();
4449
});

test/basic/src/App.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<template>
2+
<div class="content">
3+
<h1>Rsbuild with Vue</h1>
4+
<p>Start building amazing things with Rsbuild.</p>
5+
</div>
6+
</template>
7+
8+
<style scoped>
9+
.content {
10+
display: flex;
11+
min-height: 100vh;
12+
line-height: 1.1;
13+
text-align: center;
14+
flex-direction: column;
15+
justify-content: center;
16+
}
17+
18+
.content h1 {
19+
font-size: 3.6rem;
20+
font-weight: 700;
21+
}
22+
23+
.content p {
24+
font-size: 1.2rem;
25+
font-weight: 400;
26+
opacity: 0.5;
27+
}
28+
</style>

test/basic/src/env.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference types="@rsbuild/core/types" />
2+
3+
declare module '*.vue' {
4+
import type { DefineComponent } from 'vue';
5+
6+
// biome-ignore lint/complexity/noBannedTypes: reason
7+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
8+
const component: DefineComponent<{}, {}, any>;
9+
export default component;
10+
}

test/basic/src/index.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}

test/basic/src/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/basic/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createApp } from 'vue';
2+
import App from './App.vue';
3+
import './index.css';
4+
5+
createApp(App).mount('#root');

0 commit comments

Comments
 (0)