Created
August 27, 2010 19:15
-
-
Save paulredmond/553987 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'Sprockets' | |
require 'Jsmin' | |
MINFILE = 'app/webroot/js/build-min.js' | |
CONCATFILE = 'app/webroot/js/concat.js' | |
secretary = Sprockets::Secretary.new( | |
:asset_root => 'app/webroot', | |
:load_path => ['app/webroot/js', 'plugins/*/vendors/js/**', 'app/plugins/*/vendors/js/**'], | |
:source_files => ['app/webroot/js/*.js', 'plugins/*/vendors/js/**/*.js', 'app/plugins/*/vendors/js/**/*.js'], | |
:strip_comments => true | |
) | |
# generate the concatenation object | |
concatenation = secretary.concatenation | |
# write to disk | |
gluedFiles = concatenation.to_s | |
concatenation.save_to(CONCATFILE) | |
# Run through JSMin | |
File.open(MINFILE, 'w') { |file| file.write(JSMin.minify(gluedFiles)) } |
Plugin paths to js files was updated in CakePHP 1.3. This example is for CakePHP 1.2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is tailored for a CakePHP project, but easily adaptable.
Load all javascript files from the webroot and plugins into one application file--minified and non-minified versions. Could get rather beefy if the project has lots of js. A better approach would be hand-rolled js files that include dependencies as needed that can make up an application javascript file. This script would be easy to adapt to move files to CDN.