Skip to content

Commit 415b868

Browse files
docs: solutions overview / output compatibility (#376)
Co-authored-by: Timeless0911 <[email protected]>
1 parent 4f736f4 commit 415b868

File tree

11 files changed

+87
-18
lines changed

11 files changed

+87
-18
lines changed
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
[
2-
"package-json",
32
"third-party-deps",
4-
"polyfill",
3+
"output-compatibility",
4+
"dts",
55
"css",
66
"assets",
7-
"dts",
87
"module-federation",
9-
"node-polyfill",
108
"storybook"
119
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
# CSS
2+
3+
## CSS Modules
4+
5+
## Pre-processors
6+
7+
### Sass
8+
9+
### Less
10+
11+
### Stylus
12+
13+
## PostCSS
14+
15+
## Tailwind CSS
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,44 @@
11
import { Steps, SourceCode } from '@theme';
22
import { PackageManagerTabs } from '@theme';
33

4-
# Node Polyfill
4+
# Output Compatibility
5+
6+
This chapter introduces how to specify which target environment should be supported.
7+
8+
## Syntax Downgrade
9+
10+
By setting [lib.syntax](/config/lib/syntax), you can choose the syntax to which JavaScript and CSS will be downgraded. You can use the query syntax from [Browserslist](https://browsersl.ist/). Rslib also supports common ECMAScript version numbers, such as `ES2015`.
11+
12+
Rslib also supports using a [.browserslistrc](https://github.com/browserslist/browserslist#config-file) file to specify settings. Note that [lib.syntax](/config/lib/syntax) takes precedence over `.browserslistrc`. If both are present, `lib.syntax` will be used.
13+
14+
By default, the syntax is set to `ESNext`, which will only supports only the latest version of mainstream browsers (Chrome / Firefox / Edge / macOS Safari / iOS Safari) or Node.js according to [output.target](/config/rsbuild/output#target).
15+
16+
## Polyfill
17+
18+
Before dealing with compatibility issues, it is recommended that you understand the following background knowledge to better handle related issues. Check out the background knowledge on [syntax transpilation and API polyfill](https://rsbuild.dev/guide/advanced/browser-compatibility#syntax-downgrade-and-api-downgrade).
19+
20+
### Browser
21+
22+
{/* TODO */}
23+
{/* Implement a Rsbuild polyfill plugin by using core-js-pure */}
24+
25+
### Node.js
526

627
:::tip About Node Polyfill
728
Normally, we don't need to use Node libs on the browser side. However, it is possible to use some Node libs when the code will run on both the Node side and the browser side, and Node Polyfill provides browser versions of polyfills for these Node libs.
829
:::
930

1031
By using [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill), Node core libs polyfills are automatically injected into the browser-side, allowing you to use these modules on the browser side with confidence.
1132

12-
## Getting Started
13-
14-
### Install plugin
33+
#### Set up
1534

1635
Rslib uses [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill) to provide the Node Polyfill feature.
1736

1837
<PackageManagerTabs command="@rsbuild/plugin-node-polyfill -D" />
1938

20-
### Register plugin
21-
2239
Then add the plugin into the plugins field.
2340

24-
```ts
41+
```ts title="rslib.config.ts"
2542
import { defineConfig } from '@rslib/core';
2643
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
2744

@@ -31,7 +48,7 @@ export default defineConfig({
3148
});
3249
```
3350

34-
### Setup
51+
#### Configurations
3552

3653
- For projects with `bundle` enabled, the Node Polyfill will be injected and included in the output.
3754
- For projects with `bundle` disabled, polyfills are not injected into the output by default. To avoid inlining the polyfill in every module. The modules are externalized and need to be added to dependencies manually, follow these steps:
@@ -41,6 +58,4 @@ export default defineConfig({
4158

4259
With the following steps, every usage of the polyfill module will be replaced by the corresponding module in the `externals` field. Checkout the <SourceCode href="https://github.com/web-infra-dev/rslib/blob/main/tests/integration/node-polyfill/bundle-false/rslib.config.ts" /> of the example for more details.
4360

44-
## Configurations
45-
4661
Check out the documentation of [@rsbuild/plugin-node-polyfill](https://github.com/rspack-contrib/rsbuild-plugin-node-polyfill), all the configurations are applicable for Rslib.

website/docs/en/guide/advanced/package-json.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.

website/docs/en/guide/advanced/polyfill.mdx

Lines changed: 0 additions & 1 deletion
This file was deleted.

website/docs/en/guide/advanced/third-party-deps.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Handle Third-party Dependencies
1+
# Handle Third-Party Dependencies
22

33
Generally, third-party dependencies required by a project can be installed via the `install` command in the package manager. After the third-party dependencies are successfully installed, they will generally appear under `dependencies` and `devDependencies` in the project `package.json`.
44

website/docs/en/guide/basic/output-format.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ESM from '../start/components/ESM.mdx';
22
import CJS from '../start/components/CJS.mdx';
33
import UMD from '../start/components/UMD.mdx';
4+
import MF from '../start/components/MF.mdx';
45

56
# Output Format
67

@@ -64,6 +65,8 @@ The community is migrating to ESM, but there are still many projects using CJS.
6465

6566
## UMD
6667

68+
### What is UMD?
69+
6770
<UMD />
6871

6972
### When to use UMD?
@@ -124,3 +127,15 @@ export default defineConfig({
124127
],
125128
});
126129
```
130+
131+
## MF
132+
133+
### What is MF?
134+
135+
MF stands for Module Federation. <MF />
136+
137+
### When to use MF?
138+
139+
### How to build a MF library?
140+
141+
Check out [Advanced - Module Federation](/guide/advanced/module-federation) chapter for more details.

website/docs/en/guide/solution.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
11
# Solution
2+
3+
In this chapter, we will introduce how to use Rslib to development libraries for browser and Node.js. We will also cover how to create libraries for different UI frameworks.
4+
5+
## Browser Target
6+
7+
Rslib outputs code for the browser by default, so no additional configuration is necessary to get started.
8+
9+
When developing a library that runs in the browser, you can package it in both [ESM](/guide/basic/output-format#esm--cjs) and [CJS](/guide/basic/output-format#esm--cjs) formats for integration with application bundlers. Configuring the package [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to ESM output allows for better tree shaking. Additionally, you can create [UMD](/guide/basic/output-format#umd) format output for direct browser use and even generate [Module Federation ](/guide/advanced/module-federation) formats for dynamic loading by other applications. Configure [Browserslist](/config/rsbuild/output#browserslist) according to the target browser support to determine the downgrade syntax of the output, or adding [polyfill](/guide/advanced/output-compatibility) for API compatibility.
10+
11+
When publishing to npm, you can choose not to [minify](/config/rsbuild/output#minify) your code or to minify it while providing a [sourcemap](/config/rsbuild/output#sourcemap) to enhance the debugging experience for users of your library. For styling, you can use [CSS](/guide/advanced/css), or [CSS pre-processors](/guide/advanced/css#preprocessors) like Sass, Less, or Stylus, or apply [PostCSS](/guide/advanced/css#postcss) for CSS post-processing. Tools like [Tailwind CSS](/guide/advanced/css#tailwind-css) can also help in building your styles. Using [CSS modules](/guide/advanced/css#css-modules) to create CSS modules is another option.
12+
13+
In terms of resource management, Rslib handles [static assets](/guide/advanced/assets) used in your code, such as SVG and PNG files. You can also build a component library of [React](/guide/solution/react), [Preact](/guide/solution/preact), or other frameworks, using [Storybook](/guide/advanced/storybook) for UI component development and testing.
14+
15+
Refer to the solutions in this chapter to learn how to use Rslib to develop browser libraries for different frameworks.
16+
17+
{/* TODO: Clarify default behavior */}
18+
{/* ### Default Behavior */}
19+
20+
## Node.js Target
21+
22+
By setting set [target](/config/rsbuild/output#target) to `"node"` to development libraries for Node.js.
23+
24+
You can create a [pure ESM](/guide/basic/output-format#esm--cjs) package or a [dual package](/guide/basic/output-format#esm--cjs) that supports both ESM and CJS as needed. In CJS output, `import.meta.url` will be automatically [shimmed](/config/lib/shims) for compatibility and `__dirname` and `__filename` got an optional ESM shims to ensure proper use across different module system. Node.js's built-in packages will be [externalized by default](/guide/advanced/third-party-deps), simplifying the configuration.
25+
26+
{/* TODO: Clarify default behavior */}
27+
{/* ### Default Behavior */}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Preact
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Module Federation is an architectural pattern for JavaScript application decomposition (similar to microservices on the server-side), allowing you to share code and resources between multiple JavaScript applications (or micro-frontends).

website/docs/en/guide/start/glossary.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ESM from './components/ESM.mdx';
22
import CJS from './components/CJS.mdx';
33
import UMD from './components/UMD.mdx';
4+
import MF from './components/MF.mdx';
45

56
# Glossary
67

@@ -22,7 +23,7 @@ Bundleless refers to a development approach that avoids the traditional practice
2223

2324
## Module Federation
2425

25-
Module Federation is an architectural pattern for JavaScript application decomposition (similar to microservices on the server-side), allowing you to share code and resources between multiple JavaScript applications (or micro-frontends).
26+
<MF />
2627

2728
See [Module Federation](https://rsbuild.dev/guide/advanced/module-federation) for more details.
2829

0 commit comments

Comments
 (0)