Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with loading assets in production #71

Open
timothyachumba opened this issue Nov 19, 2021 · 11 comments
Open

Issues with loading assets in production #71

timothyachumba opened this issue Nov 19, 2021 · 11 comments

Comments

@timothyachumba
Copy link

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
@arnaudjuracek
Copy link
Member

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.

@timothyachumba
Copy link
Author

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

@arnaudjuracek
Copy link
Member

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')

@timothyachumba
Copy link
Author

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

@arnaudjuracek
Copy link
Member

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

@timothyachumba
Copy link
Author

@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

@arnaudjuracek
Copy link
Member

@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

@timothyachumba
Copy link
Author

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
Copy link
Author

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

@arnaudjuracek
Copy link
Member

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.

@timothyachumba
Copy link
Author

timothyachumba commented Nov 24, 2021

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'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants