Skip to content

Commit debdfb2

Browse files
authored
Merge pull request #10 from kylebarron/kyle/better-bundling
2 parents fa9a718 + 28ce49c commit debdfb2

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ node_modules
44
Cargo.lock
55
bin/
66
pkg/
7+
pkg_node/
8+
pkg_web/
79
wasm-pack.log
810
.idea/
911
www/data

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ yarn add parquet-wasm
1616
npm install parquet-wasm
1717
```
1818

19-
## Usage
19+
## API
2020

2121
### `readParquet`
2222

@@ -42,6 +42,14 @@ For the initial release, `writeParquet` is hard-coded to use Snappy compression
4242

4343
Sets [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook) in Rust, which provides better debugging of panics by having more informative `console.error` messages. Initialize this first if you're getting errors such as `RuntimeError: Unreachable executed`.
4444

45+
## Using
46+
47+
`parquet-wasm` is distributed with three bindings for use in different environments.
48+
49+
- Default, to be used in bundlers such as Webpack: `import * as parquet from 'parquet-wasm'`
50+
- Node, to be used with `require` in NodeJS: `const parquet = require('parquet-wasm/node');`
51+
- ESM, to be used directly from the Web as an ES Module: `import * as parquet from 'parquet-wasm/web';`
52+
4553
## Example
4654

4755
```js
@@ -97,6 +105,25 @@ LZ4 compression appears not to work yet. When trying to parse a file with LZ4 co
97105
- Compile: `wasm-pack build`, or change targets, e.g. `wasm-pack build --target nodejs`
98106
- Publish `wasm-pack publish`.
99107

100-
## Credits
108+
### Publishing
109+
110+
`wasm-pack` supports [three different targets](https://rustwasm.github.io/docs/wasm-pack/commands/build.html#target):
111+
112+
- `bundler` (used with bundlers like Webpack)
113+
- `nodejs` (used with Node, supports `require`)
114+
- `web` (used as an ES module directly from the web)
115+
116+
There are good reasons to distribute as any of these... so why not distribute as all three? `wasm-pack` doesn't support this directly but the build script in `scripts/build.sh` calls `wasm-pack` three times and merges the outputs. This means that bundler users can use the default, Node users can use `parquet-wasm/node` and ES Modules users can use `parquet-wasm/web` in their imports.
117+
118+
To publish:
119+
120+
```
121+
bash ./scripts/build.sh
122+
wasm-pack publish
123+
```
124+
125+
## Acknowledgements
101126

102127
A starting point of my work came from @my-liminal-space's [`read-parquet-browser`](https://github.com/my-liminal-space/read-parquet-browser) (which is also dual licensed MIT and Apache 2).
128+
129+
@domoritz's [`arrow-wasm`](https://github.com/domoritz/arrow-wasm) was a very helpful reference for bootstrapping Rust-WASM bindings.

scripts/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
rm -rf pkg pkg_node pkg_web
2+
3+
# Build node version into pkg_node
4+
wasm-pack build --release --out-dir pkg_node --out-name node --target nodejs
5+
6+
# Build web version into pkg_web
7+
wasm-pack build --release --out-dir pkg_web --out-name web --target web
8+
9+
# Build standard bundler version into pkg
10+
wasm-pack build --release --out-dir pkg --target bundler
11+
12+
# Copy files into pkg/
13+
cp pkg_node/{node.d.ts,node.js,node_bg.wasm,node_bg.wasm.d.ts} pkg/
14+
cp pkg_web/{web.d.ts,web.js,web_bg.wasm,web_bg.wasm.d.ts} pkg/
15+
16+
# Update files array using JQ
17+
jq '.files += ["node.d.ts","node.js","node_bg.wasm","node_bg.wasm.d.ts", "web.d.ts","web.js","web_bg.wasm","web_bg.wasm.d.ts"]' pkg/package.json > pkg/package.json.tmp
18+
mv pkg/package.json.tmp pkg/package.json

0 commit comments

Comments
 (0)