Skip to content

Commit 2a071f3

Browse files
committed
feat: add vanilla example
1 parent 3533080 commit 2a071f3

10 files changed

Lines changed: 140 additions & 0 deletions

File tree

examples/vanilla/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@examples/vanilla",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "rs build",
7+
"dev": "rs dev",
8+
"test": "rs test",
9+
"preview": "rs preview"
10+
},
11+
"devDependencies": {
12+
"@rsbuild/core": "catalog:",
13+
"@rstest/adapter-rsbuild": "catalog:",
14+
"@rstest/core": "catalog:",
15+
"@testing-library/dom": "catalog:",
16+
"@testing-library/jest-dom": "catalog:",
17+
"@types/node": "catalog:",
18+
"happy-dom": "catalog:",
19+
"rstack": "workspace:*",
20+
"typescript": "catalog:"
21+
}
22+
}

examples/vanilla/rsbuild.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
3+
export default defineConfig({});

examples/vanilla/rstest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { withRsbuildConfig } from '@rstest/adapter-rsbuild';
2+
import { defineConfig } from '@rstest/core';
3+
4+
export default defineConfig({
5+
extends: withRsbuildConfig(),
6+
setupFiles: ['./tests/rstest.setup.ts'],
7+
});

examples/vanilla/src/index.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}
7+
8+
.content {
9+
display: flex;
10+
min-height: 100vh;
11+
line-height: 1.1;
12+
text-align: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
}
16+
17+
.content h1 {
18+
font-size: 3.6rem;
19+
font-weight: 700;
20+
}
21+
22+
.content p {
23+
font-size: 1.2rem;
24+
font-weight: 400;
25+
opacity: 0.5;
26+
}

examples/vanilla/src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import './index.css';
2+
3+
const rootEl = document.querySelector('#root');
4+
if (rootEl) {
5+
rootEl.innerHTML = `
6+
<div class="content">
7+
<h1>Vanilla Rsbuild</h1>
8+
<p>Start building amazing things with Rsbuild.</p>
9+
</div>
10+
`;
11+
}

examples/vanilla/tests/dom.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect, test } from '@rstest/core';
2+
import { screen } from '@testing-library/dom';
3+
4+
test('test dom', () => {
5+
document.body.innerHTML = `
6+
<span data-testid="not-empty"><span data-testid="empty"></span></span>
7+
<div data-testid="visible">Visible Example</div>
8+
`;
9+
10+
expect(screen.queryByTestId('not-empty')).toBeInTheDocument();
11+
expect(screen.getByText('Visible Example')).toBeVisible();
12+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from '@rstest/core';
2+
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';
3+
4+
expect.extend(jestDomMatchers);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["@testing-library/jest-dom"]
5+
},
6+
"include": ["./"]
7+
}

examples/vanilla/tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["DOM", "ES2020"],
4+
"target": "ES2020",
5+
"noEmit": true,
6+
"skipLibCheck": true,
7+
"types": ["@rsbuild/core/types", "node"],
8+
"useDefineForClassFields": true,
9+
"moduleDetection": "force",
10+
"moduleResolution": "bundler",
11+
"verbatimModuleSyntax": true,
12+
"resolveJsonModule": true,
13+
"allowImportingTsExtensions": true,
14+
"noUnusedLocals": true,
15+
"noUnusedParameters": true
16+
},
17+
"include": ["src"]
18+
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)