Skip to content

Commit a0cc187

Browse files
authored
docs: update documentation (#233)
1 parent 8377e5a commit a0cc187

File tree

11 files changed

+383
-424
lines changed

11 files changed

+383
-424
lines changed
Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,116 @@
11
---
2-
titleSuffix: "Esmx Framework High-Performance Build Engine"
3-
description: "Deep dive into Esmx framework's Rspack build system, including high-performance compilation, multi-environment builds, resource optimization, and other core features to help developers build efficient and reliable modern Web applications."
2+
title: "Rspack"
3+
description: "Learn how to use the Rspack builder encapsulated by Esmx to quickly create HTML and Vue applications, and how to support any front-end framework like React, Svelte, etc. by extending the configuration."
44
head:
55
- - "meta"
66
- name: "keywords"
7-
content: "Esmx, Rspack, build system, high-performance compilation, hot reload, multi-environment builds, Tree Shaking, code splitting, SSR, resource optimization, development efficiency, build tool"
7+
content: "Esmx,Rspack,build system,HTML application,standard application,multi-target build,SSR,HMR,SWC,LightningCSS,Loader,DefinePlugin,ImportMap,Module Link,external,content hash,performance optimization"
88
---
99

1010
# Rspack
1111

12-
Esmx is implemented based on the [Rspack](https://rspack.dev/) build system, fully utilizing Rspack's high-performance build capabilities. This document introduces Rspack's positioning and core features in the Esmx framework.
12+
Esmx uses [Rspack](https://www.rspack.dev/) as its default high-performance build engine. Developed in Rust, Rspack offers excellent build performance and a Webpack-compatible ecosystem, providing Esmx applications with an extremely fast development experience and efficient packaging capabilities.
1313

14-
## Features
14+
To simplify the build configuration for different types of applications, Esmx provides a series of encapsulated Rspack builders. The following is a detailed introduction to these builders and their use cases.
1515

16-
Rspack is the core build system of the Esmx framework, providing the following key features:
16+
## Builders
1717

18-
- **High-Performance Builds**: Build engine based on Rust implementation, providing extremely fast compilation performance, significantly improving build speed for large projects
19-
- **Development Experience Optimization**: Supports modern development features like hot reload (HMR) and incremental compilation, providing a smooth development experience
20-
- **Multi-Environment Builds**: Unified build configuration supports client, server, and Node.js environments, simplifying multi-end development workflows
21-
- **Resource Optimization**: Built-in resource processing and optimization capabilities, supporting features like code splitting, Tree Shaking, and resource compression
18+
Esmx provides a series of hierarchical builders for users to choose and extend according to their needs:
19+
- `createRspackApp`: The most basic builder, providing the core Rspack configuration.
20+
- `createRspackHtmlApp`: Inherits from `createRspackApp`, specifically for building traditional HTML applications, with built-in HTML generation and resource injection capabilities.
21+
- `createRspackVue2App` / `createRspackVue3App`: Inherit from `createRspackHtmlApp`, used for building Vue 2 and Vue 3 applications respectively, integrating Vue loader, HMR, and SSR support.
2222

23-
## Building Applications
23+
For detailed API of the builders, please refer to [Rspack Build API](/api/app/rspack).
2424

25-
Esmx's Rspack build system adopts a modular design, mainly including the following core modules:
25+
## HTML
2626

27-
### @esmx/rspack
27+
- Used for building traditional multi-page (MPA) or single-page applications (SPA) with HTML as the entry point.
2828

29-
Basic build module, providing the following core capabilities:
30-
31-
- **Unified Build Configuration**: Provides standardized build configuration management, supporting multi-environment configuration
32-
- **Resource Processing**: Built-in processing capabilities for TypeScript, CSS, images, and other resources
33-
- **Build Optimization**: Provides performance optimization features like code splitting and Tree Shaking
34-
- **Development Server**: Integrated high-performance development server, supporting HMR
35-
36-
### @esmx/rspack-vue
29+
```ts title="src/entry.node.ts"
30+
import type { EsmxOptions } from '@esmx/core';
3731

38-
Vue framework-specific build module, providing:
32+
export default {
33+
async devApp(esmx) {
34+
return import('@esmx/rspack').then(m =>
35+
m.createRspackHtmlApp(esmx, {
36+
chain({ chain }) {
37+
// Customize Rspack configuration here through the chain object
38+
}
39+
})
40+
);
41+
}
42+
} satisfies EsmxOptions;
43+
```
3944

40-
- **Vue Component Compilation**: Supports efficient compilation of Vue 2/3 components
41-
- **SSR Optimization**: Specific optimizations for Server-Side Rendering scenarios
42-
- **Development Enhancements**: Specific feature enhancements for Vue development environment
45+
## Vue
4346

44-
## Build Process
47+
Esmx provides first-class out-of-the-box support for the Vue ecosystem. Whether it is Vue 2 or Vue 3, developers can get a complete build experience including CSR and SSR.
4548

46-
Esmx's build process mainly includes the following stages:
49+
### Vue 3
4750

48-
1. **Configuration Initialization**
49-
- Load project configuration
50-
- Merge default and user configurations
51-
- Adjust configuration based on environment variables
51+
- Used for quickly building Vue 3 applications, with complete built-in support for CSR and SSR.
5252

53-
2. **Resource Compilation**
54-
- Parse source code dependencies
55-
- Transform various resources (TypeScript, CSS, etc.)
56-
- Handle module imports and exports
53+
```ts title="src/entry.node.ts"
54+
import type { EsmxOptions } from '@esmx/core';
5755

58-
3. **Optimization Processing**
59-
- Execute code splitting
60-
- Apply Tree Shaking
61-
- Compress code and resources
56+
export default {
57+
async devApp(esmx) {
58+
return import('@esmx/rspack-vue').then(m =>
59+
m.createRspackVue3App(esmx, {
60+
chain({ chain }) {
61+
// Customize Rspack configuration here through the chain object
62+
}
63+
})
64+
);
65+
}
66+
} satisfies EsmxOptions;
67+
```
6268

63-
4. **Output Generation**
64-
- Generate target files
65-
- Output resource mappings
66-
- Generate build reports
69+
### Vue 2.7
6770

68-
## Best Practices
71+
- Used for quickly building Vue 2.7 applications, with complete built-in support for CSR and SSR.
6972

70-
### Development Environment Optimization
73+
```ts title="src/entry.node.ts"
74+
import type { EsmxOptions } from '@esmx/core';
7175

72-
- **Incremental Compilation Configuration**: Properly configure `cache` option, utilize caching to speed up builds
73-
- **HMR Optimization**: Targetedly configure hot reload scope, avoid unnecessary module updates
74-
- **Resource Processing Optimization**: Use appropriate loader configuration, avoid duplicate processing
76+
export default {
77+
async devApp(esmx) {
78+
return import('@esmx/rspack-vue').then(m =>
79+
m.createRspackVue2App(esmx, {
80+
chain({ chain }) {
81+
// Customize Rspack configuration here through the chain object
82+
}
83+
})
84+
);
85+
}
86+
} satisfies EsmxOptions;
87+
```
7588

76-
### Production Environment Optimization
89+
## Adapting to Front-end Frameworks
7790

78-
- **Code Splitting Strategy**: Properly configure `splitChunks`, optimize resource loading
79-
- **Resource Compression**: Enable appropriate compression configuration, balance build time and artifact size
80-
- **Caching Optimization**: Utilize content hashing and long-term caching strategies to improve loading performance
91+
Esmx's builders are highly extensible. Developers can easily integrate various front-end frameworks such as React, Solid, and Svelte by configuring the corresponding compilers (such as Babel Loader or framework-specific loaders) based on `createRspackHtmlApp`.
8192

82-
## Configuration Example
93+
The integration of all frameworks can be done uniformly through the `chain` function. The following example shows the entry point for custom configuration:
8394

8495
```ts title="src/entry.node.ts"
8596
import type { EsmxOptions } from '@esmx/core';
8697

8798
export default {
88-
async devApp(esmx) {
89-
return import('@esmx/rspack').then((m) =>
90-
m.createRspackHtmlApp(esmx, {
91-
// Custom build configuration
92-
config({ config }) {
93-
}
94-
})
95-
);
96-
},
99+
async devApp(esmx) {
100+
return import('@esmx/rspack').then(m =>
101+
m.createRspackHtmlApp(esmx, {
102+
chain({ chain }) {
103+
// Customize Rspack configuration here through the chain object
104+
// to meet the build requirements of a specific framework.
105+
}
106+
})
107+
);
108+
}
97109
} satisfies EsmxOptions;
98110
```
99111

100-
::: tip
101-
For more detailed API instructions and configuration options, please refer to [Rspack API Documentation](/api/app/rspack.html).
102-
:::
112+
## Decoupling of Build Tools
113+
114+
Esmx implements the decoupling of build tools. Whether using Rspack, Webpack, Vite, or esbuild, as long as its build output contains a resource manifest that complies with the [ManifestJson specification](/api/core/manifest-json), Esmx can recognize and link these modules.
115+
116+
This design gives developers full freedom of technology selection, allowing them to choose the most suitable build solution for different scenarios without being locked into a specific toolchain.

examples/docs/src/en/guide/start/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"glossary",
44
"environment",
55
"getting-started"
6-
]
6+
]
Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
titleSuffix: "Environment and Compatibility"
3-
description: "Esmx environment requirements and compatibility notes, covering prerequisites and selection strategies for both Node.js and browser sides."
3+
description: "Details on Esmx's environment requirements and compatibility, covering prerequisites for both Node.js and browsers."
44
head:
55
- - "meta"
66
- name: "keywords"
@@ -9,59 +9,53 @@ head:
99

1010
# Environment Requirements
1111

12-
This document describes the environment requirements for using this framework, including Node.js environment and browser compatibility.
12+
This document describes the environment requirements for using this framework, including the Node.js environment and browser compatibility.
1313

1414
## Node.js Environment
1515

1616
Requires Node.js version `>= 24`.
1717

18-
::: warning Note
19-
Lower versions (< 24) are not supported. Installing dependencies will fail.
18+
::: warning Warning
19+
Versions below 24 are not supported; installing dependencies will fail.
2020
:::
2121

2222
## Browser Compatibility
2323

24-
The compatibility strategy has two modes:
25-
- Compatibility mode: Provides backward compatibility for dynamic imports and `import.meta` through es-module-shims.
26-
- Native Import Maps mode: Relies on native browser Import Maps capability.
24+
The compatibility strategy is divided into two modes:
25+
- Compatibility Mode: Provides backward compatibility for dynamic imports and `import.meta` via es-module-shims.
26+
- Native Import Maps Mode: Relies on the browser's native Import Maps capability.
2727

2828
### Compatibility Mode (Default)
2929

3030
| Browser | Minimum Version |
31-
|---------|-----------------|
31+
|-------|----------|
3232
| Chrome | >= 64 |
3333
| Edge | >= 79 |
3434
| Firefox| >= 67 |
3535
| Safari | >= 11.1 |
3636

37-
Data sources: Can I Use (Dynamic Import and `import.meta`), retrieval date: 2025-11.
37+
Data source: Can I Use (Dynamic Import and `import.meta`), retrieved November 2025.
3838

39-
### Native Import Maps Mode
40-
41-
| Browser | Minimum Version |
42-
|---------|-----------------|
43-
| Chrome | >= 89 |
44-
| Edge | >= 89 |
45-
| Firefox| >= 108 |
46-
| Safari | >= 16.4 |
47-
48-
Data sources: Can I Use (Import Maps), retrieval date: 2025-11.
49-
50-
### Enabling Compatibility Support
51-
52-
::: warning Note
53-
54-
To support older browsers, please add [es-module-shims](https://github.com/guybedford/es-module-shims) to your project.
55-
56-
:::
39+
To enable compatibility mode, you need to add the [es-module-shims](https://github.com/guybedford/es-module-shims) script to your HTML. It polyfills features like dynamic import and `import.meta`.
5740

5841
```html
59-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.0.10/dist/es-module-shims.js"></script>
42+
<script async src="https://unpkg.com/es-module-shims/dist/es-module-shims.js"></script>
6043
```
6144

6245
::: tip Recommendation
6346

64-
- In production, deploy scripts to your own server.
65-
- Enable compatibility mode based on your target users' browser distribution.
47+
- For production stability, we recommend hosting this script on your own server or CDN.
48+
- Before enabling this mode, consider the trade-offs between compatibility and cost, based on your target users' browser demographics.
6649

6750
:::
51+
52+
### Native Import Maps Mode
53+
54+
| Browser | Minimum Version |
55+
|-------|----------|
56+
| Chrome | >= 89 |
57+
| Edge | >= 89 |
58+
| Firefox| >= 108 |
59+
| Safari | >= 16.4 |
60+
61+
Data source: Can I Use (Import Maps), retrieved November 2025.

0 commit comments

Comments
 (0)