Skip to content

Commit 3cdc406

Browse files
committed
refactor(react_ujs) build UJS with webpack
1 parent 6ea7524 commit 3cdc406

25 files changed

+2772
-283
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ test/dummy/tmp
55
gemfiles/*.lock
66
*.swp
77
/vendor/react
8-
react-builds/node_modules
8+
**/node_modules
99
react-builds/build
1010
coverage/

Rakefile

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ def copy_react_asset(webpack_file, destination_file)
1212
FileUtils.cp(full_webpack_path, full_destination_path)
1313
end
1414

15+
# Move to `dirname` and execute `yarn {cmd}`
16+
def yarn_run_in(dirname, cmd)
17+
Dir.chdir(dirname) do
18+
`yarn #{cmd}`
19+
end
20+
end
21+
1522
namespace :react do
1623
desc "Run the JS build process to put files in the gem source"
1724
task update: [:install, :build, :copy]
1825

1926
desc "Build the JS bundles with Webpack"
2027
task :build do
21-
Dir.chdir("react-builds") do
22-
`yarn run build`
23-
end
28+
yarn_run_in("react-builds", "build")
2429
end
2530

2631
desc "Copy browser-ready JS files to the gem's asset paths"
@@ -39,9 +44,30 @@ namespace :react do
3944

4045
desc "Install the JavaScript dependencies"
4146
task :install do
42-
Dir.chdir("react-builds") do
43-
`yarn install`
44-
end
47+
yarn_run_in("react-builds", "install")
48+
end
49+
end
50+
51+
namespace :ujs do
52+
desc "Run the JS build process to put files in the gem source"
53+
task update: [:install, :build, :copy]
54+
55+
desc "Install the JavaScript dependencies"
56+
task :install do
57+
yarn_run_in("react_ujs", "install")
58+
end
59+
60+
61+
desc "Build the JS bundles with Webpack"
62+
task :build do
63+
yarn_run_in("react_ujs", "build")
64+
end
65+
66+
desc "Copy browser-ready JS files to the gem's asset paths"
67+
task :copy do
68+
full_webpack_path = File.expand_path("../react_ujs/dist/react_ujs.js", __FILE__)
69+
full_destination_path = File.expand_path("../lib/assets/javascripts/react_ujs.js", __FILE__)
70+
FileUtils.cp(full_webpack_path, full_destination_path)
4571
end
4672
end
4773

0 commit comments

Comments
 (0)