Used to build outputs in UMD format.
UMD stands for Universal Module Definition, which is a module specification that is compatible with AMD, CommonJS, and global variable definition. UMD outputs refer to modules that follow the UMD specification, allowing them to be loaded and used in different environments, including browser and Node.js.
You can install the plugin using the following command:
You can register the plugin in the rsbuild.config.ts file:
For instance, the project contains the following code:
When using the UMD plugin, Rsbuild will generate a dist/index.js file in UMD format.
require, for example:name is a required field used to specify the name of the UMD library, corresponding to Rspack's output.library.name option.
stringSpecifies which export to use as the content of the UMD library. By default, export is undefined, which exports the whole namespace object.
string | string[]undefinedexport is configured as default, accessing window.foo will give you the content exported by export default.output.library.export, and the array will be interpreted as an access path.By default, the UMD plugin will output a dist/index.js file. You can modify the name of the output file through Rsbuild's output.filename option.
For example, output a dist/myLib.js file:
You can run the rsbuild dev command to debug UMD outputs in the browser.
First, create src/index.html and add the following code:
Then, specify the template in rsbuild.config.ts:
Finally, run npx rsbuild dev to start.