Class: Opal::Connect::RakeTask
- Inherits:
-
Object
- Object
- Opal::Connect::RakeTask
- Includes:
- Rake::DSL
- Defined in:
- lib/opal/connect/rake_task.rb
Constant Summary collapse
- STUBS =
%w'opal native promise console base64 json'
Instance Method Summary collapse
-
#initialize(name = 'webpack', opts = {}) ⇒ RakeTask
constructor
A new instance of RakeTask.
- #write_opal_file ⇒ Object
Constructor Details
#initialize(name = 'webpack', opts = {}) ⇒ RakeTask
Returns a new instance of RakeTask.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/opal/connect/rake_task.rb', line 7 def initialize(name = 'webpack', opts = {}) namespace name do return unless defined? Opal.append_path Opal::Connect.write_entry_file Opal.append_path Dir.pwd write_opal_file envs = ENV.to_h.merge({ BUNDLE_BIN: true, CONNECT_STUBS: STUBS.concat(Opal::Config.stubbed_files.to_a).join(','), OPAL_LOAD_PATH: Opal.paths.join(":"), OPAL_USE_BUNDLER: true }).inject({}) { |env, (k, v)| env[k.to_s] = v.to_s; env } desc "Start webpack" task :run do exec(envs, 'webpack --progress --watch') end desc "Build webpack" task :build do exec(envs, 'webpack --progress') end end end |
Instance Method Details
#write_opal_file ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/opal/connect/rake_task.rb', line 36 def write_opal_file file_path = "#{Dir.pwd}/.connect" version_path = "#{file_path}/opal_version" version = File.exist?(version_path) ? File.read(version_path) : false if !File.exist?("#{file_path}/opal.js") || !version || (version && version != Opal::VERSION) builder = Opal::Builder.new build_str = STUBS.map { |stub| "require '#{stub}'" }.join(";") builder.build_str(build_str, '(inline)', { dynamic_require_severity: :ignore }) File.write version_path, Opal::VERSION File.write "#{file_path}/opal.js", builder.to_s end end |