Skip to content

Commit

Permalink
Updates for Rails 5.2 / Webpacker 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
swrobel committed Jan 26, 2018
1 parent e154bf5 commit c1a902b
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 82 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
.env*
!invoker.ini

# Ignore master key for decrypting credentials and more.
/config/master.key

# Webpacker
/public/packs
/public/packs-test
/node_modules

# Ignore master key for decrypting credentials and more.
/config/master.key
yarn-debug.log*
yarn-error.log*
.yarn-integrity
2 changes: 1 addition & 1 deletion bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
2 changes: 1 addition & 1 deletion bin/rails
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ begin
rescue LoadError => e
raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
8 changes: 5 additions & 3 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
Expand All @@ -16,7 +15,10 @@ chdir APP_ROOT do

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') or system!('bundle install')
system('bundle check') || system!('bundle install')

# Install JavaScript dependencies if using Yarn
# system('bin/yarn')

# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
Expand Down
6 changes: 4 additions & 2 deletions bin/update
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
APP_ROOT = File.expand_path('..', __dir__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
Expand All @@ -18,6 +17,9 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

# Install JavaScript dependencies if using Yarn
# system('bin/yarn')

puts "\n== Updating database =="
system! 'bin/rails db:migrate'

Expand Down
37 changes: 15 additions & 22 deletions bin/webpack
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
#!/usr/bin/env ruby
$stdout.sync = true
# frozen_string_literal: true

require "shellwords"
require "yaml"
#
# This file was generated by Bundler.
#
# The application 'webpack' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]
bundle_binstub = File.expand_path("../bundle", __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

APP_PATH = File.expand_path("../", __dir__)
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
require "rubygems"
require "bundler/setup"

unless File.exist?(WEBPACK_CONFIG)
puts "Webpack configuration not found."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
end
load Gem.bin_path("webpacker", "webpack")
52 changes: 15 additions & 37 deletions bin/webpack-dev-server
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
#!/usr/bin/env ruby
$stdout.sync = true
# frozen_string_literal: true

require "shellwords"
require "yaml"
#
# This file was generated by Bundler.
#
# The application 'webpack-dev-server' is installed as part of a gem, and
# this file is here to facilitate running it.
#

ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]
bundle_binstub = File.expand_path("../bundle", __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

APP_PATH = File.expand_path("../", __dir__)
CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml")
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/development.js")
require "rubygems"
require "bundler/setup"

def args(key)
index = ARGV.index(key)
index ? ARGV[index + 1] : nil
end

begin
dev_server = YAML.load_file(CONFIG_FILE)["development"]["dev_server"]

DEV_SERVER_HOST = "http#{"s" if args('--https') || dev_server["https"]}://#{args('--host') || dev_server["host"]}:#{args('--port') || dev_server["port"]}"

rescue Errno::ENOENT, NoMethodError
puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

newenv = {
"NODE_PATH" => NODE_MODULES_PATH.shellescape,
"ASSET_HOST" => DEV_SERVER_HOST.shellescape
}.freeze

cmdline = ["yarn", "run", "webpack-dev-server", "--progress", "--color", "--config", WEBPACK_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
end
load Gem.bin_path("webpacker", "webpack-dev-server")
6 changes: 3 additions & 3 deletions bin/yarn
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
exec "yarnpkg #{ARGV.join(' ')}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.webpacker.check_yarn_integrity = true

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.webpacker.check_yarn_integrity = false

# Code is not reloaded between requests.
config.cache_classes = true
Expand Down
11 changes: 7 additions & 4 deletions config/webpacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ default: &default
cache_manifest: false

extensions:
- .coffee
- .erb
- .js
- .jsx
- .ts
- .vue
- .sass
- .scss
- .css
Expand All @@ -43,8 +39,15 @@ development:
# Inline should be set to true if using HMR
inline: true
overlay: true
compress: true
disable_host_check: true
use_local_ip: false
quiet: false
headers:
'Access-Control-Allow-Origin': '*'
watch_options:
ignored: /node_modules/


test:
<<: *default
Expand Down
3 changes: 3 additions & 0 deletions invoker.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[surf]
command = RUBY_DEBUG_PORT=4444 bin/rails s -p $PORT -b 127.0.0.1

[surf-packs]
command = bin/webpack-dev-server

[guard]
command = bin/guard -i

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"@rails/webpacker": "^3.0.2",
"@rails/webpacker": "^3.2.1",
"babel-preset-react": "^6.24.1",
"headroom.js": "^0.9.4",
"prop-types": "^15.6.0",
Expand All @@ -11,6 +11,6 @@
},
"devDependencies": {
"browser-sync": "^2.18.12",
"webpack-dev-server": "^2.9.3"
"webpack-dev-server": "^2.11.1"
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# yarn lockfile v1


"@rails/webpacker@^3.0.2":
"@rails/webpacker@^3.2.1":
version "3.2.1"
resolved "https://registry.yarnpkg.com/@rails/webpacker/-/webpacker-3.2.1.tgz#da7331106b93b2818c3595627c88c5c037fff3c8"
dependencies:
Expand Down Expand Up @@ -6438,7 +6438,7 @@ [email protected]:
range-parser "^1.0.3"
time-stamp "^2.0.0"

webpack-dev-server@^2.9.3:
webpack-dev-server@^2.11.1:
version "2.11.1"
resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-2.11.1.tgz#6f9358a002db8403f016e336816f4485384e5ec0"
dependencies:
Expand Down

0 comments on commit c1a902b

Please sign in to comment.