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

CSS fails minification due to erroneous comment match inside of base64 string #1359

Closed
Jaeiya opened this issue Jan 5, 2021 · 2 comments
Closed

Comments

@Jaeiya
Copy link

Jaeiya commented Jan 5, 2021

Describe the bug

I have a base64 encoded font in a CSS file. When it is parsed through the built-in minifier used by Vite (during the build process), it fails compilation because of an error introduced by the fix for issue #426.

This specific font I'm using, when converted to base64, includes // as part of its string. The code below interprets this as a comment and completely removes the rest of the base64 string, thereby rendering the font unusable.

When the file is minified, however, the entire rest of the file is erased as well, because it's interpreted as part of the comment (minifier places everything on same line).

// if build, analyze url() asset reference
// account for comments https://github.com/vitejs/vite/issues/426
css = css.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, '$1')

Extra Info

I had originally thought this would be fixed by #936 but as it turns out, this was an entirely separate issue.

Reproduction

  1. Create a CSS file
  2. Insert // in any CSS property that accepts a string ex: font-family: '//';
  3. Import the file in any view (I'm using Vue)
  4. Build the project in production mode (This only happens in production mode)

System Info

  • vite version: 2.0 beta 4
  • Operating System: Windows 8.1
  • Node version: 14.15.1
  • Optional:
    • Vue version: 3.0.4
    • @vue/compiler-sfc version: 3.0.4

The error message when minifying fails

This doesn't entirely reflect the specific error going on, as it's not directly related to the minifier, but I'm including this for completeness sake.
image

@yyx990803
Copy link
Member

Did this work in Vite 1 with a stricter comment removal?

@Jaeiya
Copy link
Author

Jaeiya commented Jan 5, 2021

I did not try it with Vite 1.0. Unfortunately I didn't use Vite to compile my css at the time, I decided to do that when I upgraded to 2.0. When I have some time, I can mock up a test and try it out.

yyx990803 added a commit that referenced this issue Jan 5, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants