The `canvaskit-wasm` package provides a WebAssembly (WASM) implementation of Skia's 2D graphics API, enabling high-performance rendering capabilities across diverse JavaScript environments including browsers, Node.js, and WebWorkers. Currently at version 0.41.1, its release cycle generally aligns with updates from the upstream Skia project, which is known for its robust and feature-rich graphics engine. A key differentiator is its ability to offer a comprehensive, portable alternative to native Canvas2D APIs, particularly for complex vectorial graphics, text rendering, and advanced animations like Lottie/Skottie. The package offers several bundles – a default minimal version, a 'full' version including Skottie and other advanced features, and a 'profiling' version – allowing developers to optimize for bundle size and debugging needs. This flexibility, combined with its C++ backend performance via WASM, positions it as a powerful tool for demanding visual applications.
npm install canvaskit-wasmVerified import paths — ran on the pinned version, not inferred.
Initializes CanvasKit from a CDN, creates a canvas surface, draws a red rectangle, and flushes the drawing to an HTML canvas element.
Ensure the `locateFile` function correctly returns the URL or local path to `canvaskit.wasm` relative to where your application will be served or run. For bundlers, this often requires specific asset handling.
Use `CopyWebpackPlugin` in your Webpack configuration to copy `node_modules/canvaskit-wasm/bin/canvaskit.wasm` (and other bundle variants if used) to your output directory. Adjust `locateFile` accordingly.
Add `"resolvePackageJsonExports": true` to your `compilerOptions` in `tsconfig.json`.
Always initialize CanvasKit using the asynchronous `CanvasKitInit()` function and wait for its Promise to resolve: `CanvasKitInit({...}).then((CanvasKit) => { /* use CanvasKit */ });`In your Webpack configuration, add `node: { fs: 'empty' }` to the configuration object to tell Webpack to ignore the `fs` module in browser builds.Verify that the path provided by the `locateFile` function in `CanvasKitInit` accurately points to the `canvaskit.wasm` file. Ensure the `.wasm` file is correctly placed in your deployment, has correct permissions, and is being served with the `application/wasm` MIME type.
No dependency data recorded yet.