File tree Expand file tree Collapse file tree 2 files changed +0
-48
lines changed Expand file tree Collapse file tree 2 files changed +0
-48
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 11# UMD
2-
3- ## Introduction
4-
5- UMD is a library that can be used in both the browser and Node.js environments. It is a combination of CommonJS and AMD.
6-
7- ## How to build a UMD library?
8-
9- - Set the ` output.format ` to ` umd ` in the Rslib configuration file.
10- - If the library need to be exported with a name, set ` output.umdName ` to the name of the UMD library.
11- - Use ` output.externals ` to specify the external dependencies that the UMD library depends on, ` lib.autoExtension ` is enabled by default for UMD.
12-
13- ## Examples
14-
15- The following Rslib config is an example to build a UMD library.
16-
17- - ` output.format: 'umd' ` : instruct Rslib to build in UMD format.
18- - ` output.umdName: 'RslibUmdExample' ` : set the export name of the UMD library.
19- - ` output.externals.react: 'React' ` : specify the external dependency ` react ` could be accessed by ` window.React ` .
20- - ` runtime: 'classic' ` : use the classic runtime of React to support applications that using React version under 18.
21-
22- ``` ts title="rslib.config.ts" {7-12,22}
23- import { pluginReact } from ' @rsbuild/plugin-react' ;
24- import { defineConfig } from ' @rslib/core' ;
25-
26- export default defineConfig ({
27- lib: [
28- {
29- format: ' umd' ,
30- umdName: ' RslibUmdExample' ,
31- output: {
32- externals: {
33- react: ' React' ,
34- },
35- distPath: {
36- root: ' ./dist/umd' ,
37- },
38- },
39- },
40- ],
41- plugins: [
42- pluginReact ({
43- swcReactOptions: {
44- runtime: ' classic' ,
45- },
46- }),
47- ],
48- });
49- ```
You can’t perform that action at this time.
0 commit comments