kirby-webpack icon indicating copy to clipboard operation
kirby-webpack copied to clipboard

Issues with loading assets in production

Open timothyachumba opened this issue 3 years ago • 11 comments

Hi i am able to load this font file in my dev environment but when i move to production i get a 404. I'm not sure what to do. By the way I changed my css preprocessor to SASS.

@font-face
  font-family: favorit
  src: url("/assets/fonts/fl.woff2") format('woff2')
  src: url("/assets/fonts/fl.woff") format('woff')
  src: url("/assets/fonts/fl.ttf") format('truetype')
  font-weight: 300
  font-style: normal
  font-display: fallback

timothyachumba avatar Nov 19 '21 21:11 timothyachumba

Try to define your path relative to the bundle.css, ie:

 src: url("../fonts/fl.woff2") format('woff2')

If you have assets/fonts and assets/builds/bundle.css.

arnaudjuracek avatar Nov 21 '21 09:11 arnaudjuracek

Yeah, I tried this but I just get errors. Seems like it can't resolve that URL.

CleanShot 2021-11-22 at 10 26 06@2x

timothyachumba avatar Nov 22 '21 10:11 timothyachumba

Your fonts should be relative to your bundle.css, not your sass file :

  • src/your-file.sass
  • www/assets/builds/bundle.css
  • www/assets/fonts/f1.woff

And then in your-file.sass :

// Resolve to www/assets/builds/../fonts/fl.woff2
src: url("../fonts/fl.woff2") format('woff2')

arnaudjuracek avatar Nov 22 '21 11:11 arnaudjuracek

Hmmm i thought whats what I've done. The sass file type.sass is in a subfolder but it's included n the index.sass

CleanShot 2021-11-22 at 11 25 07@2x

timothyachumba avatar Nov 22 '21 11:11 timothyachumba

What font paths do you call in src/libs/type.sass ?

arnaudjuracek avatar Nov 24 '21 18:11 arnaudjuracek

@font-face
  font-family: favorit
  src: url("/assets/fonts/fl.woff2") format('woff2')
  src: url("/assets/fonts/fl.woff") format('woff')
  src: url("/assets/fonts/fl.ttf") format('truetype')
  font-weight: 300
  font-style: normal
  font-display: fallback

timothyachumba avatar Nov 24 '21 18:11 timothyachumba

@font-face
  font-family: favorit
- src: url("/assets/fonts/fl.woff2") format('woff2') 
+ src: url("../fonts/fl.woff2") format('woff2')
  …
  font-weight: 300
  font-style: normal
  font-display: fallback

arnaudjuracek avatar Nov 24 '21 18:11 arnaudjuracek

This is the error i get

in ./src/index.sass (./node_modules/css-loader/dist/cjs.js??ref--5-1!./node_modules/postcss-loader/dist/cjs.js??ref--5-2!./node_modules/resolve-url-loader??ref--5-3!./node_modules/sass-loader/dist/cjs.js??ref--5-4!./src/index.sass)
Module not found: Error: Can't resolve './fonts/fl.ttf' in '/Users/timothyachumba/Sites/deep-time/src'

timothyachumba avatar Nov 24 '21 18:11 timothyachumba

seems like it doesn't recognise the two dots, it only shows one Can't resolve './fonts/fl.ttf'

timothyachumba avatar Nov 24 '21 18:11 timothyachumba

Clearly './fonts/fl.ttf' and '../fonts/fl.ttf' are two differents paths. You may have broken something in the webpack configs when you changed your preprocessor to SASS.

arnaudjuracek avatar Nov 24 '21 18:11 arnaudjuracek

I'm pretty sure all I changed was line 12 in the main.config.js file

const entries = {
  'src/index.js': 'www/assets/builds/bundle.js',
- 'src/index.scss': 'www/assets/builds/bundle.css'
+ 'src/index.sass': 'www/assets/builds/bundle.css'
}

timothyachumba avatar Nov 24 '21 18:11 timothyachumba