Skip to content

Commit 59394a0

Browse files
committed
Add :dist rake task for building and minifying builds
1 parent 13aee8b commit 59394a0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Rakefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,43 @@ Bundler::GemHelper.install_tasks
44

55
require 'opal/spec/rake_task'
66
Opal::Spec::RakeTask.new(:default)
7+
8+
desc "Build build/opal-jquery.js"
9+
task :dist do
10+
require 'fileutils'
11+
FileUtils.mkdir_p 'build'
12+
13+
src = Opal::Builder.build('opal-jquery')
14+
min = uglify src
15+
gzp = gzip min
16+
17+
File.open('build/opal-jquery.js', 'w+') do |out|
18+
out << src
19+
end
20+
21+
puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
22+
end
23+
24+
# Used for uglifying source to minify
25+
def uglify(str)
26+
IO.popen('uglifyjs', 'r+') do |i|
27+
i.puts str
28+
i.close_write
29+
return i.read
30+
end
31+
rescue Errno::ENOENT
32+
$stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
33+
nil
34+
end
35+
36+
# Gzip code to check file size
37+
def gzip(str)
38+
IO.popen('gzip -f', 'r+') do |i|
39+
i.puts str
40+
i.close_write
41+
return i.read
42+
end
43+
rescue Errno::ENOENT
44+
$stderr.puts '"gzip" command not found, it is required to produce the .gz version'
45+
nil
46+
end

0 commit comments

Comments
 (0)