Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wasm-bindings-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@doc-kit/generator-react': patch
---

Fall back on platforms without native Rolldown or Lightning CSS bindings
2 changes: 2 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
"@node-core/ui-components": "^1.8.1",
"@orama/orama": "^3.1.18",
"@orama/ui": "^1.5.4",
"@rolldown/binding-wasm32-wasi": "~1.2.15",
"estree-util-to-js": "^2.0.0",
"github-slugger": "^2.0.0",
"hast-util-to-html": "^9.0.5",
"hast-util-to-string": "^3.0.1",
"hastscript": "^9.0.1",
"lightningcss-wasm": "^1.33.0",
"mdast-util-slice-markdown": "^2.0.1",
"preact": "^10.29.7",
"preact-render-to-string": "^6.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/html/bundlers/vite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readFile, rm, rmdir } from 'node:fs/promises';
import { dirname, join, posix, resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

import './wasm-fallback.mjs';
import {
build as viteBuild,
defaultClientConditions,
Expand Down
21 changes: 21 additions & 0 deletions packages/react/src/html/bundlers/wasm-fallback.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createRequire, registerHooks } from 'node:module';

const viteRequire = createRequire(import.meta.resolve('vite'));

try {
viteRequire('lightningcss');
} catch {
const url = import.meta.resolve('lightningcss-wasm');

registerHooks({
/**
* Resolves `lightningcss` to `lightningcss-wasm`.
*
* @type {import('node:module').ResolveHookSync}
*/
resolve: (specifier, context, nextResolve) =>
specifier === 'lightningcss'
? { url, format: 'module', shortCircuit: true }
: nextResolve(specifier, context),
});
}
Loading
Loading