require "bundler/gem_tasks" require 'opal' Opal.append_path 'lib/opal' def compile(filename, source) compiler = Opal::Compiler.new(source, file: File.basename(filename, '.rb')) compiler.compile File.binwrite(File.basename(filename, '.rb') + '.js', compiler.result.to_s << "//# sourceMappingURL=#{File.basename(filename, '.rb')}.js.map\n" << "//# sourceURL=#{File.basename(filename)}\n" ) File.binwrite(File.basename(filename, '.rb') + '.js.map', compiler.source_map.as_json.to_json.to_s ) end task :dist do builder = Opal::Builder.new builder.build 'react' File.binwrite "dist/opal-react.js", builder.to_s << "\n//# sourceMappingURL=opal-react.js.map\n" File.binwrite "dist/opal-react.js.map", builder.source_map.to_s end