Skip to content

Commit 024cdbf

Browse files
committed
feat(JS) add webpack build process
1 parent 22ffe30 commit 024cdbf

23 files changed

+165187
-41304
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ test/dummy/tmp
55
gemfiles/*.lock
66
*.swp
77
/vendor/react
8+
react-builds/node_modules
9+
react-builds/build

Rakefile

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,35 @@ end
66

77
Bundler::GemHelper.install_tasks
88

9-
require 'pathname'
9+
def copy_react_asset(webpack_file, destination_file)
10+
full_webpack_path = File.expand_path("../react-builds/build/#{webpack_file}", __FILE__)
11+
full_destination_path = File.expand_path("../lib/assets/react-source/#{destination_file}", __FILE__)
12+
FileUtils.cp(full_webpack_path, full_destination_path)
13+
end
14+
1015
namespace :react do
11-
task :update do
12-
FileUtils.rm_f('vendor/react/.bower.json')
13-
`bower install react`
14-
assets_path = Pathname.new(File.dirname(__FILE__)).join('lib/assets/')
15-
copy_react_asset('JSXTransformer.js', assets_path.join('javascripts/JSXTransformer.js'))
16-
copy_react_asset('react.js', assets_path.join('react-source/development/react.js'))
17-
copy_react_asset('react.min.js', assets_path.join('react-source/production/react.js'))
18-
copy_react_asset('react-with-addons.js', assets_path.join('react-source/development-with-addons/react.js'))
19-
copy_react_asset('react-with-addons.min.js', assets_path.join('react-source/production-with-addons/react.js'))
16+
desc "Run the JS build process to put files in the gem source"
17+
task update: [:build, :copy]
18+
19+
desc "Build the JS bundles with Webpack"
20+
task :build do
21+
Dir.chdir("react-builds") do
22+
`webpack`
23+
`NODE_ENV=production webpack`
24+
end
2025
end
2126

22-
def copy_react_asset(source, destination)
23-
vendor_path = Pathname.new(File.dirname(__FILE__)).join('vendor/react')
24-
FileUtils.mkdir_p(destination.dirname.to_s)
25-
FileUtils.cp(vendor_path.join(source), destination.to_s)
27+
desc "Copy browser-ready JS files to the gem's asset paths"
28+
task :copy do
29+
environments = ["development", "production"]
30+
environments.each do |environment|
31+
# Without addons:
32+
copy_react_asset("#{environment}/react-browser.js", "#{environment}/react.js")
33+
copy_react_asset("#{environment}/react-server.js", "#{environment}/react-server.js")
34+
# With addons:
35+
copy_react_asset("#{environment}/react-browser-with-addons.js", "#{environment}-with-addons/react.js")
36+
copy_react_asset("#{environment}/react-server-with-addons.js", "#{environment}-with-addons/react-server.js")
37+
end
2638
end
2739
end
2840

0 commit comments

Comments
 (0)