Created
September 14, 2015 15:49
-
-
Save nekath/c48af8316d1d02ed5549 to your computer and use it in GitHub Desktop.
Rake task for rails and webpack assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The webpack must compile assets before assets:environment task. | |
# Otherwise Sprockets sees no changes and don't precompile assets. | |
Rake::Task['assets:precompile'] | |
.clear_prerequisites | |
.enhance(['assets:compile_environment']) | |
Rake::Task['assets:clobber'].enhance do | |
Rake::Task['assets:clobber_webpack'].invoke | |
end | |
namespace :assets do | |
#In this task, set prerequisites for the assets:precompile task | |
task :compile_environment => :webpack do | |
Rake::Task['assets:environment'].invoke | |
end | |
desc 'Compile assets with webpack' | |
task :webpack do | |
sh "NODE_ENV=#{Rails.env} npm run build" | |
end | |
desc 'Remove compiled assets by webpack' | |
task :clobber_webpack do | |
rm_rf "#{Rails.application.config.root}/app/assets/javascripts/react_bundle.js" | |
rm_rf "#{Rails.application.config.root}/app/assets/stylesheets/react_bundle.css" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment