Skip to content

Commit

Permalink
Workarounds for Yarn not playing nicely on Windows
Browse files Browse the repository at this point in the history
- Bypass `yarn run` when running on Windows; instead, we can go directly
to `node_modules/.bin/`
- Create batch scripts so users don't need to type in `ruby bin/webpack`
manually

See discussion on rails#583
  • Loading branch information
soundasleep committed Jul 22, 2017
1 parent 2b0972a commit b480fa6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/install/bin/webpack-dev-server.bat.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@ruby bin\webpack-dev-server %*
8 changes: 7 additions & 1 deletion lib/install/bin/webpack-dev-server.tt
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ newenv = {
"ASSET_HOST" => DEV_SERVER_ADDR.shellescape
}.freeze

cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config",
if Gem.win_platform?
# Workaround for yarn not playing nicely with path separators
cmdline = ["#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color", "--config",
WEBPACK_CONFIG, "--host", LISTEN_IP_ADDR, "--port", PORT.to_s] + ARGV
else
cmdline = ["yarn", "run", "webpack-dev-server", "--", "--progress", "--color", "--config",
WEBPACK_CONFIG, "--host", LISTEN_IP_ADDR, "--port", PORT.to_s] + ARGV
end

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
Expand Down
1 change: 1 addition & 0 deletions lib/install/bin/webpack.bat.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@ruby bin\webpack %*
7 changes: 6 additions & 1 deletion lib/install/bin/webpack.tt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ unless File.exist?(WEBPACK_CONFIG)
end

newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV
if Gem.win_platform?
# Workaround for yarn not playing nicely with path separators
cmdline = ["#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG] + ARGV
else
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV
end

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
Expand Down

0 comments on commit b480fa6

Please sign in to comment.