Skip to content

Allow usage of devServer combined with an absolute URL as publicPath #66

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

Closed
wants to merge 4 commits into from

Conversation

robertfausk
Copy link
Contributor

This fixes #59 when webpack encore is used inside a docker container and webpack-dev-server needs an absolute URL.

I'm not sure about printing and message of warning.
I used console.log for printing analogous to "bin/encore.js" but maybe FriendlyErrorsWebpackPlugin should be used... There aren't any other warnings yet whjch I could take for reference.

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
@robertfausk robertfausk changed the title Convert error into warning when using devServer and setPublicPath with an absolute URL Allow usage of devServer combined with an absolute URL as publicPath Jun 30, 2017
@weaverryan
Copy link
Member

Yes! Thanks for the PR!

+1 for how you've done the warning. It's quite likely we'll need to refactor into more of a "logging" system... but that can be done easily later.

I think we should add a new flag to activate this behavior - e.g. encore dev-server --without-dev-server-public-path... or... something shorter? :). The current behavior is to override the publicPath with the URL to the dev server (and to throw an exception for clarity if the user is setting publicPath to some other host name). What I really want, is to tell Encore to stop doing that.

With this new flag, if I have Encore.setPublicPath('/build'), I don't need to change that to Encore.setPublicPath('http://localhost/build')... I can just leave it alone... and Encore will now continue to just use /build as the publicPath for all assets. With this flag passed, we would still allow someone to set an absolute URL to their publicPath, but it wouldn't be necessary.

I think it'll also simplify things - we won't need a warning anymore: we'll throw an exception like now... unless they have the new --without-dev-server-public-path flag (then we will totally be ok with allowing them to set the publicPath to an absolute URL).

Wdyt?

update to symfony/webpack-encore
@weaverryan
Copy link
Member

I'm working on this locally - I've incorporated your commits. So, I'll close this and make a new PR soon :)

@weaverryan weaverryan closed this Jul 13, 2017
weaverryan added a commit that referenced this pull request Jul 21, 2017
…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
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

Successfully merging this pull request may close these issues.

dev-server inside docker?
2 participants