Skip to content

Commit

Permalink
👽 [#724] Fix loading/resolving the font-awesome font files
Browse files Browse the repository at this point in the history
CRA seems to properly translate the relative path and include the files
while Vite requires some extra hints to properly point to the package
location before it can find the font files.

Unfortunately, both setups are not compatible, so in the vite config
we override the sass-variable to pass down to the sass module import,
where the default is set to the current, legacy behaviour.
  • Loading branch information
sergei-maertens committed Dec 3, 2024
1 parent beaf18c commit 4e13611
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/scss/components/_fa-icon.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@use 'sass:math';

@import '@fortawesome/fontawesome-free/scss/fontawesome';
@import '@fortawesome/fontawesome-free/scss/brands';
@import '@fortawesome/fontawesome-free/scss/regular';
@import '@fortawesome/fontawesome-free/scss/solid';
@import 'microscope-sass/lib/typography';

.fa-icon {
Expand Down
13 changes: 10 additions & 3 deletions src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// Open Forms SDK styles
// TODO: we should see if we can re-use even smaller bits to shed dead weight and
// reduce the bundle size
$fa-font-path: '../webfonts/' !default; // vite.config.mts overrides this
@use '@fortawesome/fontawesome-free/scss/fontawesome';
@use '@fortawesome/fontawesome-free/scss/brands';
@use '@fortawesome/fontawesome-free/scss/regular';
@use '@fortawesome/fontawesome-free/scss/solid';
@use '@fortawesome/fontawesome-free/scss/brands' with (
$fa-font-path: $fa-font-path
);
@use '@fortawesome/fontawesome-free/scss/regular' with (
$fa-font-path: $fa-font-path
);
@use '@fortawesome/fontawesome-free/scss/solid' with (
$fa-font-path: $fa-font-path
);
@use 'flatpickr/dist/flatpickr.min';
@use 'formiojs/dist/formio.form';
@use 'leaflet/dist/leaflet';
Expand Down
1 change: 1 addition & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default defineConfig({
css: {
preprocessorOptions: {
scss: {
additionalData: `$fa-font-path: '@fortawesome/fontawesome-free/webfonts/';`,
charset: false,
},
},
Expand Down

0 comments on commit 4e13611

Please sign in to comment.