modular-js icon indicating copy to clipboard operation
modular-js copied to clipboard

@:jsRequire support

Open dpeek opened this issue 9 years ago • 3 comments

Right now the generator doesn't seem to recognise externs with @:jsRequire as dependencies. That would be really useful and allow mixing with node_module code through browserify or webpack.

dpeek avatar Oct 12 '15 21:10 dpeek

Yes, I have plans for this. Stay tuned.

explorigin avatar Oct 19 '15 01:10 explorigin

I see that @:jsRequire support appears to be here?

One question -- what if I want to require the whole Pixi.js library? Is there a syntax for that? If I put a @:jsRequire on, for example, the Pixi Matrix class:

@:native("PIXI.Matrix") @:jsRequire("PIXI.Matrix")
extern class Matrix {

It ends up generating a define header like this:

define(["PIXI.Matrix", "../../extend_stub"],
       function (PIXI_Matrix, extend_stub) {
  var m = new PIXI_Matrix();

But pixi is a single, bundled .js file, so what I really what is this:

define(["PIXI", "../../extend_stub"],
       function (PIXI, extend_stub) {
  var m = new PIXI.Matrix();

Is this possible with the current @:jsRequire schema?

jcward avatar Jan 20 '17 20:01 jcward

FYI, over on my fork I've implemented this feature -- I call it require namespaces.

This allows me to require a large project, like Pixi.JS, and reference the classes therein.

e.g. the Pixi.js Matrix extern is defined like so:

@:native("PIXI.Matrix")
extern class Matrix {

The JS generator, when run with -D RequireNamespaces=PIXI, will see that PIXI prefix, and add a dependency on 'PIXI', while locally referencing the variable as PIXI.Matrix. e.g.

define(['PIXI'], function(PIXI) {

...
  var m = new PIXI.Matrix();

});

jcward avatar Jan 31 '17 17:01 jcward