We are including font awesome via
$fa-font-path: "#{$asset-path}/../../project/assets/fonts/fontawesome";
@import "fontawesome/fontawesome";
@import "fontawesome/brands";
@import "fontawesome/solid";
In our Shopware 6 SCSS files.
We noticed on some machines (we are building on server), that the generate CSS file contains "\0" null bytes
.fa-certificate:before {
content: "\0";
}
which leads to an output like this:
Shopware uses webpack to build the CSS file from SCSS.
What can be the reason for this additonal \0
?
We saw https://github.com/FortAwesome/Font-Awesome/issues/14660 but adding the
@charset "UTF-8";
at the beginning of the CSS file does not help.
When we copy the built file from one machine to the other, it works. So it does not seem to be a problem on serving the CSS by the server, but during the built process.
EDIT: Digging deeper:
In the fontawesome SCSS there is:
$fa-var-certificate: \f0a3;
...
.#{$fa-css-prefix}-certificate:before { content: fa-content($fa-var-certificate); }
// Convenience function used to set content property
@function fa-content($fa-var) {
@return unquote("\"#{ $fa-var }\"");
}
Unquote is a sass_function
- I don't know where the \0
comes from
EDIT2 We compared the file vendor/shopware/storefront/Resources/app/storefront/package-lock.json
on both machines, and they are both identical - so the same node package should be in use, just a slightly different node version (local: v14.18.2, server: v14.18.1). Still the problem is not reproducible locally.
If your webpack config is watching for CSS instead of SCSS, you'll be able to load all of Font Awesome's fonts by importing its CSS file directly into app.js like so: However, if you're following along with the tutorial repo, webpack will be watching for SCSS files instead CSS files, returning an error in the terminal:
If webpack finds any font files being referenced inside of any CSS files being pulled into app.js, it'll duplicate the font files, and place them into whatever directory we specify using outputPath. This is required for our fonts to be referenced correctly within our compiled down version of our CSS located in /dist.
Yes font-awesome-webpack is missing because it no worked. I've had to use font-awesome directly in order to work correctly (with css-modules). Gorav, I don't know what is up with my config.
At the minimum, you’ll need to add to add fontawesome-svg-core The Pro version of Font Awesome is great – and a cheap way to support the project. We highly recommend it. First we add variables with our license to the root of our package: If you’re signed into the Font Awesome site, you can find your token here. Next, add the Pro package:
While not an ideal solution, simply replacing the \0
character in the compiled css file seems to do the trick:
sed -i 's/\\0"/"/g' public/theme/c220db9f32a7e868b9b8009bdaa080d0/css/all.css
I've discovered when I use the sass
binary directly it does not append the \0
characters:
$ ./vendor/shopware/storefront/Resources/app/storefront/node_modules/.bin/sass custom/static-plugins/Theme/src/Resources/app/storefront/src/scss/_font-awesome.scss
The generated code looks a bit different though:
.fa-zhihu:before {
content: "\f63f";
}
This seems to indicate the error is somewhere in shopware's webpack stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With