Skip to content

Commit f74d2a9

Browse files
committed
chore: add Preact example
1 parent 5871389 commit f74d2a9

File tree

16 files changed

+215
-35
lines changed

16 files changed

+215
-35
lines changed

examples/express-plugin/rslib.config.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
import { defineConfig } from '@rslib/core';
22

3-
const shared = {
4-
dts: {
5-
bundle: false,
6-
},
7-
};
8-
93
export default defineConfig({
104
lib: [
115
{
12-
...shared,
136
format: 'esm',
7+
dts: true,
148
output: {
159
distPath: {
1610
root: './dist/esm',
1711
},
1812
},
1913
},
2014
{
21-
...shared,
2215
format: 'cjs',
16+
dts: true,
2317
output: {
2418
distPath: {
2519
root: './dist/cjs',

examples/module-federation/mf-react-component/rslib.config.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,29 @@ import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
22
import { pluginReact } from '@rsbuild/plugin-react';
33
import { defineConfig } from '@rslib/core';
44

5-
const shared = {
6-
dts: {
7-
bundle: false,
8-
},
9-
};
10-
115
export default defineConfig({
126
lib: [
137
{
14-
...shared,
158
format: 'esm',
9+
dts: true,
1610
output: {
1711
distPath: {
1812
root: './dist/esm',
1913
},
2014
},
2115
},
2216
{
23-
...shared,
2417
format: 'cjs',
18+
dts: true,
2519
output: {
2620
distPath: {
2721
root: './dist/cjs',
2822
},
2923
},
3024
},
3125
{
32-
...shared,
3326
format: 'mf',
27+
dts: true,
3428
output: {
3529
distPath: {
3630
root: './dist/mf',
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @examples/preact-component
2+
3+
This example demonstrates how to use Rslib to build a simple Preact component.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@examples/preact-component-bundle-false",
3+
"private": true,
4+
"main": "./dist/cjs/index.js",
5+
"module": "./dist/esm/index.mjs",
6+
"types": "./dist/cjs/index.d.ts",
7+
"scripts": {
8+
"build": "rslib build"
9+
},
10+
"devDependencies": {
11+
"@rsbuild/plugin-preact": "^1.2.0",
12+
"@rsbuild/plugin-sass": "^1.1.1",
13+
"@rslib/core": "workspace:*",
14+
"preact": "^10.24.3"
15+
},
16+
"peerDependencies": {
17+
"preact": "*"
18+
}
19+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { pluginPreact } from '@rsbuild/plugin-preact';
2+
import { pluginSass } from '@rsbuild/plugin-sass';
3+
import { type LibConfig, defineConfig } from '@rslib/core';
4+
5+
export default defineConfig({
6+
source: {
7+
entry: {
8+
index: ['./src/**', '!./src/env.d.ts'],
9+
},
10+
},
11+
lib: [
12+
{
13+
bundle: false,
14+
dts: true,
15+
format: 'esm',
16+
output: {
17+
distPath: {
18+
root: './dist/esm',
19+
},
20+
},
21+
},
22+
{
23+
bundle: false,
24+
dts: true,
25+
format: 'cjs',
26+
output: {
27+
distPath: {
28+
root: './dist/cjs',
29+
},
30+
},
31+
},
32+
],
33+
output: {
34+
target: 'web',
35+
},
36+
plugins: [pluginPreact(), pluginSass()],
37+
});
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { FunctionComponent } from 'preact';
2+
import styles from './index.module.scss';
3+
4+
interface CounterButtonProps {
5+
onClick: () => void;
6+
label: string;
7+
}
8+
9+
export const CounterButton: FunctionComponent<CounterButtonProps> = ({
10+
onClick,
11+
label,
12+
}) => (
13+
<button type="button" className={styles.button} onClick={onClick}>
14+
{label}
15+
</button>
16+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.module.scss' {
2+
const classes: { [key: string]: string };
3+
export default classes;
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.counter-text {
2+
font-size: 50px;
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { FunctionComponent } from 'preact';
2+
import { CounterButton } from './components/CounterButton/index';
3+
import { useCounter } from './useCounter';
4+
import './index.scss';
5+
6+
export const Counter: FunctionComponent = () => {
7+
const { count, increment, decrement } = useCounter();
8+
9+
return (
10+
<div>
11+
<h2 className="counter-text">Counter: {count}</h2>
12+
<CounterButton onClick={decrement} label="-" />
13+
<CounterButton onClick={increment} label="+" />
14+
</div>
15+
);
16+
};

0 commit comments

Comments
 (0)