Search code examples
opalrb

How shall I migrate to opal 0.7.0.beta


I tried to upgrade to use Opal 0.7.0.beta. I want to compile to a static app and follow the steps in http://opalrb.org/docs/static_applications/

My Rakefile looks like the one below. The questions:

  1. How do I need to rework the :build task to get rid of the deprecation message. i tried. to use Opal::Server instead of Opal::Environment but it did not work.

  2. I get `Opal already loaded. Loading twice can cause troubles, please fix your setup.``

  3. I get undefined is not a function in the generated javascript Opal.mark_as_loaded(Opal.normalize_loadable_path("corelib/runtime"));

Thanks for Opal and thanks for any advice.

# Rakefile
require 'opal'
require 'opal/sprockets/environment'
require 'opal-jquery'
require 'erb'
require 'zip'


ZUPFNOTER_JS = "../deploy_files/build.js"


desc "Build our app to #{ZUPFNOTER_JS}"
task :build do
  env = Opal::Environment.new
  env.append_path "."
  env.use_gem "vector2d"

  File.open(ZUPFNOTER_JS, "w+") do |out|
    out << env["application"].to_s
  end

  Dir.glob "../public/*.scss" do |f|
    cmd = "sass #{f} > #{File.dirname(f)}/#{File.basename(f, ".scss")}.css"
    puts sh cmd
  end
end

...


Solution

  • Something like the following should work:

    require 'opal'
    task :build do
      env = Sprockets::Environment.new
      Opal.append_path '.'
      Opal.use_gem 'vector2d'
      Opal.paths.each { |p| env.append_path(p) }
    
      File.open(ZUPFNOTER_JS, 'w+') { |out| out << env['application.js'].to_s }
    
      # …
    end
    

    I also suggest to use the same sprockets environment to build SCSS too as it should work out of the box (maybe a require "sass" is needed too).