Skip to content

Commit 20198ac

Browse files
authored
build: support UMD bundle (#44)
1 parent 77de988 commit 20198ac

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

docs/pages/en-US/docs/introduction.mdx

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import { Callout } from "nextra/components";
1111

1212
Inside your project, run the following:
1313

14-
```shell
15-
pnpm install @wendellhu/redi
16-
```
17-
18-
or use other package managers such as npm:
19-
20-
```shell
14+
```shell npm2yarn
2115
npm install @wendellhu/redi
2216
```
2317

@@ -99,4 +93,37 @@ Then you get an instance of `FileListService`, and its dependency `AuthService`
9993
const authService = injector.get(FileListService);
10094
```
10195

102-
Read the next chapter to learn basic concepts in dependency injection.
96+
Read the [next chapter](/en-US/docs/concepts) to learn basic concepts in dependency injection.
97+
98+
## Using redi with CDN
99+
100+
You can also use redi via CDN if you don't want to use npm or yarn.
101+
102+
Include the following `<script>` tag in your HTML file:
103+
104+
```html
105+
<script src="https://unpkg.com/@wendellhu/redi/dist/umd/index.js"></script>
106+
```
107+
108+
Redi will be mounted on the global variable `@wendellhu/redi`, and you can access it via `window["@wendellhu/redi"]`.
109+
110+
<Callout>
111+
Here we use [UNPKG](https://unpkg.com) as the CDN service. You can also choose other CDN services that host npm packages, such as [jsDelivr](https://www.jsdelivr.com).
112+
</Callout>
113+
114+
If you want to use redi with React, you can include the following `<script>` tag:
115+
116+
```html
117+
<script src="https://unpkg.com/@wendellhu/redi/dist/umd/react-bindings/index.js"></script>
118+
```
119+
120+
Redi's React API will be mounted on the global variable `@wendellhu/redi/react-bindings`, and you can access it via `window["@wendellhu/redi/react-bindings"]`.
121+
122+
If you are using React 19, you should import the React bindings using [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules):
123+
124+
```html
125+
<script type="module">
126+
import { Inject, Injector } from "https://unpkg.com/@wendellhu/redi/dist/esm/index.js";
127+
import { connectDependencies } from "https://unpkg.com/@wendellhu/redi/dist/esm/react-bindings/index.js";
128+
</script>
129+
```

rolldown.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export default defineConfig([
2121
sourcemap: true,
2222
},
2323
},
24+
{
25+
input: 'src/index.ts',
26+
external: ['@wendellhu/redi', 'react', 'react/jsx-runtime', 'rxjs'],
27+
output: {
28+
file: 'dist/umd/index.js',
29+
format: 'umd',
30+
name: '@wendellhu/redi',
31+
sourcemap: true,
32+
},
33+
},
2434
{
2535
input: 'src/react-bindings/index.ts',
2636
external: ['@wendellhu/redi', 'react', 'react/jsx-runtime', 'rxjs'],
@@ -40,4 +50,20 @@ export default defineConfig([
4050
sourcemap: true,
4151
},
4252
},
53+
{
54+
input: 'src/react-bindings/index.ts',
55+
external: ['@wendellhu/redi', 'react', 'react/jsx-runtime', 'rxjs'],
56+
output: {
57+
file: 'dist/umd/react-bindings/index.js',
58+
format: 'umd',
59+
name: '@wendellhu/redi/react-bindings',
60+
sourcemap: true,
61+
globals: {
62+
react: 'React',
63+
'react/jsx-runtime': 'React',
64+
rxjs: 'rxjs',
65+
'@wendellhu/redi': '@wendellhu/redi',
66+
},
67+
},
68+
},
4369
]);

0 commit comments

Comments
 (0)