From 1382a05b5d0e7b35fbd6f9ddf27f32fd8f54dca2 Mon Sep 17 00:00:00 2001 From: fc_arny Date: Sat, 7 Jan 2017 00:09:11 +0300 Subject: [PATCH] Ability to work without sprockets --- CHANGELOG.md | 3 +- lib/tasks/assets.rake | 68 +++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be4832f7c..9a1bcd373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ All notable changes to this project's source code will be documented in this fil Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version. ## [Unreleased] -*Please add entries here for your pull requests.* +### Changed +- Add ability use gem without sprockets. [#671](https://github.com/shakacode/react_on_rails/pull/671) by [fc-arny](https://github.com/fc-arny) ## [6.3.5] - 2016-1-6 ### Fixed diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index ea83248fb..c1a255134 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,28 +1,50 @@ require "react_on_rails/assets_precompile" -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 +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 + 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 + # 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 + 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 @@ -33,21 +55,5 @@ sh "cd client && `ReactOnRails.configuration.npm_build_production_command`" sh "cd client && #{ReactOnRails.configuration.npm_build_production_command}" end 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 -