WebCompiler icon indicating copy to clipboard operation
WebCompiler copied to clipboard

Compiled scss to css file wont validate according to standard

Open kledung opened this issue 1 year ago • 13 comments

When I compile from scss to css, the encoding of the css is "UTF-8 with BOM". This puts a special character at the beginning of the compiled css file before @charset "UTF-8"; The special characters makes the CSS to not validate in W3C CSS validator with the following validation error: The @charset rule may only occur at the start of the style sheet. Please check that there are no spaces before it. @charset "UTF-8";

Is there a config option that will give the encoding of the output as "UTF-8" instead of "UTF-8 BOM"?

kledung avatar Feb 03 '25 15:02 kledung

I'll take a look; I have a new release ready, but was waiting on a possible pull request; if this is a straightforward fix, I'll try to squeeze it into the next release.

failwyn avatar Feb 04 '25 15:02 failwyn

Hi again! Perfect. Do you have any estimate when a new release might come?

kledung avatar Mar 21 '25 11:03 kledung

I did not have a chance to fix this issue yet; I'll try to look i to it today.

failwyn avatar Mar 21 '25 12:03 failwyn

It looks like this should be a relatively easy fix, I'll add a bool outputUTF8Identifier option to the config, default to true if it's not present to maintain current behavior. I'll update the code over the weekend and test it at work over the next week to make sure no issues arise from the changes.

failwyn avatar Mar 21 '25 17:03 failwyn

This should work for all types

{ "outputFile": "wwwroot/css/site.css", "inputFile": "Styles/site/scss/site.scss", "outputUTF8Identifier": false, "minify": { "enabled": false }, "options": { "sourceMap": true, "relativeUrls": false } }

// the back ticks are putting it in one line, sorry for the formatting

failwyn avatar Mar 21 '25 21:03 failwyn

Is it possible to use the compilerconfig.json.defaults to configure outputUTF8Identifier so it always "false" instead of configure it for each entries?

alexandrejobin avatar May 16 '25 18:05 alexandrejobin

I haven't tested it, but that should work

failwyn avatar May 16 '25 19:05 failwyn

How should it be written in the defaults file? At the root level? I haven't seen any example to configure that kind of properties.

alexandrejobin avatar May 16 '25 19:05 alexandrejobin

I've just tried to add it at the rook without success

{
  "outputUTF8Identifier": false
  "compilers": {
    "less": {
      "autoPrefix": "",
      "cssComb": "none",
      "ieCompat": true,
      ...
  }
}

alexandrejobin avatar May 20 '25 13:05 alexandrejobin

It should probably be in the SASS default options; I'll try to find time to test it, but I have a deadline for work at the moment, so it may be a bit.

failwyn avatar May 20 '25 14:05 failwyn

I've just tested it in the SASS options and it doesn't work.

alexandrejobin avatar May 20 '25 14:05 alexandrejobin

Would you mind opening a new issue for this as a feature request?

failwyn avatar May 20 '25 15:05 failwyn

Here's the new issue to have the possibility to transform some WebCompiler specific properties as default value: #114

alexandrejobin avatar May 20 '25 16:05 alexandrejobin