Skip to content
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

Dynamic port for webpacker-dev-server #767

Closed
monai opened this issue Sep 6, 2017 · 11 comments
Closed

Dynamic port for webpacker-dev-server #767

monai opened this issue Sep 6, 2017 · 11 comments

Comments

@monai
Copy link
Contributor

monai commented Sep 6, 2017

Webpacker configuration file is extensively reloaded and it seems there is no straight forward way to dynamically set dev server port, e.g., using Foreman to start Rails and webpacker-dev-server. Any suggestions how to do that?

@gauravtiwari
Copy link
Member

gauravtiwari commented Sep 6, 2017

What do you mean by dynamic port? You want to specify a port on runtime i.e. inside your Procfile? You can change port inside config/webpacker.yml, no?

@monai
Copy link
Contributor Author

monai commented Sep 6, 2017

I don't want to have dev server port hardcoded to config/webpacker.yml. I can pass dev server port via command line argument but Rails uses the port from config/webpacker.yml.

@javan
Copy link
Contributor

javan commented Sep 6, 2017

I don't want to have dev server port hardcoded to config/webpacker.yml

Can you expand on that? It it adding friction to your development setup in some way?

@gauravtiwari
Copy link
Member

@javan We allow passing CLI arguments to binstubs, which can change host and port at runtime but since we also got proxy that's using values from webpacker.yml, CLI arguments are never used: https://github.com/rails/webpacker/blob/master/lib/install/bin/webpack-dev-server.tt#L29

One solution is we set explicit env vars based on these arguments so we can use them as well inside dev server configuration: https://github.com/rails/webpacker/blob/master/lib/webpacker/dev_server.rb#L28

# inside binstubs: 
ENV['WEBPACK_DEV_SERVER_PORT'] ||= args('--port')
ENV['WEBPACK_DEV_SERVER_PORT'] || fetch(:port)

@javan
Copy link
Contributor

javan commented Sep 6, 2017

We allow passing CLI arguments to binstubs, which can change host and port at runtime

I still don't understand why we do that. Why can't the sole source of configuration be webpacker.yml?

@gauravtiwari
Copy link
Member

Personally, I haven't really had any use for this :) but I guess for teams where folks are using different setup, say someone using a Docker container and someone using puma-dev, it would be nice to override the settings at runtime instead of committing conflicting config/webpacker.yml

@javan
Copy link
Contributor

javan commented Sep 6, 2017

I'd prefer that go in Webpacker itself and then remove all the CLI arg wrangling in bin/webpack-dev-server:

--- a/lib/webpacker/dev_server.rb
+++ b/lib/webpacker/dev_server.rb
@@ -25,7 +25,7 @@ class Webpacker::DevServer
   end
 
   def port
-    fetch(:port)
+    ENV['WEBPACK_DEV_SERVER_PORT'] || fetch(:port)
   end

@gauravtiwari
Copy link
Member

Yeah, makes sense 👍

@monai
Copy link
Contributor Author

monai commented Sep 7, 2017

@javan I and my coworkers usually work with at least two running Rails projects. For each project, there is separate dev server. So with this development setup, we have to hardcode unique port in webpacker.yml in every project. The latter snippet you posted solves our issue. Are you going to implement it or would you rather prefer PR?

@gauravtiwari
Copy link
Member

Fixed in #843

@gauravtiwari
Copy link
Member

3.0.2 released 👍

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

No branches or pull requests

3 participants