Skip to content

Commit e25864e

Browse files
authored
chore(example): add SolidJS (#944)
1 parent 2a5ff4e commit e25864e

File tree

12 files changed

+254
-0
lines changed

12 files changed

+254
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @examples/solid-component
2+
3+
This example demonstrates how to use Rslib to build a simple SolidJS component.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@examples/solid-component-bundle",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"main": "./dist/index.js",
7+
"module": "./dist/index.js",
8+
"types": "./dist/index.d.ts",
9+
"scripts": {
10+
"build": "rslib build"
11+
},
12+
"devDependencies": {
13+
"@rsbuild/plugin-sass": "^1.3.1",
14+
"@rsbuild/plugin-solid": "^1.0.5",
15+
"@rslib/core": "workspace:*",
16+
"solid-js": "^1.6.0",
17+
"typescript": "^5.8.3"
18+
},
19+
"peerDependencies": {
20+
"solid-js": "^1.0.0"
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { pluginSass } from '@rsbuild/plugin-sass';
2+
import { pluginSolid } from '@rsbuild/plugin-solid';
3+
import { defineConfig } from '@rslib/core';
4+
5+
export default defineConfig({
6+
lib: [
7+
{
8+
format: 'esm',
9+
dts: true,
10+
},
11+
],
12+
output: {
13+
target: 'web',
14+
},
15+
plugins: [pluginSolid(), pluginSass()],
16+
});
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.button {
2+
background: yellow;
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Component } from 'solid-js';
2+
import styles from './index.module.scss';
3+
4+
interface CounterButtonProps {
5+
onClick: () => void;
6+
label: string;
7+
}
8+
9+
export const CounterButton: Component<CounterButtonProps> = (props) => (
10+
<button
11+
type="button"
12+
onClick={props.onClick}
13+
classList={{ 'counter-button': true, [styles.button]: true }}
14+
>
15+
{props.label}
16+
</button>
17+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rslib/core/types" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.counter-title {
2+
width: 100px;
3+
height: 100px;
4+
background: no-repeat url('./assets/logo.svg');
5+
background-size: cover;
6+
}
7+
8+
.counter-text {
9+
font-size: 50px;
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Component } from 'solid-js';
2+
import { CounterButton } from './components/CounterButton';
3+
import { useCounter } from './useCounter';
4+
import './index.scss';
5+
6+
export const Counter: Component = () => {
7+
const { count, increment, decrement } = useCounter();
8+
9+
return (
10+
<div>
11+
<h1 class="counter-title">Solid</h1>
12+
<h2 class="counter-text">Counter: {count()}</h2>
13+
<CounterButton onClick={decrement} label="-" />
14+
<CounterButton onClick={increment} label="+" />
15+
</div>
16+
);
17+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createSignal } from 'solid-js';
2+
3+
export const useCounter = (initialValue = 0) => {
4+
const [count, setCount] = createSignal(initialValue);
5+
6+
const increment = () => setCount((prev) => prev + 1);
7+
const decrement = () => setCount((prev) => prev - 1);
8+
9+
return { count, increment, decrement };
10+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"jsx": "preserve",
6+
"jsxImportSource": "solid-js",
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"moduleResolution": "node",
12+
"baseUrl": "./src",
13+
"paths": {
14+
"@/*": ["*"]
15+
}
16+
},
17+
"include": ["src"],
18+
"exclude": ["node_modules", "dist"]
19+
}

pnpm-lock.yaml

Lines changed: 135 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)