Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(wasm): use vite to embed the WASM module in base64 #283

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions ffi/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ This should be run in the CI.
2. Build the package:

```
$ wasm-pack build --target web --scope devolutions --out-name picky
$ npm run build:wasm
$ npm run build
```

3. Rename `@devolutions/picky-wasm` to `@devolutions/picky` in `pkg/package.json`.

4. Publish to npm:
3. Publish to npm:

```
$ wasm-pack publish
$ npm publish
```

## Testing
Expand Down
3 changes: 3 additions & 0 deletions ffi/wasm/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './pkg/picky.js';
import init from './pkg/picky.js';
export default init;
33 changes: 33 additions & 0 deletions ffi/wasm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@devolutions/picky",
"collaborators": [
"Benoît CORTIER <[email protected]>"
],
"description": "Portable X.509, PKI, JOSE and HTTP signature implementation.",
"version": "0.10.1",
"repository": {
"type": "git",
"url": "https://github.com/Devolutions/picky-rs"
},
"main": "./dist/picky.js",
"files": [
"dist"
],
"scripts": {
"build": "vite build",
"build:wasm": "wasm-pack build --target web --scope devolutions --out-name picky --out-dir ./pkg --release",
"clean": "npm run clean:win && npm run clean:lin",
"clean:win": "node -e \"if (process.platform === 'win32') process.exit(1)\" || (if exist dist rmdir /Q /S dist && if exist pkg rmdir /Q /S pkg)",
"clean:lin": "node -e \"if (process.platform !== 'win32') process.exit(1)\" || (rm -rf dist pkg)"
},
"author": "",
"license": "MIT OR Apache-2.0",
"types": "./dist/main.d.ts",
"type": "module",
"dependencies": {
"vite": "^4.2.12",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-top-level-await": "^1.3.1",
"vite-plugin-wasm": "^3.2.2"
}
}
4 changes: 2 additions & 2 deletions ffi/wasm/publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

$ErrorActionPreference = "Stop"

wasm-pack build --target bundler --scope devolutions --out-name picky
npm run build:wasm && npm run build

if ($LastExitCode -ne 0)
{
throw "wasm-pack build failed"
}

wasm-pack publish --access=public
npm run publish

if ($LastExitCode -ne 0)
{
Expand Down
16 changes: 16 additions & 0 deletions ffi/wasm/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite';
import topLevelAwait from 'vite-plugin-top-level-await';
import dtsPlugin from 'vite-plugin-dts';
import wasm from 'vite-plugin-wasm';

export default defineConfig({
build: {
lib: {
entry: 'main.ts',
name: '@Devolutions/picky',
formats: ['es'],
},
},
assetsInclude: ['pkg/picky_bg.wasm'],
plugins: [wasm(), topLevelAwait(), dtsPlugin()],
});