Repository navigation
feat: add wasmBaseUrl option and migrate the build from tsup to tsdown - #26
Merged
Merged
Conversation
tsup is unmaintained; tsdown is its actively-developed successor built on Rolldown. Port the build config, mapping tsup options to their tsdown equivalents: `noExternal` to `deps.alwaysBundle`, the esbuild `esbuildOptions.assetNames` override to Rolldown's `outputOptions.assetFileNames`, and the `loader` map to Rolldown module types (`.wasm` via `asset`). The Tailwind CSS assets are imported with a `?raw` suffix (a Vite convention added for the Vitest browser tests). Rolldown doesn't resolve query suffixes, and tsdown's CSS handling claims modules by their `.css` id (requiring `@tsdown/css`, which would also preprocess the CSS). Since these strings must stay verbatim — they're fed as `@import` sources into the browser-side Tailwind compiler — add a small `raw-imports` plugin that resolves the real file and loads its contents as a text module through a virtual id. Update the `tailwindcss-v4` type declaration to match the `?raw` specifiers used in the source. Build output is unchanged: the same versioned WASM file (byte-identical), the `?url` banner import, and the same exports and type declarations.
… resolve it
The Lightning CSS WASM file was loaded via
`new URL(lightningCssWasm, import.meta.url)`, where `lightningCssWasm` is an
import binding that minifies to a variable. Static-analysis-based bundlers
resolve `new URL` asset references only when the first argument is a string
literal (e.g. Vite's dependency optimizer), so a variable is left pointing at
the bundled module's own location. When a consumer pre-bundles this library
into a cache directory, the WASM URL resolves there instead of next to the
shipped file, and instantiation fails. Consumers currently work around this by
excluding the library from dependency optimization.
Reference the file with a relative literal,
`new URL("./lightningcss_node.wasm", import.meta.url)`, and ship the WASM
file in the package by copying it verbatim from `lightningcss-wasm` (it is no
longer emitted via a module import). This lets bundlers rewrite the reference to
the real file, so consumers no longer need the optimization workaround.
The `banner` `?url` import and the `assetFileNames` version-pinning existed
only to make the WASM filename predictable for that hardcoded import; with the
literal reference in place they are removed.
harumijang
marked this pull request as ready for review
October 16, 2026 21:53
balintbrews
reviewed
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
1. Migrate from tsup to tsdown
tsup.config.tswithtsdown.config.ts, keeping the same output: a single ESM browser bundle with type declarations, andcss-tree,lightningcss-wasm,tailwindcss-v3andtailwindcss-v4bundled in.raw-importsplugin so the?rawTailwind CSS imports are inlined verbatim. Rolldown doesn't support?raw, and tsdown's CSS handling would otherwise process the files. The plugin resolves each file to a\0-prefixed virtual id (the Rolldown convention, so other plugins skip it) and loads its contents as text.?rawTailwind CSS imports explicitly insrc/types/tailwindcss-v4.d.ts.2. Remove the WASM workaround now that Vite resolves literal asset URLs
The Lightning CSS WASM was loaded with
new URL(variable, import.meta.url), which consumers' bundlers can't detect. Abanner?urlimport forced them to copy the file, and Vite users also neededoptimizeDeps.exclude: ['tailwindcss-in-browser']in dev. With vitejs/vite#21434 (Vite 8.3.3+), Vite resolves literalnew URL()asset references, including in pre-bundled dependencies, so the workaround can go.banner?urlimport and the version-pinnedassetNames.new URL()so consumers' bundlers detect it and rewrite the URL themselves. Thelightningcss-wasmversion is inlined at build time viadefine, sodist/index.jscontains a plain string, e.g.new URL("./lightningcss_node-1.30.1.wasm", import.meta.url).copy, renamed to the same versioned file name (lightningcss_node-1.30.1.wasm, as in 0.6.0). The version is read once fromlightningcss-wasmintsdown.config.tsand used for both, so the URL and the file name can't drift apart, and the file name changes when the binary does, for cache busting.wasmBaseUrloption totransformCss()for apps that serve assets from a different path than their bundler assumes, e.g. Drupal Canvas serving them from a module directory. Only the directory is replaced: the library keeps the default file name (including the version, or any hash added by the consumer's bundler) and appends it to the base URL.Testing instructions with Canvas MR: https://git.drupalcode.org/project/canvas/-/merge_requests/1812, using a packed build (
npm pack) instead of a link:optimizeDeps.exclude): the package is pre-bundled into.vite/deps, and the WASM loads fromnode_modules/tailwindcss-in-browser/dist/lightningcss_node-1.30.1.wasm.ui/dist/assets/containslightningcss_node-1.30.1.wasm, and withwasmBaseUrlthe bundle resolves to the same path under the module directory.