From b480fa6218fab3bfdef70da65b9a9594fec12aa6 Mon Sep 17 00:00:00 2001 From: Jevon Wright Date: Sun, 23 Jul 2017 01:48:19 +1200 Subject: [PATCH 1/2] Workarounds for Yarn not playing nicely on Windows - 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 https://github.com/rails/webpacker/pull/583 --- lib/install/bin/webpack-dev-server.bat.tt | 1 + lib/install/bin/webpack-dev-server.tt | 8 +++++++- lib/install/bin/webpack.bat.tt | 1 + lib/install/bin/webpack.tt | 7 ++++++- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 lib/install/bin/webpack-dev-server.bat.tt create mode 100755 lib/install/bin/webpack.bat.tt diff --git a/lib/install/bin/webpack-dev-server.bat.tt b/lib/install/bin/webpack-dev-server.bat.tt new file mode 100755 index 000000000..c8ec8b2e2 --- /dev/null +++ b/lib/install/bin/webpack-dev-server.bat.tt @@ -0,0 +1 @@ +@ruby bin\webpack-dev-server %* diff --git a/lib/install/bin/webpack-dev-server.tt b/lib/install/bin/webpack-dev-server.tt index 6b0d1c829..cf8479454 100644 --- a/lib/install/bin/webpack-dev-server.tt +++ b/lib/install/bin/webpack-dev-server.tt @@ -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 diff --git a/lib/install/bin/webpack.bat.tt b/lib/install/bin/webpack.bat.tt new file mode 100755 index 000000000..857b3e080 --- /dev/null +++ b/lib/install/bin/webpack.bat.tt @@ -0,0 +1 @@ +@ruby bin\webpack %* diff --git a/lib/install/bin/webpack.tt b/lib/install/bin/webpack.tt index 31abc125e..6a3248aa8 100644 --- a/lib/install/bin/webpack.tt +++ b/lib/install/bin/webpack.tt @@ -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 From 34d8d4c2cbd853dc61f4a3957cca0d64b051f09e Mon Sep 17 00:00:00 2001 From: Jevon Wright Date: Mon, 24 Jul 2017 17:11:23 +1200 Subject: [PATCH 2/2] Update Changelog and README for Webpacker on Windows Do not generate batch files when installing --- CHANGELOG.md | 2 ++ README.md | 12 ++++++++++++ lib/install/bin/webpack-dev-server.bat.tt | 1 - lib/install/bin/webpack.bat.tt | 1 - 4 files changed, 14 insertions(+), 2 deletions(-) delete mode 100755 lib/install/bin/webpack-dev-server.bat.tt delete mode 100755 lib/install/bin/webpack.bat.tt diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f6ceaa85..29429b9c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ host: localhost ``` +- On Windows, `ruby bin/webpacker` and `ruby bin/webpacker-dev-server` will now bypass yarn, and execute via `node_modules/.bin` directly - [#584](https://github.com/rails/webpacker/pull/584) + ### Breaking changes - Add `compile` option to `config/webpacker.yml` for configuring lazy compilation of packs when a file under tracked paths is changed [#503](https://github.com/rails/webpacker/pull/503). To enable expected behavior, update `config/webpacker.yml`: diff --git a/README.md b/README.md index 3ef6fa599..b297dcb30 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ in which case you may not even need the asset pipeline. This is mostly relevant - [Error: listen EADDRINUSE 0.0.0.0:8080](#error-listen-eaddrinuse-00008080) - [throw er; // Unhandled 'error' event](#throw-er--unhandled-error-event) - [webpack or webpack-dev-server not found](#webpack-or-webpack-dev-server-not-found) + - [Running Webpack on Windows](#running-webpack-on-windows) - [Wishlist](#wishlist) - [License](#license) @@ -1185,6 +1186,17 @@ bundle config --delete bin ./bin/rails app:update:bin # or rails app:update:bin ``` +##### Running Webpack on Windows + +If you are running Webpack on Windows, your command shell may not be able to interpret the preferred interpreter +for the scripts generated in `bin/webpack` and `bin/webpack-dev-server`. Instead you'll want to run the scripts +manually with Ruby: + +``` +C:\path>ruby bin\webpack +C:\path>ruby bin\webpack-dev-server +``` + ## Wishlist - HMR - [#188](https://github.com/rails/webpacker/issues/188) diff --git a/lib/install/bin/webpack-dev-server.bat.tt b/lib/install/bin/webpack-dev-server.bat.tt deleted file mode 100755 index c8ec8b2e2..000000000 --- a/lib/install/bin/webpack-dev-server.bat.tt +++ /dev/null @@ -1 +0,0 @@ -@ruby bin\webpack-dev-server %* diff --git a/lib/install/bin/webpack.bat.tt b/lib/install/bin/webpack.bat.tt deleted file mode 100755 index 857b3e080..000000000 --- a/lib/install/bin/webpack.bat.tt +++ /dev/null @@ -1 +0,0 @@ -@ruby bin\webpack %*