mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
feat(nitro): support importing/inlining wasm binaries (#693)
This commit is contained in:
parent
abfaaa97eb
commit
5275624f2e
12
examples/wasm/package.json
Normal file
12
examples/wasm/package.json
Normal 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"
|
||||
}
|
||||
}
|
9
examples/wasm/server/api/hello.ts
Normal file
9
examples/wasm/server/api/hello.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import sample from './sample.wasm'
|
||||
|
||||
export default async () => {
|
||||
const { instance } = await sample({})
|
||||
|
||||
return {
|
||||
result: instance.exports.main()
|
||||
}
|
||||
}
|
BIN
examples/wasm/server/api/sample.wasm
Normal file
BIN
examples/wasm/server/api/sample.wasm
Normal file
Binary file not shown.
@ -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",
|
||||
|
@ -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
|
||||
|
18
yarn.lock
18
yarn.lock
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user