lindera-wasm-bundler is a WebAssembly-based morphological analysis library designed for use in bundler environments like Webpack or Rollup. It provides Japanese text segmentation and part-of-speech tagging capabilities, leveraging WebAssembly for performance and portability. The current stable version is 3.0.5, with minor releases occurring frequently to address bugs and introduce minor enhancements, as seen in the recent v3.0.x series. Major version updates (like the v2 to v3 transition) introduce significant changes, often including refactoring and API adjustments. A key differentiator is its reliance on the OPFS (Origin Private File System) API for efficient runtime loading and management of large dictionary files, making it suitable for web applications requiring robust text processing without bundling dictionaries directly into the main application payload.
npm install lindera-wasm-bundlerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Lindera WASM module, download and load a dictionary using the OPFS API, and then tokenize a Japanese sentence, logging each token's surface form and morphological details.
For Node.js environments, switch to `lindera-nodejs`. For bundler environments, ensure you are importing from `lindera-wasm-bundler` and update import paths/statements as necessary. Review the v3.0.0 changelog for specific refactoring details.
Add `lindera-wasm-bundler` to the `optimizeDeps.exclude` array in your `vite.config.js`:
```javascript
// vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
optimizeDeps: {
exclude: [
"lindera-wasm-bundler" // Use "lindera-wasm-web" if using that package
]
},
});
```In `manifest.json`, ensure your CSP includes `script-src 'self' 'wasm-unsafe-eval';` for `extension_pages`. For Vite development, configure `cors` in `vite.config.js`:
```json
// manifest.json
"content_security_policy": {
"extension_pages": "script-src 'self' 'wasm-unsafe-eval';"
}
```
```javascript
// vite.config.js
import { defineConfig } from 'vite'
export default defineConfig({
server: {
cors: {
origin: [
/chrome-extension:\/\//,
],
},
},
});
```Always `await` calls to `__wbg_init()` and any methods that return a Promise, typically those that interact with the underlying WASM or I/O, such as `downloadDictionary` and potentially `tokenizer.tokenize` in some complex scenarios. Wrap usage in an `async` function.
Verify that your bundler is correctly configuring the output path and serving the WebAssembly `.wasm` file. For Vite, ensure the `optimizeDeps.exclude` configuration is correctly applied to prevent issues with pre-bundling that might interfere with WASM file resolution.
Ensure `__wbg_init` is imported as the default export: `import __wbg_init from 'lindera-wasm-bundler';`
Ensure `downloadDictionary` has completed successfully and that the dictionary name provided to `loadDictionaryFiles` matches the name used during download. Also, verify that the browser's Origin Private File System (OPFS) is accessible and not blocked by security policies.
No dependency data recorded yet.