Skip to content
Merged
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/postcss-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@doc-kit/generator-react': patch
---

Fall back to PostCSS, rather than Lightning CSS's wasm build, on platforms without native Lightning CSS bindings
1 change: 0 additions & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"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
13 changes: 9 additions & 4 deletions packages/react/src/html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,15 @@ export default {

The generator owns the fields required to coordinate its builds: config-file
loading, app type and base, virtual inputs, Preact compatibility aliases and
automatic JSX runtime, the Lightning CSS transformer, output/write mode, SSR
format and output, and SSR dependency bundling. Values supplied for those
fields are replaced after configuration is merged. User plugins are registered
after the generator's virtual-module plugin; other Vite options are preserved.
automatic JSX runtime, the CSS transformer, output/write mode, SSR format and
output, and SSR dependency bundling. Values supplied for those fields are
replaced after configuration is merged. User plugins are registered after the
generator's virtual-module plugin; other Vite options are preserved.

CSS is transformed and minified by Lightning CSS. On platforms without its
native bindings, such as ppc64 and s390x, Vite's PostCSS pipeline transforms
the CSS instead and the output is not minified; `css.lightningcss` options have
no effect there.

Vite builds the client entry as a module, not the pages as HTML entries, so
plugins see and can transform every module of the client and server builds but
Expand Down
15 changes: 15 additions & 0 deletions packages/react/src/html/bundlers/__tests__/vite.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ describe('Vite configuration', () => {
);
});

it('transforms CSS with Lightning CSS where its bindings are native', () => {
const config = createViteConfig({
sources: new Map(),
input: {},
server: false,
outDir: output,
config: getConfig('html'),
vite: { css: { lightningcss: { targets: {} } } },
});

assert.strictEqual(config.css.transformer, 'lightningcss');
assert.deepStrictEqual(config.css.lightningcss, { targets: {} });
assert.strictEqual(config.build.cssMinify, undefined);
});

it('keeps the server library self-contained', () => {
const vite = {
ssr: {
Expand Down
14 changes: 11 additions & 3 deletions packages/react/src/html/bundlers/vite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 Expand Up @@ -138,6 +137,9 @@ export const createViteConfig = ({
const root = resolve(vite.root ?? process.cwd());
const conditions = server ? defaultServerConditions : defaultClientConditions;

// Lightning CSS publishes no native bindings for these platforms
const lightningcss = process.arch !== 'ppc64' && process.arch !== 's390x';

return {
...vite,

Expand Down Expand Up @@ -194,15 +196,21 @@ export const createViteConfig = ({
},

// CSS imports, modules, URLs, splitting, and minification are all Vite
// responsibilities. Native Lightning CSS options remain configurable.
// responsibilities. Lightning CSS transforms the CSS, with its options
// configurable, on platforms that have its native bindings; elsewhere
// Vite's PostCSS pipeline transforms it instead.
css: {
...vite.css,
transformer: 'lightningcss',
transformer: lightningcss ? 'lightningcss' : 'postcss',
},

build: {
...vite.build,

// Vite's only CSS minifier is Lightning CSS itself, so without its
// bindings the CSS is left as PostCSS produced it.
...(lightningcss ? {} : { cssMinify: false }),

// Both builds are complete Vite outputs. The server library goes to a
// private directory; the client writes into the final site.
outDir,
Expand Down
17 changes: 0 additions & 17 deletions packages/react/src/html/bundlers/wasm-fallback.mjs

This file was deleted.

11 changes: 0 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading