Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sprockets precompile rake task #190

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions templates/project/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# First need to import Dashing with the Smashing Sinatra App
require 'dashing'
# Then import Sinatra, which will prepare sprockets settings
require 'sinatra'
# Now match the imports from Smashing's app.rb so that the resources are pre-processed
require 'coffee-script'
require 'sass' if RUBY_VERSION < "2.5.0"
require 'sassc' if RUBY_VERSION >= "2.5.0"
# Logger and misc
require 'pathname'
require 'logger'

# From: https://simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/
ROOT = Pathname(File.dirname(__FILE__))
LOGGER = Logger.new(STDOUT)
BUNDLES = %w( application.js )
BUILD_DIR = ROOT.join("assets/javascripts/")

# This contains the settings from the Smashign Sinatra App (see app.rb)
# so no need to append_path, etc.
sprockets = Sinatra::Application.settings.sprockets
sprockets.logger = LOGGER

# Task: precompile-assets
# Pre-compiles sprockets application.js so users don't need to wait for Sinatra/Sprockets
# to generate it on the fly.
# see: https://github.com/Smashing/smashing/issues/189
task :'precompile-assets' do
BUNDLES.each do |bundle|
asset = sprockets.find_asset(bundle)
asset.write_to(BUILD_DIR.join(asset.logical_path))
end
end