Skip to content

Commit 68f559f

Browse files
authored
chore: s/lightningcss-wasm/postcss (#1209)
1 parent 6ef74f6 commit 68f559f

7 files changed

Lines changed: 40 additions & 36 deletions

File tree

‎.changeset/postcss-fallback.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@doc-kit/generator-react': patch
3+
---
4+
5+
Fall back to PostCSS, rather than Lightning CSS's wasm build, on platforms without native Lightning CSS bindings

‎packages/react/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"hast-util-to-html": "^9.0.5",
4646
"hast-util-to-string": "^3.0.1",
4747
"hastscript": "^9.0.1",
48-
"lightningcss-wasm": "^1.33.0",
4948
"mdast-util-slice-markdown": "^2.0.1",
5049
"preact": "^10.29.7",
5150
"preact-render-to-string": "^6.7.0",

‎packages/react/src/html/README.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,15 @@ export default {
301301
302302
The generator owns the fields required to coordinate its builds: config-file
303303
loading, app type and base, virtual inputs, Preact compatibility aliases and
304-
automatic JSX runtime, the Lightning CSS transformer, output/write mode, SSR
305-
format and output, and SSR dependency bundling. Values supplied for those
306-
fields are replaced after configuration is merged. User plugins are registered
307-
after the generator's virtual-module plugin; other Vite options are preserved.
304+
automatic JSX runtime, the CSS transformer, output/write mode, SSR format and
305+
output, and SSR dependency bundling. Values supplied for those fields are
306+
replaced after configuration is merged. User plugins are registered after the
307+
generator's virtual-module plugin; other Vite options are preserved.
308+
309+
CSS is transformed and minified by Lightning CSS. On platforms without its
310+
native bindings, such as ppc64 and s390x, Vite's PostCSS pipeline transforms
311+
the CSS instead and the output is not minified; `css.lightningcss` options have
312+
no effect there.
308313
309314
Vite builds the client entry as a module, not the pages as HTML entries, so
310315
plugins see and can transform every module of the client and server builds but

‎packages/react/src/html/bundlers/__tests__/vite.test.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ describe('Vite configuration', () => {
108108
);
109109
});
110110

111+
it('transforms CSS with Lightning CSS where its bindings are native', () => {
112+
const config = createViteConfig({
113+
sources: new Map(),
114+
input: {},
115+
server: false,
116+
outDir: output,
117+
config: getConfig('html'),
118+
vite: { css: { lightningcss: { targets: {} } } },
119+
});
120+
121+
assert.strictEqual(config.css.transformer, 'lightningcss');
122+
assert.deepStrictEqual(config.css.lightningcss, { targets: {} });
123+
assert.strictEqual(config.build.cssMinify, undefined);
124+
});
125+
111126
it('keeps the server library self-contained', () => {
112127
const vite = {
113128
ssr: {

‎packages/react/src/html/bundlers/vite.mjs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { readFile, rm, rmdir } from 'node:fs/promises';
22
import { dirname, join, posix, resolve } from 'node:path';
33
import { fileURLToPath, pathToFileURL } from 'node:url';
44

5-
import './wasm-fallback.mjs';
65
import {
76
build as viteBuild,
87
defaultClientConditions,
@@ -138,6 +137,9 @@ export const createViteConfig = ({
138137
const root = resolve(vite.root ?? process.cwd());
139138
const conditions = server ? defaultServerConditions : defaultClientConditions;
140139

140+
// Lightning CSS publishes no native bindings for these platforms
141+
const lightningcss = process.arch !== 'ppc64' && process.arch !== 's390x';
142+
141143
return {
142144
...vite,
143145

@@ -194,15 +196,21 @@ export const createViteConfig = ({
194196
},
195197

196198
// CSS imports, modules, URLs, splitting, and minification are all Vite
197-
// responsibilities. Native Lightning CSS options remain configurable.
199+
// responsibilities. Lightning CSS transforms the CSS, with its options
200+
// configurable, on platforms that have its native bindings; elsewhere
201+
// Vite's PostCSS pipeline transforms it instead.
198202
css: {
199203
...vite.css,
200-
transformer: 'lightningcss',
204+
transformer: lightningcss ? 'lightningcss' : 'postcss',
201205
},
202206

203207
build: {
204208
...vite.build,
205209

210+
// Vite's only CSS minifier is Lightning CSS itself, so without its
211+
// bindings the CSS is left as PostCSS produced it.
212+
...(lightningcss ? {} : { cssMinify: false }),
213+
206214
// Both builds are complete Vite outputs. The server library goes to a
207215
// private directory; the client writes into the final site.
208216
outDir,

‎packages/react/src/html/bundlers/wasm-fallback.mjs‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎pnpm-lock.yaml‎

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)