webpacker: ./bin/webpack-dev-server command line arguments are ignored
I am using the rails/webpacker
v4.0.2
.
When I run the ./bin/webpack-dev-server
with command line arguments, those actually don’t get passed to the actual webpack-dev-server
. As a result - I cannot pass the needed arguments.
Steps to replicate the issue:
-
Set the breakpoint here: https://github.com/rails/webpacker/blob/7a241e75bd5376524348466aa2daa11661c49f41/lib/webpacker/dev_server_runner.rb#L58
-
Run the command with the debuger:
./bin/webpack-dev-server --https --cert ~/.ssl/private.pem --key ~/.ssl/private.key
- See that the arguments were ignored.
The command being built here basically is not passing any of the original
@args
to thewebpack-dev-server
command:
def execute_cmd
env = Webpacker::Compiler.env
cmd = if node_modules_bin_exist?
["#{@node_modules_bin_path}/webpack-dev-server"]
else
["yarn", "webpack-dev-server"]
end
cmd += ["--config", @webpack_config]
cmd += ["--progress", "--color"] if @pretty
Dir.chdir(@app_path) do
Kernel.exec env, *cmd
end
end
Related issues
- https://github.com/rails/webpacker/issues/612#issuecomment-319930567
- https://github.com/webpack/webpack-dev-server/issues/1695
Suggested solution
Add the line to pass the arguments from @argv
to the real webpack-dev-server
command.
Changed code:
def execute_cmd
env = Webpacker::Compiler.env
cmd = if node_modules_bin_exist?
["#{@node_modules_bin_path}/webpack-dev-server"]
else
["yarn", "webpack-dev-server"]
end
cmd += ["--config", @webpack_config]
cmd += ["--progress", "--color"] if @pretty
cmd += @argv # <===== Add this line here
Dir.chdir(@app_path) do
Kernel.exec env, *cmd
end
end
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Pass the command line arguments to the webpack-dev-server module (#2000) — committed to metricswatch/webpacker by deleted user 5 years ago
- Pass the command line arguments to the webpack-dev-server module (#2000) — committed to metricswatch/webpacker by deleted user 5 years ago
A solution which worked for me is to set
https: true
in thewebpacker.yml
and read cert and key in the development.js:FYI setting
https
inwebpacker.yml
to this currently works just fine (I struggled with this for a bit as well):Replace
key
andcert
with a path to your SSL cert.I’m on
Webpacker 4.0.7
I would appreciate this feature, as certain configuration parameters for webpack-dev-server (color, info, progress, and stdin) can only be set at the command line.
This is super useful, and in fact required for me.
Use case:
I integrate with a bunch of third party platforms via OAuth. Some of them doesn’t work with localhost (Mailchimp, for example), so I moved to 127.0.0.1 but others don’t support 127.0.0.1 (FB Ads). So I decided to use a custom domain for local dev.
But then I started to get warnings that the FB’s JS stuff (that I need to refresh the FB token, that expires after 90 days now without being able to refresh it with a refresh token) will stop working over http and require https.
So, I need my app to be on something that is a domain (not an IP), not localhost and needs to be HTTPS.
i.e., I pretty much need this to be able to use Let’s Encrypt and not a self-signed certificate (or anything custom).
What can we do to make it happen?
In the meantime, I am using @marisveide’s fork (thanks!), but it’s only a short term solution 😃 You can use it like this:
./bin/webpack-dev-server --key ssl.server.key --cert ssl.server.crt
Thank you, @jipiboily - that’s exactly what’s needed for us as well! Will be switching to yours now! ✌️
For those like me who wanted to have a more recent fork, but also wants the patch from @marisveide, I made this fork + branch, which is branched off of the v4.0.7 tag with only one commit cherry-picked from @marisveide’s fork (thanks for that @marisveide!): https://github.com/metricswatch/webpacker/tree/4.0.7-with-custom-ssl
In your Gemfile, you should use:
For future readers @PatKoperwas solution runs into the same problem that @nicklozon identified.
It gets the key and cert passed as configuration but then the DevServer thinks https is not enabled when this line is called: https://github.com/rails/webpacker/blob/master/lib/webpacker/dev_server_proxy.rb#L15.
Maybe the below method can be changed to just check for a truth value instead of the exact boolean true?
Here is the related PR: https://github.com/rails/webpacker/pull/2002
Hi, @hwhelchel! I am using my fork at the moment - while waiting this PR to be merged: https://github.com/marisveide/webpacker
Since we can’t pass arguments to the
webpack-dev-server
I pasted my key and cert intowebpacker.yml
https
field as a workaround as suggested above.This works when connecting directly to the
webpack-dev-server
on port 3035, but does not when requesting assets directly from the rails server which reverse proxies the request to thewebpack-dev-server
without using SSL. Webpacker is treating the Webpackhttps
configuration field as boolean indev_server.py
and anything other than “true” will result in regular http calls, such is the case of hard-oding the key and cert above.I think the real issue here is that webpacker made an incorrect assumption about a webpack-dev-server configuration - the
https?
method indev_server.rb
should not be expecting strictly boolean, or it should not be using another library’s configuration to make decisions, though I understand the desire since the two are directly tied to each other.This is my workaround in
dev_server.rb
, defaults to true when not false:This doesn’t work if you use the webpacker.yml file instead of .js.
You could pass plain certificate PEM strings to yml https: key, but then the other thing breaks - it doesn’t recognize it as “https”.