feat(nitro): support importing/inlining wasm binaries (#693)

This commit is contained in:
Daniel Roe 2021-10-07 15:43:34 +02:00 committed by GitHub
parent abfaaa97eb
commit 5275624f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,12 @@
{
"name": "example-wasm",
"private": true,
"devDependencies": {
"nuxt3": "latest"
},
"scripts": {
"dev": "nuxt dev",
"build": "nuxt build",
"start": "node .output/server/index.mjs"
}
}

View File

@ -0,0 +1,9 @@
import sample from './sample.wasm'
export default async () => {
const { instance } = await sample({})
return {
result: instance.exports.main()
}
}

Binary file not shown.

View File

@ -25,6 +25,7 @@
"@rollup/plugin-node-resolve": "^13.0.5",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-virtual": "^2.0.3",
"@rollup/plugin-wasm": "^5.1.2",
"@rollup/pluginutils": "^4.1.1",
"@types/jsdom": "^16.2.13",
"@vercel/nft": "^0.15.1",

View File

@ -10,6 +10,7 @@ import alias from '@rollup/plugin-alias'
import json from '@rollup/plugin-json'
import replace from '@rollup/plugin-replace'
import virtual from '@rollup/plugin-virtual'
import wasmPlugin from '@rollup/plugin-wasm'
import inject from '@rollup/plugin-inject'
import analyze from 'rollup-plugin-analyzer'
import * as unenv from 'unenv'
@ -141,6 +142,9 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
// Raw asset loader
rollupConfig.plugins.push(raw())
// WASM import support
rollupConfig.plugins.push(wasmPlugin())
// https://github.com/rollup/plugins/tree/master/packages/replace
rollupConfig.plugins.push(replace({
// @ts-ignore https://github.com/rollup/plugins/pull/810

View File

@ -2613,6 +2613,7 @@ __metadata:
"@rollup/plugin-node-resolve": ^13.0.5
"@rollup/plugin-replace": ^3.0.0
"@rollup/plugin-virtual": ^2.0.3
"@rollup/plugin-wasm": ^5.1.2
"@rollup/pluginutils": ^4.1.1
"@types/debounce": ^1.2.1
"@types/fs-extra": ^9.0.13
@ -3259,6 +3260,15 @@ __metadata:
languageName: node
linkType: hard
"@rollup/plugin-wasm@npm:^5.1.2":
version: 5.1.2
resolution: "@rollup/plugin-wasm@npm:5.1.2"
peerDependencies:
rollup: ^1.20.0 || ^2.0.0
checksum: ba8d02fd351900b7e1fa722b7f71cf420dd5b67dcade3bf91f7ac60d75fca1fc4ed61ff5cecfe033dc9bfd7f857ab374d6858de74fcf5fae3acebfbc193ffa01
languageName: node
linkType: hard
"@rollup/pluginutils@npm:^3.0.4, @rollup/pluginutils@npm:^3.0.8, @rollup/pluginutils@npm:^3.1.0":
version: 3.1.0
resolution: "@rollup/pluginutils@npm:3.1.0"
@ -9246,6 +9256,14 @@ __metadata:
languageName: unknown
linkType: soft
"example-wasm@workspace:examples/wasm":
version: 0.0.0-use.local
resolution: "example-wasm@workspace:examples/wasm"
dependencies:
nuxt3: latest
languageName: unknown
linkType: soft
"example-with-components@workspace:examples/with-components":
version: 0.0.0-use.local
resolution: "example-with-components@workspace:examples/with-components"