Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack build of Font Awesome adds \0 null-byte on one machine, not on others

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:

Nullbyte

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.

like image 654
Alex Avatar asked Dec 14 '21 10:12

Alex


People also ask

Why can't I load Font Awesome's fonts into my Webpack app?

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:

Why does Webpack duplicate the font files in my App?

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.

Is Font-Awesome-Webpack missing?

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.

How to add fontawesome-SVG-core to your project?

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:


Video Answer


1 Answers

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.

like image 104
kolaente Avatar answered Oct 22 '22 23:10

kolaente