Skip to content

Commit

Permalink
Add :dist rake task for building and minifying builds
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 19, 2013
1 parent 13aee8b commit 59394a0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Rakefile
Expand Up @@ -4,3 +4,43 @@ Bundler::GemHelper.install_tasks

require 'opal/spec/rake_task'
Opal::Spec::RakeTask.new(:default)

desc "Build build/opal-jquery.js"
task :dist do
require 'fileutils'
FileUtils.mkdir_p 'build'

src = Opal::Builder.build('opal-jquery')
min = uglify src
gzp = gzip min

File.open('build/opal-jquery.js', 'w+') do |out|
out << src
end

puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
end

# Used for uglifying source to minify
def uglify(str)
IO.popen('uglifyjs', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
rescue Errno::ENOENT
$stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
nil
end

# Gzip code to check file size
def gzip(str)
IO.popen('gzip -f', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
rescue Errno::ENOENT
$stderr.puts '"gzip" command not found, it is required to produce the .gz version'
nil
end

0 comments on commit 59394a0

Please sign in to comment.