Skip to content

Commit

Permalink
iniital impl for rollup plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 27, 2023
1 parent 54faf96 commit 9f4acf2
Show file tree
Hide file tree
Showing 19 changed files with 5,026 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ dist
.eslintcache
*.log*
*.env*
.output
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# unwasm
# 🇼 unwasm

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]

Univeral [WebAssembly](https://webassembly.org/) tools for JavaScript.

>[!IMPORTANT]
> [!IMPORTANT]
> This Project is under development!
## Goal
Expand All @@ -18,7 +17,8 @@ This project aims to make common and future-proof solution for WebAssembly modul

The development of this project will be splited into multiple stages.

- [ ] Plugin for bundlers using [unjs/unplugin](https://github.com/unjs/unplugin)
- [ ] Universal builder plugins built with [unjs/unplugin](https://github.com/unjs/unplugin)
- [x] Rollup
- [ ] Tools to operate and inspect `.wasm` files
- [ ] Runtime utils
- [ ] ESM loader for Node.js and other JavaScript runtimes
Expand All @@ -42,16 +42,26 @@ pnpm install unwasm
bun install unwasm
```

Import:
## Using build plugin

```js
// ESM
import {} from "unwasm";
###### Rollup

// CommonJS
const {} = await import("unwasm")
```js
import unwasmPlugin from "unwasm/plugin";

export default {
plugins: [
unwasmPlugin.rollup({
/* options */
}),
],
};
```

### Options

- `esmImport`: Direct import the wasm file instead of bundling, required in Cloudflare Workers (default is `false`)
- `lazy`: Import `.wasm` files using a lazily evaluated promise for compatibility with runtimes without top-level await support (default is `false`)

## Development

Expand All @@ -75,5 +85,3 @@ Published under [MIT License](./LICENSE).
[npm-downloads-href]: https://npmjs.com/package/unwasm
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/unwasm/main?style=flat&colorA=18181B&colorB=F0DB4F
[codecov-href]: https://codecov.io/gh/unjs/unwasm
[bundle-src]: https://img.shields.io/bundlephobia/minzip/unwasm?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=unwasm
7 changes: 7 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
declaration: true,
entries: ["src/plugin"],
externals: ["unwasm", "rollup"],
});
20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,43 @@
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
"./plugin": {
"types": "./dist/plugin.d.mts",
"import": "./dist/plugin.mjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "vitest dev",
"play": "jiti playground",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier -c src test",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier -c src test -w",
"prepack": "pnpm build",
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
"test:types": "tsc --noEmit --skipLibCheck"
},
"dependencies": {
"magic-string": "^0.30.5",
"mlly": "^1.4.2",
"pathe": "^1.1.1",
"unplugin": "^1.6.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@types/node": "^20.10.5",
"@vitest/coverage-v8": "^1.1.0",
"changelogen": "^0.5.5",
"eslint": "^8.56.0",
"eslint-config-unjs": "^0.2.1",
"jiti": "^1.21.0",
"prettier": "^3.1.1",
"rollup": "^4.9.1",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.0.10",
"vitest": "^1.1.0"
},
"packageManager": "[email protected]"
Expand Down
3 changes: 0 additions & 3 deletions playground/index.ts

This file was deleted.

Loading

0 comments on commit 9f4acf2

Please sign in to comment.