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. diff --git a/README.md b/README.md index 9ce90b3f7..3c21f10ff 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. @@ -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 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..cc302b8af 100644 --- a/lib/install/bin/webpack.tt +++ b/lib/install/bin/webpack.tt @@ -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 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")