Skip to content

Commit 82bddc1

Browse files
committed
feat(js): Add wasm export path and improve bundler compatibility
- Add "./wasm" export in package.json to expose suzume-wasm.wasm directly, enabling bundlers (webpack, Next.js, Vite) to resolve the WASM file via import '@libraz/suzume/wasm' - Simplify locateFile logic in Suzume.create(): skip setting locateFile entirely when no wasmPath is provided, avoiding potential interference with default Emscripten resolution - Add bundler integration examples to README.npm.md (Vite ?url import and new URL() pattern) - Fix POS values in README.npm.md examples to use uppercase (NOUN, VERB) matching the actual Tag.pos string values returned by generateTags()
1 parent 45fe132 commit 82bddc1

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

README.npm.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ for (const t of tokens) {
1616

1717
// Tag extraction (returns { tag, pos } objects)
1818
const tags = suzume.generateTags('東京スカイツリーに行きました')
19-
// → [{ tag: '東京', pos: 'noun' }, { tag: 'スカイツリー', pos: 'noun' }, { tag: '行く', pos: 'verb' }]
19+
// → [{ tag: '東京', pos: 'NOUN' }, { tag: 'スカイツリー', pos: 'NOUN' }, { tag: '行く', pos: 'VERB' }]
2020

2121
// Nouns only
2222
suzume.generateTags('美味しいラーメンを食べた', { pos: ['noun'] })
23-
// → [{ tag: 'ラーメン', pos: 'noun' }]
23+
// → [{ tag: 'ラーメン', pos: 'NOUN' }]
2424

2525
// Exclude basic words (hiragana-only lemma like する, ある, いい)
2626
suzume.generateTags('今日はいい天気ですね', { excludeBasic: true })
27-
// → [{ tag: '今日', pos: 'noun' }, { tag: '天気', pos: 'noun' }]
27+
// → [{ tag: '今日', pos: 'NOUN' }, { tag: '天気', pos: 'NOUN' }]
2828
```
2929

3030
### Browser (CDN)
@@ -38,6 +38,23 @@ suzume.generateTags('今日はいい天気ですね', { excludeBasic: true })
3838
</script>
3939
```
4040

41+
### Bundlers (webpack, Next.js, etc.)
42+
43+
If your bundler doesn't automatically resolve the `.wasm` file, you can specify its path manually:
44+
45+
```typescript
46+
import wasmUrl from '@libraz/suzume/wasm?url' // Vite
47+
const suzume = await Suzume.create({ wasmPath: wasmUrl })
48+
```
49+
50+
Or specify the path directly:
51+
52+
```typescript
53+
const suzume = await Suzume.create({
54+
wasmPath: new URL('@libraz/suzume/wasm', import.meta.url).href
55+
})
56+
```
57+
4158
## Documentation
4259

4360
- [Getting Started](https://suzume.libraz.net/docs/getting-started)

js/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,11 @@ export class Suzume {
172172

173173
// Dynamic import of the Emscripten-generated module
174174
const createModule = await import('./suzume.js');
175-
const module: EmscriptenModule = await createModule.default({
176-
locateFile: (path: string) => {
177-
if (path.endsWith('.wasm') && wasmPath) {
178-
return wasmPath;
179-
}
180-
return path;
181-
},
182-
});
175+
const moduleOptions: Record<string, unknown> = {};
176+
if (wasmPath) {
177+
moduleOptions.locateFile = (path: string) => (path.endsWith('.wasm') ? wasmPath : path);
178+
}
179+
const module: EmscriptenModule = await createModule.default(moduleOptions);
183180

184181
let handle: number;
185182

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"types": "./dist/index.d.ts",
1212
"import": "./dist/index.js"
1313
},
14+
"./wasm": "./dist/suzume-wasm.wasm",
1415
"./package.json": "./package.json"
1516
},
1617
"sideEffects": false,

0 commit comments

Comments
 (0)