The compiler supports special [JSModule] metadata for Node so that it emits
the correct require() calls. It might be possible to make use of this for
projects that target Node and other contexts. The compiler will probably
need some tweaks, though.

Here's an example:

package {
  [JSModule]
  public class fs {
  }
}

It will use the class name as the module name by default, or you can
specify the module name explicitly:

package fs {
  [JSModule(name="fs")]
  public class FSWatcher extends events.EventEmitter {
  }
}

The compiler will emit a require() call in the following style any time
that a class with [JSModule] metadata is used:

var fs = require("fs");

Currently, it will always emit the require() call, even if you aren't
building a Node project. The compiler could probably be tweaked so that
emitting require() calls works for Node only and gets skipped in other
contexts.

- Josh

On Sun, Feb 12, 2017 at 3:17 PM, Harbs <harbs.li...@gmail.com> wrote:

> I just added a CompressionUtils class which uses ByteArray on the Flash
> side and pako on the javascript side.
>
> It uses inject_html to link to the js because I don’t know of a better way
> to currently do this.
>
> I don’t like this approach for a number of reasons:
> 1. It hardwires the link into the generated HTML. In this case it’s using
> the “best” cdn, but it does not allow the content to be hosted on the app
> server.
> 2. There’s no (easy) way to link to relative paths when an app is being
> loaded locally. Requiring it be downloaded from the internet is
> inefficient, and does not allow the app to be run when there’s no internet
> connection.
> 3. This will not work for Node.js. Node.js needs require(‘pako’) instead
> of linking to the script.
>
> Here’s what I’m thinking: I’d like to have a “Require” tag which would
> cause FlaconJX to do the right thing depending on the compilation. If it’s
> compiling for Node.js, it would require() the dependency. If it’s compiling
> for the browser, it would link to a relative path if that path exists
> (there would be some standardized way of linking) or to a url if not
> (assuming a url is provided).
>
> I don’t really care what the require tag looks like, but I personally like
> metadata over the comment approach. It could also be a function call which
> the compiler recognizes as a “special” one which gets optimized out.
>
> So something like this:
>
> [Require(name=“pako", url="https://cdnjs.cloudflare.
> com/ajax/libs/pako/1.0.3/pako.min.js”)]
>
> or:
> /**
> * @require pako, https://cdnjs.cloudflare.com/
> ajax/libs/pako/1.0.3/pako.min.js <https://cdnjs.cloudflare.com/
> ajax/libs/pako/1.0.3/pako.min.js>
> */
> or:
> require(‘pako’,'https://cdnjs.cloudflare.com/ajax/libs/pako/
> 1.0.3/pako.min.js' <https://cdnjs.cloudflare.com/
> ajax/libs/pako/1.0.3/pako.min.js'>);
> where the signature for require would be:
> require(name:String,url:String=“”)
>
> Thoughts?
> Harbs

Reply via email to