|
1 | 1 | --- |
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." |
4 | 4 | head: |
5 | 5 | - - "meta" |
6 | 6 | - 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" |
8 | 8 | --- |
9 | 9 |
|
10 | 10 | # Rspack |
11 | 11 |
|
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. |
13 | 13 |
|
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. |
15 | 15 |
|
16 | | -Rspack is the core build system of the Esmx framework, providing the following key features: |
| 16 | +## Builders |
17 | 17 |
|
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. |
22 | 22 |
|
23 | | -## Building Applications |
| 23 | +For detailed API of the builders, please refer to [Rspack Build API](/api/app/rspack). |
24 | 24 |
|
25 | | -Esmx's Rspack build system adopts a modular design, mainly including the following core modules: |
| 25 | +## HTML |
26 | 26 |
|
27 | | -### @esmx/rspack |
| 27 | +- Used for building traditional multi-page (MPA) or single-page applications (SPA) with HTML as the entry point. |
28 | 28 |
|
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'; |
37 | 31 |
|
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 | +``` |
39 | 44 |
|
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 |
43 | 46 |
|
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. |
45 | 48 |
|
46 | | -Esmx's build process mainly includes the following stages: |
| 49 | +### Vue 3 |
47 | 50 |
|
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. |
52 | 52 |
|
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'; |
57 | 55 |
|
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 | +``` |
62 | 68 |
|
63 | | -4. **Output Generation** |
64 | | - - Generate target files |
65 | | - - Output resource mappings |
66 | | - - Generate build reports |
| 69 | +### Vue 2.7 |
67 | 70 |
|
68 | | -## Best Practices |
| 71 | +- Used for quickly building Vue 2.7 applications, with complete built-in support for CSR and SSR. |
69 | 72 |
|
70 | | -### Development Environment Optimization |
| 73 | +```ts title="src/entry.node.ts" |
| 74 | +import type { EsmxOptions } from '@esmx/core'; |
71 | 75 |
|
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 | +``` |
75 | 88 |
|
76 | | -### Production Environment Optimization |
| 89 | +## Adapting to Front-end Frameworks |
77 | 90 |
|
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`. |
81 | 92 |
|
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: |
83 | 94 |
|
84 | 95 | ```ts title="src/entry.node.ts" |
85 | 96 | import type { EsmxOptions } from '@esmx/core'; |
86 | 97 |
|
87 | 98 | 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 | + } |
97 | 109 | } satisfies EsmxOptions; |
98 | 110 | ``` |
99 | 111 |
|
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. |
0 commit comments