Skip to content

refactor(UJS) make it webpack-friendly #678

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

Merged
merged 9 commits into from
Apr 4, 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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Gemfile.lock
*.log
test/dummy/tmp
test/dummy/public/packs
gemfiles/*.lock
*.swp
/vendor/react
react-builds/node_modules
**/node_modules
react-builds/build
coverage/
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: ruby
sudo: required
dist: trusty
cache: bundler
cache:
bundler: true
yarn: true
rvm:
- 2.3.0
- 2.1
Expand Down Expand Up @@ -60,3 +62,8 @@ before_install:
- tar -xvf $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis-phantomjs
- export PATH=$PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH
- phantomjs --version
# Repo for Yarn
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- sudo apt-get update -qq
- sudo apt-get install -y -qq yarn
2 changes: 2 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ appraise "rails-4.2-sprockets_4" do
gem 'rails', '~> 4.2.1'
gem "sprockets", "~> 4.0.x"
gem "turbolinks", "~> 2.5.0"
gem "webpacker", github: "rails/webpacker"
end

appraise "rails-5" do
gem 'rails', '~> 5.0.0'
gem "turbolinks", "~> 5.0.0"
gem "webpacker", github: "rails/webpacker"
end

appraise "rails-5-no_sprockets" do
Expand Down
51 changes: 46 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ def copy_react_asset(webpack_file, destination_file)
FileUtils.cp(full_webpack_path, full_destination_path)
end

# Move to `dirname` and execute `yarn {cmd}`
def yarn_run_in(dirname, cmd)
Dir.chdir(dirname) do
`yarn #{cmd}`
end
end

namespace :react do
desc "Run the JS build process to put files in the gem source"
task update: [:install, :build, :copy]

desc "Build the JS bundles with Webpack"
task :build do
Dir.chdir("react-builds") do
`yarn run build`
end
yarn_run_in("react-builds", "build")
end

desc "Copy browser-ready JS files to the gem's asset paths"
Expand All @@ -39,8 +44,36 @@ namespace :react do

desc "Install the JavaScript dependencies"
task :install do
Dir.chdir("react-builds") do
`yarn upgrade`
yarn_run_in("react-builds", "upgrade")
end
end

namespace :ujs do
desc "Run the JS build process to put files in the gem source"
task update: [:install, :build, :copy]

desc "Install the JavaScript dependencies"
task :install do
yarn_run_in("react_ujs", "upgrade")
end


desc "Build the JS bundles with Webpack"
task :build do
yarn_run_in("react_ujs", "build")
end

desc "Copy browser-ready JS files to the gem's asset paths"
task :copy do
full_webpack_path = File.expand_path("../react_ujs/dist/react_ujs.js", __FILE__)
full_destination_path = File.expand_path("../lib/assets/javascripts/react_ujs.js", __FILE__)
FileUtils.cp(full_webpack_path, full_destination_path)
end

desc "Publish the package in ./react_ujs/ to npm as `react_ujs`"
task :publish do
Dir.chdir("react_ujs") do
`npm publish`
end
end
end
Expand All @@ -57,3 +90,11 @@ Rake::TestTask.new(:test) do |t|
end

task default: :test

task :test_setup do
Dir.chdir("./test/dummy") do
`yarn install`
end
end

task test: :test_setup
1 change: 1 addition & 0 deletions gemfiles/rails_4.2_sprockets_4.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ source "http://rubygems.org"
gem "rails", "~> 4.2.1"
gem "sprockets", "~> 4.0.x"
gem "turbolinks", "~> 2.5.0"
gem "webpacker", :github => "rails/webpacker"

gemspec :path => "../"
1 change: 1 addition & 0 deletions gemfiles/rails_5.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ source "http://rubygems.org"

gem "rails", "~> 5.0.0"
gem "turbolinks", "~> 5.0.0"
gem "webpacker", :github => "rails/webpacker"

gemspec :path => "../"
Loading