question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When I include semantic or bootstrap in my main.js I end up with a 404 not found error for the fonts

Apparently, the output path of fonts go to the root of my web server like this

http://localhost/build/fonts/icons.woff2

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:41 (12 by maintainers)

github_iconTop GitHub Comments

7reactions
weaverryancommented, Jun 20, 2017

@heitorvrb Ah, thanks for the extra info! If you’re deployed under a subdirectory, that should be reflected in your setPublicPath:

// this is your *true* public path
.setPublicPath('/mySymfonyApp/build')
// this is now needed so that your manifest.json keys are still `build/foo.js`
// i.e. you won't need to change anything in your Symfony app
config.setManifestKeyPrefix('build')

You can see an example of this in the tests as well: https://github.com/symfony/webpack-encore/blob/db980b4018104b8f16a9f83111078ce86e7b76ad/test/functional.js#L180

Webpack must be aware of the true public path, because if you use “code splitting”, then webpack itself will make AJAX requests for assets (so it needs to know the real path). That’s why the config lives in webpack.config.js, instead of allowing your app (i.e. Symfony) to “fix” the subdirectory.

Let me know if that helps! I’ll open an issue on the docs about this.

6reactions
stoccccommented, Feb 2, 2018

@kevinpapst @weaverryan

I am in this scenario:

  • my symfony app is deployed in production under a subdirectory, e.g. www.myhost.com/apps/mySymfonyApp
  • the same app is under www.myhost.com/some/development/path/mySymfonyApp for development purposes and under www.myhost.com/some/demo/path/mySymfonyApp for demo purposes
  • if possibile, I don’t want to care in my config what is the path where the app is deployed

I have deleted these two lines of code in version 0.17.2 (they add a traling slash if it is not present), so that I can have a public path defined as '' (otherwise it is transformed to '/').

With this configuration in webpack.config.js

.setOutputPath('public/build/')
.setPublicPath('')
.setManifestKeyPrefix('build/')

all works correctly:

  • I can access assets from twig with

     {{ asset('build/app.js') }}
    
  • And if some scss file (like in Bootstrap) uses some other file (like glyphicons fonts) they are referenced properly. For example glyphicons-halflings-regular.eot is referenced as url(fonts/glyphicons-halflings-regular.f4769f9b.eot) in compiled css.

I am wondering: is this solution acceptable or are there some other consequences/scenarios which I can’t figure out (I’m new to encore/webpack and nodejs…)?

If it is acceptable, we could test if publicPath is not empty before adding the trailing slash.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong path font not working - Stack Overflow
I've use the font face but it seems that I'm missing something on the declaration. How should i declare to make my font...
Read more >
Typeface self hosted font wrong path? - Foundry - Elixir Support
A possible bug with Typeface: may be a wrong path when using Self hosted font on 2nd child-level page. Works fine Inside Rapidweaver...
Read more >
Fontawesome with webpack and Laravel 5.4, wrong path to ...
I want to get some fonts loaded to my app, but I have just issues. Before I used gulp and everything worked fine....
Read more >
Wrong font URL Loading - WordPress.org
The issue in that URL is the /home1/syncrion/public_html/ , that is the full path to my site from the old host, and wouldn't...
Read more >
Wrong path to font directory - Mobirise Forums
I think I've identified the issue / bug. I've imported an old project file with working fonts and tried to publish it. I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found