Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions docs/guide/api-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ export default function myPlugin() {
return {
name: 'transform-file',

transform(src, id) {
if (fileRegex.test(id)) {
transform: {
filter: {
id: fileRegex,
},
handler(src, id) {
return {
code: compileFileToJS(src),
map: null, // provide source map if available
}
}
},
},
}
}
Expand All @@ -110,21 +113,25 @@ See the example in the [next section](#virtual-modules-convention).
Virtual modules are a useful scheme that allows you to pass build time information to the source files using normal ESM import syntax.

```js
import { exactRegex } from '@rolldown/pluginutils'

export default function myPlugin() {
const virtualModuleId = 'virtual:my-module'
const resolvedVirtualModuleId = '\0' + virtualModuleId

return {
name: 'my-plugin', // required, will show up in warnings and errors
resolveId(id) {
if (id === virtualModuleId) {
resolveId: {
filter: { id: exactRegex(virtualModuleId) },
handler() {
return resolvedVirtualModuleId
}
},
},
load(id) {
if (id === resolvedVirtualModuleId) {
load: {
filter: { id: exactRegex(resolvedVirtualModuleId) },
handler() {
return `export const msg = "from virtual module"`
}
},
},
}
}
Expand Down