snowpack super fast than webpack. but I fetch some problem like when I import font-awesome my react project it fail. cause snowpack won't load font (.woff2) file.
snowpack official website not about this topic.
now how to fix it?
snowpack super fast than webpack. but I fetch some problem like when I import font-awesome my react project it fail. cause snowpack won't load font (.woff2) file.
snowpack official website not about this topic.
now how to fix it?
Copyright © 2021 Jogjafile Inc.
Well, right now it's a pain. I'll explain why.
The theory:
plugin-postcss
along with PostCSSpostcss-import
plugin. Your PostCSS config could look like this:@font-face
paths, your CSS need to be in a subfolder likecss/app.css
, because Font Awesome CSS imports fonts fonts in a relative way (../webfonts
).node_modules/@fortawesome/fontawesome-free/webfonts
directory into thewebfonts
directory of your build destination (mine is_dist
). This could be solved easily with the following code in yoursnowpack.config.js
:But it won't work in production because of this issue, basically Snowpack can't mirror anything from
node_modules
because this folder is hardcoded-excluded.I found a workaround using the
ncp package
(npm i --save-dev ncp
) and the@snowpack/plugin-run-script
. Add the plugin tosnowpack.config.js
and set thecmd
option to look like this:This will copy the Font Awesome
webfonts
folder contents into the web root folder namedwebfonts
, so CSS relative imports will work.If you don't use PostCSS, mount the folder at step 3 (will work in dev mode, not in production), use
ncp
as explained (will solve the issue in production) and add this line to your application JavaScript entry point: