Skip to content

Commit 351e075

Browse files
committed
Add sprockets precompile rake task
1 parent 5c4d421 commit 351e075

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

templates/project/Rakefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# First need to import Dashing with the Smashing Sinatra App
2+
require 'dashing'
3+
# Then import Sinatra, which will prepare sprockets settings
4+
require 'sinatra'
5+
# Now match the imports from Smashing's app.rb so that the resources are pre-processed
6+
require 'coffee-script'
7+
require 'sass' if RUBY_VERSION < "2.5.0"
8+
require 'sassc' if RUBY_VERSION >= "2.5.0"
9+
# Logger and misc
10+
require 'pathname'
11+
require 'logger'
12+
13+
# From: https://simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/
14+
ROOT = Pathname(File.dirname(__FILE__))
15+
LOGGER = Logger.new(STDOUT)
16+
BUNDLES = %w( application.js )
17+
BUILD_DIR = ROOT.join("assets/javascripts/")
18+
19+
# This contains the settings from the Smashign Sinatra App (see app.rb)
20+
# so no need to append_path, etc.
21+
sprockets = Sinatra::Application.settings.sprockets
22+
sprockets.logger = LOGGER
23+
24+
# Task: precompile-assets
25+
# Pre-compiles sprockets application.js so users don't need to wait for Sinatra/Sprockets
26+
# to generate it on the fly.
27+
# see: https://github.com/Smashing/smashing/issues/189
28+
task :'precompile-assets' do
29+
BUNDLES.each do |bundle|
30+
asset = sprockets.find_asset(bundle)
31+
asset.write_to(BUILD_DIR.join(asset.logical_path))
32+
end
33+
end

0 commit comments

Comments
 (0)