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

Nix watcher #295

Merged
merged 4 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ app/javascript/packs/hello.vue
- Add initial test case by @kimquy [#259](https://github.com/rails/webpacker/pull/259)


### Removed
- Webpack watcher - [#295](https://github.com/rails/webpacker/pull/295)

## [1.1] - 2017-03-24

This release requires you to run below commands to install new features.
Expand Down
17 changes: 4 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ You can also see a list of available commands by running `./bin/rails webpacker`

## Binstubs

Webpacker ships with three binstubs: `./bin/webpack`, `./bin/webpack-watcher` and `./bin/webpack-dev-server`.
They're thin wrappers around the standard webpack.js executable, just to ensure that the right configuration
file is loaded.

Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
They're thin wrappers around the standard webpack.js executable, just to ensure that the right configuration file is loaded depending on your environment.

A binstub is also created to install your npm dependencies,
and can be called via `./bin/yarn`.

In development, you'll need to run either `./bin/webpack-dev-server` or `./bin/webpack-watcher` in a separate terminal from `./bin/rails server` to have your `app/javascript/packs/*.js` files compiled as you make changes. If you'd rather not have to run the two processes separately by hand, you can use [Foreman](https://ddollar.github.io/foreman). `./bin/webpack-dev-server` launches the [Webpack Dev Server](https://webpack.js.org/configuration/dev-server/), which serves your pack files on http://localhost:8080/, and provides advanced Webpack features, such as [Hot Module Replacement](https://webpack.js.org/guides/hmr-react/).

If you would rather forego the advanced features and serve your javascript packs directly from the rails server, you may use `./bin/webpack-watcher` instead, but make sure to disable the Dev Server in `config/webpack/development.server.yml`, otherwise script tags will keep pointing to `localhost:8080` and won't load properly.
In development, you'll need to run `./bin/webpack-dev-server` in a separate terminal from `./bin/rails server` to have your `app/javascript/packs/*.js` files compiled as you make changes. If you'd rather not have to run the two processes separately by hand, you can use [Foreman](https://ddollar.github.io/foreman). `./bin/webpack-dev-server` launches the [Webpack Dev Server](https://webpack.js.org/configuration/dev-server/), which serves your pack files on http://localhost:8080/, and provides advanced Webpack features, such as [Hot Module Replacement](https://webpack.js.org/guides/hmr-react/).

## Configuration

Expand Down Expand Up @@ -135,11 +131,6 @@ port: 8080
By default, `webpack-dev-server` uses `output` option specified in
`paths.yml` as `contentBase`.

**Note:** Don't forget to disable `webpack-dev-server` in case you are using
`./bin/webpack-watcher` to serve assets in development mode otherwise
you will get 404 for assets because the helper tag will use webpack-dev-server url
to serve assets instead of public directory.

## Linking to static assets

Static assets like images, fonts and stylesheets support is enabled out-of-box so, you can link them into your javascript app code and have them compiled automatically.
Expand Down Expand Up @@ -240,7 +231,7 @@ Webpacker uses a `manifest.json` file to keep track of packs in all environments
however since this file is generated after packs are compiled by webpack. So,
if you load a view in browser whilst webpack is compiling you will get this error.
Therefore, make sure webpack
(i.e `./bin/webpack-watcher` or `./bin/webpack-dev-server`) is running and has
(i.e `./bin/webpack-dev-server`) is running and has
completed the compilation successfully before loading a view.

## Wishlist
Expand Down
2 changes: 1 addition & 1 deletion lib/install/bin/webpack-dev-server.tt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ end

Dir.chdir(APP_PATH) do
exec "NODE_PATH=#{NODE_MODULES_PATH} #{WEBPACK_BIN} --progress --color " \
"--config #{DEV_SERVER_CONFIG}"
"--config #{DEV_SERVER_CONFIG} #{ARGV.join(" ")}"
end
10 changes: 0 additions & 10 deletions lib/install/bin/webpack-watcher.tt

This file was deleted.

9 changes: 1 addition & 8 deletions lib/install/bin/webpack.tt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,14 @@ NODE_ENV = ENV["NODE_ENV"]

APP_PATH = File.expand_path("../", __dir__)
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
DEV_SERVER_CONFIG_PATH = File.join(APP_PATH, "config/webpack/development.server.yml")

begin
paths = YAML.load(File.read(CONFIG_PATH))[NODE_ENV]
dev_server = YAML.load(File.read(DEV_SERVER_CONFIG_PATH))[NODE_ENV]

NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])

if NODE_ENV == "development" && dev_server["enabled"]
puts "Warning: webpack-dev-server is currently enabled in #{DEV_SERVER_CONFIG_PATH}. " \
"Disable to serve assets directly from public/packs directory"
end
rescue Errno::ENOENT, NoMethodError
puts "Configuration not found in config/webpack/paths.yml or config/webpack/development.server.yml."
puts "Configuration not found in config/webpack/paths.yml"
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/install/config/webpack/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const devServer = safeLoad(readFileSync(join(configPath, 'development.server.yml
const ifHasCDN = env.ASSET_HOST !== undefined && env.NODE_ENV === 'production'
const devServerUrl = `http://${devServer.host}:${devServer.port}/${paths.entry}/`
const publicUrl = ifHasCDN ? `${env.ASSET_HOST}/${paths.entry}/` : `/${paths.entry}/`
const publicPath = env.NODE_ENV !== 'production' && devServer.enabled ? devServerUrl : publicUrl
const publicPath = env.NODE_ENV !== 'production' ? devServerUrl : publicUrl

module.exports = {
devServer,
Expand Down
1 change: 0 additions & 1 deletion lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

puts "Copying binstubs"
template "#{__dir__}/bin/webpack-dev-server", "bin/webpack-dev-server"
template "#{__dir__}/bin/webpack-watcher", "bin/webpack-watcher"
template "#{__dir__}/bin/webpack", "bin/webpack"

if !File.exist?("bin/yarn")
Expand Down