Open llRandom opened 1 year ago
Either the font-awesome
package root import or the package's Sass variable $fa-font-path
will need to be set to allow the fonts to be found. Previously the Sass deep import worked on its own due to Webpack specific behavior.
The first option also has the advantage of not requiring the font-awesome Sass files to be processed on every application build.
Package root example:
@import 'font-awesome';
Variable example:
$fa-font-path: 'font-awesome/fonts';
@import 'font-awesome/scss/font-awesome';
Thanks! It works for esbuild but it breaks regular build. Is it ok?
The first option should work in both (@import 'font-awesome';
). The later should as well but currently doesn't for the default builder. A fix for that will require some additional investigation.
Noticed the tags of this removed the browser-esbuild
and changed to just the browser
. Pretty sure this error is just with the browser-esbuild
option though. The regular browser
setup uses webpack and pulls in the resolve-url-loader
which handles the hoisting of files and rewriting of urls. I've yet to discover (still looking) if the esbuild
option has the equivalent plugin used, but if it's just using the basic sass compilation, that would be the problem here.
The defect here is with the Webpack-based build system. The following should work with the Webpack-based build system but does not:
$fa-font-path: 'font-awesome/fonts';
@import 'font-awesome/scss/font-awesome';
The Webpack-based build system also fails with just @import url(font-awesome/scss/font-awesome.scss);
. Both of these work with the esbuild-based build system though.
However, the first option in the comment above (just @import 'font-awesome';
) does work in both build systems and is the preferred option. It avoids the need to deep import into a package as well as manipulate Sass variables.
I'm wondering if there's just a typo there, as with webpack builds what you're describing works (with a little tweak). For example, this works perfectly fine with the webpack builds (in fact, this is exactly what our production setup is doing)
@import '@fortawesome/fontawesome-pro/scss/fontawesome';
This is because the webpack builds when it can't find a relative file goes up directories looking for node_modules
and trying to match, which it eventually will (assuming you have it installed) at the root level's node_modules directory.
Now, the reason why your @import url(...);
isn't working is because Sass translates that as a plain css @import
, not a sass one (https://sass-lang.com/documentation/at-rules/import#plain-css-imports), and therefore likely isn't trying to do any node_module searching.
I'm not sure where it's documented that @import 'font-awesome'
is the preferred option, nor am I sure how that would feasibly work. When dealing with JS files, that works fine because the package.json
has a main
entry that describes the main entry point. However with Sass files, no such entry exists, so there's no way for the system to infer what the desired file is when you simply try to import based off the package name.
I'm not sure where it's documented that @import 'font-awesome' is the preferred option, nor am I sure how that would feasibly work. When dealing with JS files, that works fine because the package.json has a main entry that describes the main entry point. However with Sass files, no such entry exists, so there's no way for the system to infer what the desired file is when you simply try to import based off the package name.
There are several entry field values as well as exports conditions that are available for use with stylesheets. Both style
and sass
are available for use in both cases for build systems as well as other bundlers such as Vite. The Angular Material package has multiple in the exports condition form: https://github.com/angular/components/blob/7c48a36b5d153af55f42349bb3a80a3d950570e6/src/material/package-base.json
Ah, thanks for clarifying the exports
entry, forgot about that.
However, with that being said, font-awesome doesn't have an exports
entry in their package json. Nor can we always assume that a library would have an exports
entry.
Bringing this back full circle, we return to the difference between how the esbuild is working and how the historical browser build works. The browser build appropriately uses the resolve-url-loader
to change urls in scss files, and this happens inside the webpack build. However, the esbuild (not webpack) does not make use of a library to handle deeply nested urls and how to resolve them (hence why I suggested that the esbuild
tag be returned to this issue rather than removed, since it works fine with the regular browser
build)
font-awesome
does have a style
entry field which is why it works as a bare specifier: https://github.com/FortAwesome/Font-Awesome/blob/afecf2af5d897b763e5e8e28d46aad2f710ccad6/js-packages/%40fortawesome/fontawesome-free/package.json#L53
My oversight, I was looking for exports
😄
Regardless, the issue here is about handling urls, and isn't a webpack issue but rather an esbuild issue.
It is easy to miss a top-level field in a package.json. The newer exports
field does make it much more convenient to discover what's available from within package.
What does one have to do if one wants to use the solid variant of the FA font? That doesn't seem possible when using the bare specifier?
@clydin politely pinging you because the suggestion to use the package root import was yours originally and it does seem promising.
is there a solution that would work for both esbuild and webpack? esbuild is now default app builder but karma build is still webpack-based and both reference styles so either one or the other would fail with suggested workaround
Im stuck at this stage. I don't know what to do with my setup. Any solution?
Command
build
Is this a regression?
The previous version in which this bug was not present was
No response
Description
I'm getting an error for fontawesome & icomoon references when switching to esbuild. It works fine for default angular build
Minimal Reproduction
@import 'font-awesome/scss/font-awesome';
Exception or Error
Your Environment
Anything else relevant?
No response