You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/rolldown.md
+101Lines changed: 101 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -91,3 +91,104 @@ For real-time discussions and troubleshooting, make sure to join the [Rolldown D
91
91
The `rolldown-vite` package is a temporary solution to gather feedback and stabilize the Rolldown integration. In the future, this functionality will be merged back into the main Vite repository.
92
92
93
93
We encourage you to try out `rolldown-vite` and contribute to its development through feedback and issue reports.
94
+
95
+
## Plugin / Framework authors guide
96
+
97
+
### The list of big changes
98
+
99
+
- Rolldown is used for build (Rollup was used before)
100
+
- Rolldown is used for the optimizer (esbuild was used before)
101
+
- CommonJS support is handled by Rolldown (@rollup/plugin-commonjs was used before)
102
+
- Oxc is used for syntax lowering (esbuild was used before)
103
+
- Lightning CSS is used for CSS minification by default (esbuild was used before)
104
+
- Oxc minifier is used for JS minification by default (esbuild was used before)
105
+
- Rolldown is used for bundling the config (esbuild was used before)
106
+
107
+
### Detecting rolldown-vite
108
+
109
+
You can detect by either
110
+
111
+
- checking the `this.meta.rolldownVersion` existence
112
+
113
+
```js
114
+
constplugin= {
115
+
resolveId() {
116
+
if (this.meta.rolldownVersion) {
117
+
// logic for rolldown-vite
118
+
} else {
119
+
// logic for rollup-vite
120
+
}
121
+
},
122
+
}
123
+
```
124
+
125
+
- checking the `rolldownVersion` export existence
126
+
127
+
```js
128
+
import*asvitefrom'vite'
129
+
130
+
if (vite.rolldownVersion) {
131
+
// logic for rolldown-vite
132
+
} else {
133
+
// logic for rollup-vite
134
+
}
135
+
```
136
+
137
+
If you have `vite` as a dependency (not a peer dependency), the `rolldownVersion` export is useful as it can be used from anywhere in your code.
138
+
139
+
### Ignoring option validation in Rolldown
140
+
141
+
Rolldown throws an error when unknown or invalid options are passed. Because some options available in Rollup are not supported by Rolldown, you may encounter errors. Below, you can find an an example of such an error message:
142
+
143
+
> Error: Failed validate input options.
144
+
>
145
+
> - For the "preserveEntrySignatures". Invalid key: Expected never but received "preserveEntrySignatures".
146
+
147
+
This can be fixed by conditionally passing the option by checking whether it's running with `rolldown-vite` as shown above.
148
+
149
+
If you would like to suppress this error for now, you can set the `ROLLDOWN_OPTIONS_VALIDATION=loose` environment variable. However, keep in mind that you will eventually need to stop passing the options not supported by Rolldown.
150
+
151
+
### `transformWithEsbuild` requires `esbuild` to be installed separately
152
+
153
+
A similar function called `transformWithOxc`, which uses Oxc instead of `esbuild`, is exported from `rolldown-vite`.
154
+
155
+
### Compatibility layer for `esbuild` options
156
+
157
+
Rolldown-Vite has a compatibility layer to convert options for `esbuild` to the respective Oxc or `rolldown` ones. As tested in [the ecosystem-ci](https://github.com/vitejs/vite-ecosystem-ci/blob/rolldown-vite/README-temp.md), this works in many cases, including simple `esbuild` plugins.
158
+
That said, **we'll be removing the `esbuild` options support in the future** and encourage you to try the corresponding Oxc or `rolldown` options.
159
+
You can get the options set by the compatibility layer from the `configResolved` hook.
Rolldown introduced a [hook filter feature](https://rolldown.rs/guide/plugin-development#plugin-hook-filters) to reduce the communication overhead the between Rust and JavaScript runtimes. By using this feature you can make your plugin more performant.
173
+
This is also supported by Rollup 4.38.0+ and Vite 6.3.0+. To make your plugin backward compatible with the older versions, make sure to also run the filter inside the hook handlers.
174
+
175
+
### Converting content to JavaScript in `load` or `transform` hooks
176
+
177
+
If you are converting the content to JavaScript from other types in `load` or `transform` hooks, you may need to add `moduleType: 'js'` to the returned value.
178
+
179
+
```js
180
+
constplugin= {
181
+
name:'txt-loader',
182
+
load(id) {
183
+
if (id.endsWith('.txt')) {
184
+
constcontent=fs.readFile(id, 'utf-8')
185
+
return {
186
+
code:`export default ${JSON.stringify(content)}`,
187
+
moduleType:'js', // [!code ++]
188
+
}
189
+
}
190
+
},
191
+
}
192
+
```
193
+
194
+
This is because [Rolldown supports non-JavaScript modules](https://rolldown.rs/guide/in-depth/module-types) and infers the module type from extensions unless specified. Note that `rolldown-vite` does not support ModuleTypes in dev.
0 commit comments