Skip to content

Instantly share code, notes, and snippets.

@jtallant
Created September 23, 2013 19:28
Show Gist options
  • Save jtallant/6675672 to your computer and use it in GitHub Desktop.
Save jtallant/6675672 to your computer and use it in GitHub Desktop.
Example Laravel Guardfile
# Given an array of files, they will be concatenated in order. Do no add the file extension, only the name.
# %w(bootstrap/bootstrap.min, profile, application)
guard :concat, type: "js", files: %w(bootstrap/bootstrap.min profile application), input_dir: "public/js", output: "public/js/scripts.min"
# Compass will read from the main config.rb file
guard :compass
# Refresh the browser on save
guard 'livereload' do
watch(%r{.+(?<!\.min)\.(css|html|js|blade\.php)$})
end
guard :phpunit, :all_on_start => false, :tests_path => 'app/tests/', :cli => '--colors -c phpunit.xml' do
# Run any test in app/tests upon save.
watch(%r{^.+Test\.php$})
# When a view file is updated, run tests.
# Tip: you probably only want to run your integration tests.
watch(%r{app/views/.+\.php}) { Dir.glob('app/tests/**/*.php') }
# When a file is edited, try to run its associated test.
# Save app/models/User.php, and it will run app/tests/models/UserTest.php
watch(%r{^app/(.+)/(.+)\.php$}) { |m| "app/tests/#{m[1]}/#{m[2]}Test.php"}
end
module ::Guard
class MyJsMin < Guard
end
end
require 'jsmin'
# Minify the scripts.min.js file when it changes
guard :myjsmin do
watch('public/js/scripts.min.js') do |m|
js = File.read(m[0])
File.open(m[0], 'w') { |file| file.write(JSMin.minify(js)) }
end
end
# This will minify the combined javascript file
# It has a looping problem when used with live reload so for now we will use the jsmin solution above
# guard 'uglify', :destination_file => "content/assets/js/script.min.js" do
# watch ('content/assets/js/script.min.js')
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment