I have font-awesome in my node_modules folder so I try to import it in my main .scss file like so:
@import "../../node_modules/font-awesome/scss/font-awesome.scss";
But Webpack bundling compilation fails, telling me
Error: Cannot resolve 'file' or 'directory' ../fonts/fontawesome-webfont.eot
because the font-awesome.scss file refers to a relative path, '../fonts/'.
How can I tell scss \ webpack to @import another file, and use that file's folder as the home folder so that its relative paths work as it expects?
Use
where the
$fa-font-path
variable is seen infont-awesome/scss/_variables.scss
As is described overhere: http://fontawesome.io/get-started/
There doesn't appear to be any way to @import files that have their own relative paths in SCSS \ SASS.
So instead I managed to get this to work:
Import the scss \ css font-awesome file in my .js or .jsx files, not my stylesheet files:
Add this to my webpack.config file:
Following worked for me:
This is to import the
font-awesome
& required fonts in the project. Other change is inwebpack
configurations, to load required fonts usingfile-loader
.See angular site for instructions Include Font Awesome
v.4 (symofony 4 + webpack)
What worked for me was to add
resolve-url-loader
and enablesourceMaps
I already imported font-awesome in my root
.scss
file:This root file is imported in my
main.js
file defined as Webpack's entrypoint:Then my final webpack module rules look like so:
Note:
I used
mini-css-extract-plugin
, which can be registered like this:url-loader
requiresfile-loader
to be installed, so if you get an error like:cannot find module file-loader
, then just install it:Useful Links:
https://github.com/webpack/webpack/issues/2771#issuecomment-277514138 https://github.com/rails/webpacker/issues/384#issuecomment-301318904