These are chat archives for opal/opal

24th
Feb 2017
Bernhard Weichel
@bwl21
Feb 24 2017 08:21

@eilia I tried your proposal. rackup works. It stops woking if I append "." to the path. I do not know why.

# zupfnoter-server.rb
SERVER= Opal::Server.new { |s|

  Opal.use_gem "vector2d"
  Opal::Config.source_map_enabled = true

  Opal.paths.each { |p| s.append_path(p) }

  s.append_path 'public'
  s.append_path 'src'
  s.append_path 'vendor'
# s.append_path "."   uncommenting this line, it does not work


  s.source_map = true

  s.main = 'application'

  s.index_path = 'index_opal.html.erb'
}

  # config.ru
  require 'bundler'
  Bundler.require

  require_relative './zupfnoter-server'
  run SERVER

But the static build does not work: (Rakefile:)

require_relative '../zupfnoter-server'
  File.open(ZUPFNOTER_JS, "w+") do |out|
    env = SERVER.sprockets
    out.puts env['application'].to_s
  end

If I compare the output, I can see the following difference at the very end of the generated Javascript file

generated by env['application'].to_s - does not work:

/* Generated by Opal 0.9.0 */
Opal.modules["application"] = function(Opal) {
  Opal.dynamic_require_severity = "error";
  var OPAL_CONFIG = { method_missing: true, arity_check: false, freezing: true, tainting: true };
  var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

  Opal.add_stubs(['$require', '$puts']);
  self.$require("opal");
  self.$require("opal-jquery");
 ...
  self.$require("snippet_editor");
  self.$puts("now starting zupfnoter");
  return self.$puts("zupfnoter is now running");
};

Generated by out.puts(Opal::Builder::build("application").to_s) - this works

/* Generated by Opal 0.9.0 */
(function(Opal) {
  Opal.dynamic_require_severity = "error";
  var OPAL_CONFIG = { method_missing: true, arity_check: false, freezing: true, tainting: true };
  var self = Opal.top, $scope = Opal, nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;

  Opal.add_stubs(['$require', '$puts']);
  self.$require("opal");
  self.$require("opal-jquery");
  ... 

  self.$require("snippet_editor");
  self.$puts("now starting zupfnoter");
  return self.$puts("zupfnoter is now running");
})(Opal);
Elia Schito
@elia
Feb 24 2017 09:36
@bwl21 you're right, as of now for buiding with sprockets you have to change this line: out.puts env['application'].to_s + "\nOpal.load('application');\n"
Elia Schito
@elia
Feb 24 2017 09:46
the additional makes opal do the initial load of the app
Bernhard Weichel
@bwl21
Feb 24 2017 11:50
@elia yes! this works. I somehow remember that we had that before ...
So there are basically two ways to do a static build (http://opalrb.org/docs/guides/v0.10.3/static_applications.html)
Do you have an Idea, why adding '.' to the path prevents the server from working?
Elia Schito
@elia
Feb 24 2017 12:09
@bwl21 not yet, need to try it locally to catch the problem
Bernhard Weichel
@bwl21
Feb 24 2017 12:31
ok i will investigate if there are conflicting files