From 325a821ea7f6320d0197cd94d252343dbd5b90ad Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Thu, 27 Apr 2017 15:55:54 +0100 Subject: [PATCH 1/4] Remove webpack watcher --- README.md | 16 ++++------------ lib/install/bin/webpack-dev-server.tt | 2 +- lib/install/bin/webpack-watcher.tt | 10 ---------- lib/install/bin/webpack.tt | 7 ------- lib/install/config/webpack/configuration.js | 2 +- lib/install/template.rb | 1 - 6 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 lib/install/bin/webpack-watcher.tt diff --git a/README.md b/README.md index 9ce90b3f7..38ff06616 100644 --- a/README.md +++ b/README.md @@ -39,17 +39,14 @@ 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 either `./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 @@ -135,11 +132,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. @@ -240,7 +232,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 diff --git a/lib/install/bin/webpack-dev-server.tt b/lib/install/bin/webpack-dev-server.tt index b7cfbca6f..368cbb054 100644 --- a/lib/install/bin/webpack-dev-server.tt +++ b/lib/install/bin/webpack-dev-server.tt @@ -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 diff --git a/lib/install/bin/webpack-watcher.tt b/lib/install/bin/webpack-watcher.tt deleted file mode 100644 index fa83972f7..000000000 --- a/lib/install/bin/webpack-watcher.tt +++ /dev/null @@ -1,10 +0,0 @@ -<%= shebang %> - -ENV['RAILS_ENV'] ||= 'development' -ENV['NODE_ENV'] ||= ENV['RAILS_ENV'] - -BIN_PATH = File.expand_path('.', __dir__) - -Dir.chdir(BIN_PATH) do - exec "./webpack --watch --progress --color #{ARGV.join(" ")}" -end diff --git a/lib/install/bin/webpack.tt b/lib/install/bin/webpack.tt index 6b11c4aeb..5a8edaddf 100644 --- a/lib/install/bin/webpack.tt +++ b/lib/install/bin/webpack.tt @@ -12,19 +12,12 @@ 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 "Please run bundle exec rails webpacker:install to install webpacker" diff --git a/lib/install/config/webpack/configuration.js b/lib/install/config/webpack/configuration.js index 904af8229..c8f8461ab 100644 --- a/lib/install/config/webpack/configuration.js +++ b/lib/install/config/webpack/configuration.js @@ -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, diff --git a/lib/install/template.rb b/lib/install/template.rb index bc4925cc3..18e18ed26 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -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") From 16c07d7b97e47348c239d54c9f92a884d90615a9 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Thu, 27 Apr 2017 15:58:05 +0100 Subject: [PATCH 2/4] Update readme --- README.md | 1 - lib/install/bin/webpack.tt | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 38ff06616..b8481ab7f 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,6 @@ You can also see a list of available commands by running `./bin/rails webpacker` 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`. diff --git a/lib/install/bin/webpack.tt b/lib/install/bin/webpack.tt index 5a8edaddf..cc302b8af 100644 --- a/lib/install/bin/webpack.tt +++ b/lib/install/bin/webpack.tt @@ -19,7 +19,7 @@ begin NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"]) WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"]) 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 From e78f8449ef463a2ca5c050474e73ce9d1d0c60b1 Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Thu, 27 Apr 2017 16:11:55 +0100 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1136136f8..c95972da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. From b791b57429a6c8832249977a8ce3c1aaf0782cff Mon Sep 17 00:00:00 2001 From: Gaurav Tiwari Date: Thu, 27 Apr 2017 16:13:17 +0100 Subject: [PATCH 4/4] Remove either --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8481ab7f..3c21f10ff 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ They're thin wrappers around the standard webpack.js executable, just to ensure 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` 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/). +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