wasmHelperPlugin() — vite Function Reference
Architecture documentation for the wasmHelperPlugin() function in wasm.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 488c94be_f327_5956_a885_8d97686ca66e["wasmHelperPlugin()"] d496a62e_d9d8_41d4_a984_96f1dbd5f4bd["wasm.ts"] 488c94be_f327_5956_a885_8d97686ca66e -->|defined in| d496a62e_d9d8_41d4_a984_96f1dbd5f4bd b1b40b5b_3e43_2197_dea0_d36389d312a1["resolvePlugins()"] b1b40b5b_3e43_2197_dea0_d36389d312a1 -->|calls| 488c94be_f327_5956_a885_8d97686ca66e dfa3f5a8_b519_cb65_4b7e_9d4824406fd4["perEnvironmentPlugin()"] 488c94be_f327_5956_a885_8d97686ca66e -->|calls| dfa3f5a8_b519_cb65_4b7e_9d4824406fd4 13b5d2b4_0a9d_90ef_9bfa_129b74a9d64e["fileToUrl()"] 488c94be_f327_5956_a885_8d97686ca66e -->|calls| 13b5d2b4_0a9d_90ef_9bfa_129b74a9d64e c25246ea_7a11_06af_dc93_7717f85216db["createToImportMetaURLBasedRelativeRuntime()"] 488c94be_f327_5956_a885_8d97686ca66e -->|calls| c25246ea_7a11_06af_dc93_7717f85216db 10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"] 488c94be_f327_5956_a885_8d97686ca66e -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e style 488c94be_f327_5956_a885_8d97686ca66e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/wasm.ts lines 75–160
export const wasmHelperPlugin = (): Plugin => {
return perEnvironmentPlugin('vite:wasm-helper', (env) => {
return {
name: 'vite:wasm-helper',
resolveId: {
filter: { id: exactRegex(wasmHelperId) },
handler(id) {
return id
},
},
load: {
filter: { id: [exactRegex(wasmHelperId), wasmInitRE] },
async handler(id) {
const ssr = this.environment.config.consumer === 'server'
if (id === wasmHelperId) {
return `
const instantiateFromUrl = ${ssr ? instantiateFromFileCode : instantiateFromUrlCode}
export default ${wasmHelperCode}
`
}
id = id.split('?')[0]
let url = await fileToUrl(this, id, ssr)
if (ssr && assetUrlRE.test(url)) {
url = url.replace('__VITE_ASSET__', '__VITE_WASM_INIT__')
}
return `
import initWasm from "${wasmHelperId}"
export default opts => initWasm(opts, ${JSON.stringify(url)})
`
},
},
renderChunk:
env.config.consumer === 'server'
? {
filter: { code: wasmInitUrlRE },
async handler(code, chunk, opts, meta) {
const toRelativeRuntime =
createToImportMetaURLBasedRelativeRuntime(
opts.format,
this.environment.config.isWorker,
)
let match: RegExpExecArray | null
let s: BindingMagicString | MagicString | undefined
wasmInitUrlRE.lastIndex = 0
while ((match = wasmInitUrlRE.exec(code))) {
const [full, referenceId] = match
const file = this.getFileName(referenceId)
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
const { runtime } = toRelativeRuntime(file, chunk.fileName)
s ??= meta.magicString ?? new MagicString(code)
s.update(
match.index,
match.index + full.length,
`"+${runtime}+"`,
)
}
if (!s) return null
return meta.magicString
? {
code: s as BindingMagicString,
}
: {
code: s.toString(),
map: this.environment.config.build.sourcemap
? (s as MagicString).generateMap({
hires: 'boundary',
})
: null,
}
},
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does wasmHelperPlugin() do?
wasmHelperPlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/wasm.ts.
Where is wasmHelperPlugin() defined?
wasmHelperPlugin() is defined in packages/vite/src/node/plugins/wasm.ts at line 75.
What does wasmHelperPlugin() call?
wasmHelperPlugin() calls 4 function(s): cleanUrl, createToImportMetaURLBasedRelativeRuntime, fileToUrl, perEnvironmentPlugin.
What calls wasmHelperPlugin()?
wasmHelperPlugin() is called by 1 function(s): resolvePlugins.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free