Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightningCSS minify issues #16354

Open
7 tasks done
predaytor opened this issue Apr 4, 2024 · 1 comment
Open
7 tasks done

LightningCSS minify issues #16354

predaytor opened this issue Apr 4, 2024 · 1 comment
Labels
bug: upstream Bug in a dependency of Vite feat: css p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@predaytor
Copy link

predaytor commented Apr 4, 2024

Describe the bug

I noticed an unnecessary duplication of @supports rules when using the Lightning CSS minification, which also differs from the LightningCSS playground output.

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import browserslist from 'browserslist';
import { browserslistToTargets } from 'lightningcss';

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    transformer: 'lightningcss',
    lightningcss: {
      targets: browserslistToTargets(browserslist('>= 0.25%')),
      drafts: {
        customMedia: true,
      },
    },
  },
  build: {
    cssMinify: 'lightningcss',
    // cssMinify: true,
  },
  plugins: [react()],
});

1st test (OKLCH):

Input:

.x {
  --x: oklch(61% 0.016 277.7);
}

Result:

.x {
	--x: #81828d;
}
@supports (color: lab(0% 0 0)) {
	.x {
		--x: #81828d;
	}
	@supports (color: color(display-p3 0 0 0)) {
		.x {
			--x: color(display-p3 0.50541 0.511328 0.549274);
		}
	}
	@supports (color: lab(0% 0 0)) {
		.x {
			--x: lab(54.6419% 0.899702 -5.96);
		}
	}
}

Expected result (LightningCSS playground):

.x {
	--x: #81828d;
}
@supports (color: lab(0% 0 0)) {
	.x {
		--x: lab(54.6419% 0.899702 -5.96);
	}
}

///

2nd case (display-p3):

Input:

.x {
  --x: color(display-p3 0.004 0.278 0.933 / 0.173);
}

Result:

.x {
	--x: #0051e52c;
}
@supports (color: color(display-p3 0 0 0)) {
	.x {
		--x: #0051e52c;
	}
	@supports (color: color(display-p3 0 0 0)) {
		.x {
			--x: color(display-p3 0.004 0.278 0.933/.173);
		}
	}
}

Expected result (LightningCSS playground):

.x {
	--x: rgba(0, 81, 229, 0.173);
}
@supports (color: color(display-p3 0 0 0)) {
	.x {
		--x: color(display-p3 0.004 0.278 0.933/.173);
	}
}

Reproduction

https://stackblitz.com/edit/vitejs-vite-wdjgbn?file=src%2FApp.css,vite.config.ts

Steps to reproduce

Run pnpm build to inspect /dist folder for CSS output

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.2.1 
    vite: ^5.2.7 => 5.2.8

Used Package Manager

pnpm

Logs

No response

Validations

Copy link

stackblitz bot commented Apr 4, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added bug: upstream Bug in a dependency of Vite feat: css p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

2 participants