-
Notifications
You must be signed in to change notification settings - Fork 359
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
Allow removing @charset atrule with expanded OutputStyle #567
Comments
What's your use-case here? If you want to minimize the number of bytes Sass produces, that's what
This isn't strictly true; the
MDN's use of "cannot" here is overly strong; |
We do have a fairly uncommon use case use, making this possibly a nice-to-have depending on how usability gets affected. I work on a website-generating engine, where stylesheets are embedded as <style> elements in template files. Being in a <style> element, the (Our engine also currently escapes UTF-8 characters—hence why I've filed #568—which makes the |
#644 sorted this out for the CLI and the Dart API! But the JavaScript API is still out of luck. Any chance we could get the |
The current JS API needs to be overhauled, and it's generally not a good practice to add API surface to something that will be deleted. The design for the next gen JS API is tracked here. |
@nex3 Hi, why the @charset declaration is not added when using js: const sass = require('sass');
const result2 = sass.renderSync({
outputStyle: 'expanded',
file: "./test.scss",
});
console.log('dart-sass(expanded):\n', result2.css.toString());
const result3 = sass.renderSync({
outputStyle: 'compressed',
file: "./test.scss",
});
console.log('dart-sass(compressed):\n', result3.css.toString()); scss file: .a-icon {
content: "\E91E";
}
.a-iconb {
content: "你好"
} output:
|
In compressed output style, we emit a Unicode byte-order mark instead. This has the same effect as |
@nex3 using the JS API for Dart Sass ("dart-sass 1.35.1 (Sass Compiler), dart2js 2.13.3 (Dart Compiler)") I have come across this small issue, in "compressed" mode the byte-order mark seems to be corrupting(?) the first @font-face declaration I had (Chrome Version 92.0.4515.131), i.e. fonts set to "100" were showing up as "300" rather than as "100" weight, the CSS works as expected in "expanded" mode, by adding a throw-away atrule in front solved issue for me e.g.
|
@tobyfisher Can you send me a repository with a minimal reproduction? |
@nex3 Maybe the spec changed since 2019? WhatWG spec is as forceful as Mozilla, as per your linked document https://drafts.csswg.org/css-syntax-3/#charset-rule:
This causes validators (e.g., AMP) to fail when the user injects sass-generated CSS in a Setting output style isn't correct, either: Unicode has also changed in the past few years. Now, TL;DR: both The solution is a |
I'm trying to figure out the root cause (quite a few complains: https://github.com/search?q=%22must+be+the+first+rule+in+the+file%22&type=issues) Is the cause concatenating multiple css files from various UI libraries used in a project? (which is a common use case) ? |
It is generally not safe to naively concatenate multiple CSS files, because CSS does have features that must appear in a certain order in the file (not just In other words, if you're seeing bugs due to a |
Thanks for clarification, Natalie! |
It looks like Dart Sass always prefixes stylesheets with a
@charset
atrule if the output style isn'tcompressed
.This is unnecessary for stylesheets embedded in <style> elements:
The MDN has a stronger interpretation of this:
Outputting the
@charset
atrule should be optional, because removing this atrule isn't trivial when maintaining a sourcemap.The text was updated successfully, but these errors were encountered: