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

fix(css): use esbuild legalComments config when minifying CSS #13661

Merged
merged 1 commit into from Jun 30, 2023

Conversation

niksy
Copy link
Contributor

@niksy niksy commented Jun 28, 2023

Description

If you set esbuild configuration with additional transform options, those options are passed down to JS minification process, but they’re ignored for CSS minification, resulting in situations where you can e.g. set legalComments option to different value and expect that it will be applied to both JS and CSS files, but it’s applied only to JS files.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@@ -1517,22 +1517,23 @@ function resolveMinifyCssEsbuildOptions(
options: ESBuildOptions,
): TransformOptions {
const base: TransformOptions = {
...options,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit concerned with passing everything since the esbuild options is shared between JS too. Configuration like target might inadvertently override build.cssTarget. Is legalComments the only property you need here? We can pass that specifically here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand, that was also my concern. Currently it’s only legalComments, but the idea was to align this with JS options. Is there a list of explicit config fields such as build.cssTarget? Maybe we can omit them here to avoid conflicts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's still better to opt-in properties individually like legalComments to be safe. e.g. banner and footer wouldn't really work in both CSS and JS too (arguably it's an edge cases). If there's more properties needed to pass, we can revisit passing the entire thing again if needed.

Copy link
Contributor Author

@niksy niksy Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legalComments and lineLimit are options that could be applied to JS and CSS files in minification process. banner and footer could be adjusted to replace JS inline comments to block comments but I think that’s out of scope for this PR.

I’ve added only legalComments support, but let me know if it’s okay to work on other options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do legalComments for now and see if there's request for lineLimit in the future. IIRC it's a recent feature and isn't too bad for CSS if it's not used.

@bluwy bluwy changed the title fix(css): use esbuild configuration when minifying CSS fix(css): use esbuild legalComments config when minifying CSS Jun 30, 2023
@bluwy bluwy added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Jun 30, 2023
@bluwy bluwy merged commit 2d9008e into vitejs:main Jun 30, 2023
14 checks passed
@bluwy
Copy link
Member

bluwy commented Jun 30, 2023

Thanks!

xinxinhe1810 pushed a commit to xinxinhe1810/vite that referenced this pull request Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants