-
-
Notifications
You must be signed in to change notification settings - Fork 632
/
assets.rake
59 lines (53 loc) · 2.2 KB
/
assets.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require "react_on_rails/assets_precompile"
if defined?(Sprockets)
namespace :react_on_rails do
namespace :assets do
desc "Creates non-digested symlinks for the assets in the public asset dir"
task symlink_non_digested_assets: :"assets:environment" do
ReactOnRails::AssetsPrecompile.new.symlink_non_digested_assets
end
desc "Cleans all broken symlinks for the assets in the public asset dir"
task delete_broken_symlinks: :"assets:environment" do
ReactOnRails::AssetsPrecompile.new.delete_broken_symlinks
end
# In this task, set prerequisites for the assets:precompile task
desc <<-DESC
Create webpack assets before calling assets:environment
The webpack task must run before assets:environment task.
Otherwise Sprockets cannot find the files that webpack produces.
This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
DESC
task compile_environment: :webpack do
Rake::Task["assets:environment"].invoke
end
desc "Delete assets created with webpack, in the generated assetst directory (/app/assets/webpack)"
task clobber: :environment do
ReactOnRails::AssetsPrecompile.new.clobber
end
end
end
# These tasks run as pre-requisites of assets:precompile.
# Note, it's not possible to refer to ReactOnRails configuration values at this point.
Rake::Task["assets:precompile"]
.clear_prerequisites
.enhance([:environment, "react_on_rails:assets:compile_environment"])
.enhance do
Rake::Task["react_on_rails:assets:symlink_non_digested_assets"].invoke
Rake::Task["react_on_rails:assets:delete_broken_symlinks"].invoke
end
end
# Sprockets independent tasks
namespace :react_on_rails do
namespace :assets do
desc <<-DESC
Compile assets with webpack
Uses command defined with ReactOnRails.configuration.npm_build_production_command
sh "cd client && `ReactOnRails.configuration.npm_build_production_command`"
DESC
task webpack: :locale do
if ReactOnRails.configuration.npm_build_production_command.present?
sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}"
end
end
end
end