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.

Devserver has problems serving static assets with assetsPublicPath != '/'

See original GitHub issue

Hello I have made a Vuetify app using vue-cli and vue init vuetifyjs/webpack-advanced the resulting code is this https://github.com/vuetifyjs/webpack-advanced/tree/master/template

The problem I have is that my production app isn’t in the root of the server and it is a subpath in www.example.com/foo. When I run npm run build all my static assets like images and fonts are referenced like /static/images/example.png, so the server doesn’t find them as they are being looked in www.example.com/static/images/example.png instead of www.example.com/foo/static/images/example.png

If I change config/index.js and set assetsPublicPath: '/foo' and change all my references from /static/... to /foo/static/... then my production server finds all my static assets but then my dev server using npm run dev can’t find them as they are being referenced as localhost:8080/foo/static/images/example.png but they seem to be at localhost:8080/static/images/example.png for some reason.

My ideal solution would be just to keep the references as /static and tell webpack or vueloader somehow that on npm run build it should prepend /foo to all of my assets urls. If that is impossible at least I would like to know a way to make my dev and production environments to work with the same code even though it implies to prepend manually /foo to my static assets urls

Thank you

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alxpppcommented, Dec 28, 2017

Thanks @LinusBorg! That has been bugging me for a while now. The latest development branch is working fine for me!

Two small hints for others updating from the old dev server:

  • Instead of assetsPublicPath: '/abc/' it now has to be assetsPublicPath: '/abc'
  • To get browser reloads working again, I had to change history api fallback to:
historyApiFallback: {
  rewrites: [
    { from: /.*/, to: `${config.dev.assetsPublicPath}/index.html` },
  ],
},
0reactions
SirM2zcommented, May 17, 2018

Hello @LinusBorg My browser generated extra duplicate requests when I added this configuration

historyApiFallback: {
  rewrites: [
    { from: /.*/, to: `${config.dev.assetsPublicPath}/index.html` },
  ],
},

before modifying: image

after modification: image

I found that extra requests are related to favicon.ico.

But it can work normally when I change back historyApiFallback: true

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serving static assets in webpack dev server - Stack Overflow
I originally had my images and .obj/.mtl files in a public folder that existed at the root of my application. I moved them...
Read more >
DevServer - webpack
If you're having trouble, navigating to the /webpack-dev-server route will show where files are served. For example, http://localhost:9000/webpack-dev-server .
Read more >
Static Asset Handling - Vite
Importing a static asset will return the resolved public URL when it is served: js import imgUrl from './img.png' document.getElementById('hero-img').src = ...
Read more >
webpack-dev-server
It also has a little runtime which is connected to the server via Socket.IO. ... Using this config webpack-dev-server will serve the static...
Read more >
HTML and Static Assets - Vue CLI
During build, asset links will be injected automatically. ... If you have a large app with many async chunks and your users are...
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