-
-
Notifications
You must be signed in to change notification settings - Fork 200
Relaxed public path requirements with dev-server #96
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
Relaxed public path requirements with dev-server #96
Conversation
Hey @weaverryan thanks for the heads-up! I gave this a go with config like this: if (!Encore.isProduction()) {
Encore
.setPublicPath('http://dev.vcap.me:8080')
.setManifestKeyPrefix('/assets/build/')
;
} and when I run the command with Example - paths to CSS are being generated as relative: <link href="/assets/build/global.css" rel="stylesheet"> if I disable the above Encore settings in my webpack conf, my path to CSS is this: <link href="http://0.0.0.0:8080/assets/build/global.css" rel="stylesheet"> have I missed something? |
Thanks @samjarrett! Hmm... I bet I missed one small detail - i'll take a look at this soon and ping back when I'm sure it's ready :) |
Hi @weaverryan,
I think this will create some troubles when using live reloading with Browser Sync. Resources are not written in file system but kept in memory. So do we need that url: How do you think i could do with this PR to address #78 ? |
Yo @davidmpaz!
It won't, but this was step 1 towards that (they're kind of unrelated, but work in the same area). So, we're definitely going to address that :).
You're 100% right. Your link/script tags need to be prefixed with the absolute URL to the dev-server... and, internally, webpack's Buuuuut, in @samjarrett's situation, the tl;dr; for 99% of the use-cases, the assets will still be prefixed with the dev server URL. But this PR allows them to be disconnected. Well, it will once I get it fully working ;).
I just shot you a question over on that issue. When we answer that, I think it'll be a pretty easy PR. We're throwing the exception now because we simply cannot determine the |
@weaverryan, got it thanks!! |
when using dev-server and an absolute URL for publicPath to get webpack encore working in docker environment
test for successful config set when using devServer and setPublicPath with an absolute URL
- when using devServer and absolute URL for publicPath - also add test case
9848b4f
to
4bc1e19
Compare
My apologies @samjarrett - this is (and was) totally ready to go after all :). There's one mistake in your script: if (!Encore.isProduction()) {
Encore
.setPublicPath('http://dev.vcap.me:8080')
// I removed the opening slash
.setManifestKeyPrefix('assets/build/')
;
} The manifest key normally doesn't start with a <script src="{{ asset('assets/build/main.js') }}"> Because you had I'm going to make a PR to guarantee that Soooo, make this one line change, and let me know how things look. I appreciate it! |
Works well @weaverryan, thanks! |
…ausk, weaverryan) This PR was merged into the master branch. Discussion ---------- Relaxed public path requirements with dev-server Fixes #59 and finishes #66. * Adds a new `--keep-public-path` option for `dev-server`. When used, your `publicPath` is not prefixed with the dev server URL. For #59, this means you can use `setPublicPath('/build')` with the dev-server, and your assets will remain local (i.e. `/build/main.js` instead of `http://localhost:8080/build/main.js`). * It is now possible to pass an absolute URL to `setPublicPath()` without an error when using `dev-server`. But, we issue a big warning, because this means your assets will point to to that absolute URL, instead of to the dev-server (which for most setups, is not what you want). @samjarrett I'd love to confirm that this would solve your issue in Docker :). Commits ------- 4bc1e19 Using real public path, though it doesn't look like it matters 92e22af Allowing an absolute publicPath with dev-server, but showing a warning 830fdb5 Adding --keep-public-path to dev-server to allow you to fully control the publicPath b27f7c9 Reversing some of the changes we won't do for now, and adding the failing test e206a12 fix issue in generated public path of manifest.json eb5565b convert error into warning 910b6bc convert error into warning
Cheers - thanks for checking @samjarrett! |
@weaverryan I can't figure out how to use this feature, I keep getting
even though the keep-public-path option is shown in the --help:
|
@adrienbrault It's caused by the fact that the Unless I'm missing something too it didn't seem to work in the version it was released in either (v0.12.0), would you mind opening an issue about it ? |
@Lyrkan Are you saying that the |
@weaverryan Looks like it...
I don't know what could've caused it to break... maybe a dependency that got updated? The issue that I referenced in my previous comment seems quite old though. |
glad I found this thread. When I run the wepack-dev-server in the docker container, it should not bind to localhost (and would be inaccessible from docker-host) We HAVE to use --host 0.0.0.0, so that the manifest.json will always contain: Shouldn't setting the publicPath be mentioned here: best regards |
Yea - it almost definitely should. And we should mention Docker specifically. Could you open a doc PR or issue and dump your information there? It would be really helpful :) |
i will |
… to all interfaces This is the discussion, for setting an absolute url as publicPath, when you're binding the dev server not to localhost but to any external interface (0.0.0.0) and disable host checking. This is the related discussion: symfony/webpack-encore#96 best regards philipp
Fixes #59 and finishes #66.
Adds a new
--keep-public-path
option fordev-server
. When used, yourpublicPath
is not prefixed with the dev server URL. For dev-server inside docker? #59, this means you can usesetPublicPath('/build')
with the dev-server, and your assets will remain local (i.e./build/main.js
instead ofhttp://localhost:8080/build/main.js
).It is now possible to pass an absolute URL to
setPublicPath()
without an error when usingdev-server
. But, we issue a big warning, because this means your assets will point to to that absolute URL, instead of to the dev-server (which for most setups, is not what you want).@samjarrett I'd love to confirm that this would solve your issue in Docker :).