-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Devserver has problems serving static assets with assetsPublicPath != '/' #1176
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
Comments
First of all, why are you treating them as static assets instead of letting Webpack handle them by putting them into If that's not possible, we will have to work something out, becaue it seems that webpack-dev-server doesn't apply the I will investigate a bit more if that's really the case and what to do about that, but for now we will have to work around that. We can do that by generating the static paths dynamically depending on environment: // /config/dev.env.js
STATIC_PATH_PREFIX: '"/"'
// /config/prod.env.js
STATIC_PATH_PREFIX: '"/foo/"' Then add a helper to your app: Vue.mixin({
methods: {
$toStaticPath(path = '') {
return process.env.STATIC_PATH_PREFIX + path
}
}
}) and use it like this: <img v-bind:src="$toStaticPath('static/images/example.png')"> |
Thank you, I will try to use assets whenever it's possible and Will use this for the rest of my urls |
Like I said in #1141, adding CopyWebpackPlugin to the dev config (with the exact same configuration except with |
I see how that could provide a workaround, but it would have to copy to a different location, e.g. So thanks, I will fall back to this if I don't find a way to make webpack-dev-server serve the files appropriately. |
Oh, I just saw this: https://github.com/webpack-contrib/copy-webpack-plugin#this-doesnt-copy-my-files-with-webpack-dev-server
That could work after all. Thanks! |
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:
|
Hey, thanks for the feedback, that's very valuable. I'll add those fixes when I can. |
After the switch to CopyWebpackPlugin (#1176), historyAPIFallback had to be adjusted to still serve index.html from all catched paths correctly. See: #1176 (comment)
Hello @LinusBorg historyApiFallback: {
rewrites: [
{ from: /.*/, to: `${config.dev.assetsPublicPath}/index.html` },
],
}, I found that extra requests are related to favicon.ico. But it can work normally when I change back |
After the switch to CopyWebpackPlugin (#1176), historyAPIFallback had to be adjusted to still serve index.html from all catched paths correctly. See: vuejs-templates/webpack#1176 (comment)
* develop: bump template version fix bug with vuejs-templates#1202 Make CSS sourcemaps on by default Ensure page reloads in history mode serve index.html use old sourcemap option Add postcss-url to match postcss-import (vuejs-templates#1115) Change engine>node{4 => 6} for template (vuejs-templates#1206) Fix static file serving for publicPath != `/` (fix#1176) (vuejs-templates#1180) Load, render template version using helper (vuejs-templates#1202) fix typo in a comment (vuejs-templates#1183) fix vuejs-templates#1140
After the switch to CopyWebpackPlugin (#1176), historyAPIFallback had to be adjusted to still serve index.html from all catched paths correctly. See: vuejs-templates/webpack#1176 (comment)
After the switch to CopyWebpackPlugin (#1176), historyAPIFallback had to be adjusted to still serve index.html from all catched paths correctly. See: vuejs-templates/webpack#1176 (comment)
Uh oh!
There was an error while loading. Please reload this page.
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/templateThe 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 runnpm 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 inwww.example.com/static/images/example.png
instead ofwww.example.com/foo/static/images/example.png
If I change
config/index.js
and setassetsPublicPath: '/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 usingnpm run dev
can't find them as they are being referenced aslocalhost:8080/foo/static/images/example.png
but they seem to be atlocalhost: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 urlsThank you
The text was updated successfully, but these errors were encountered: