feat: add browser-only WASM build variant #622
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When bundling sql.js for browser environments, tools like Vite, Webpack, and esbuild emit warnings about
require("node:fs")andrequire("node:crypto")being externalized for browser compatibility. Theserequire()calls exist in the emcc-generated code because the defaultENVIRONMENTincludesnode.This PR adds a new
sql-wasm-browser.jsbuild variant that eliminates these warnings:EMFLAGS_WASM_BROWSERin Makefile: same asEMFLAGS_WASMbut with-s ENVIRONMENT=web,worker, which tells Emscripten to strip all Node.js code paths at compile timedist/sql-wasm-browser.js(optimized) anddist/sql-wasm-browser-debug.js(debug)package.json: bundlers targeting browsers automatically resolve to the cleansql-wasm-browser.jsvia thebrowsercondition, while Node.js and other environments continue using the originalsql-wasm.jsBefore (bundler output)
After
No sql.js related warnings.
Build comparison
require()callssql-wasm.js(unchanged)require("node:fs"),require("node:crypto")sql-wasm-browser.js(new).wasmbinaryNo breaking changes — the original
sql-wasm.jsis fully preserved as thedefaultexport.Closes #620
Test plan
sql-wasm-browser.jswithmake dist/sql-wasm-browser.js— succeedssql-wasm-browser.jscontains zerorequire()callssql-wasm.jsstill contains Node.js support code🤖 Generated with Claude Code