Skip to content

Commit

Permalink
Workarounds for Yarn not playing nicely on Windows (#584)
Browse files Browse the repository at this point in the history
* 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 #583

* Update Changelog and README for Webpacker on Windows

Do not generate batch files when installing
  • Loading branch information
soundasleep authored and gauravtiwari committed Jul 24, 2017
1 parent 2b0972a commit b55f002
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
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
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 b55f002

Please sign in to comment.