Skip to content

Instantly share code, notes, and snippets.

@felinebabies
Created January 19, 2016 14:31
Show Gist options
  • Select an option

  • Save felinebabies/e1938d7a24e4620f8b46 to your computer and use it in GitHub Desktop.

Select an option

Save felinebabies/e1938d7a24e4620f8b46 to your computer and use it in GitHub Desktop.
Opalでrubyスクリプトをjavascriptにコンパイルする
require 'rake/clean'
SRCDIR = './src'
DESTDIR = './dest'
SRCS = FileList[SRCDIR + "/**/*.rb"]
JSS = SRCS.ext('js')
directory DESTDIR
# 出力先パスに書き換え
JSS.gsub!(SRCDIR, DESTDIR)
puts JSS
CLEAN.include(JSS)
CLOBBER.include('opal_js')
task :default => [DESTDIR, 'opal_js']
desc 'Opalでrubyスクリプトをjavascriptにコンパイルする'
file 'opal_js' => JSS
# ディレクトリの変更を含む場合、正規表現によるルール指定が必要
# http://qiita.com/takkkun/items/c588c96b9ecf38021312
rule %r{^\./dest/.+\.js} => '%{^\./dest,./src}X.rb' do |t|
sh "bundle exec opal --compile #{t.source.gsub(DESTDIR, SRCDIR)} > #{t.name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment