Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading with a module loader.
Babylon.js currently uses namespaces and its types can be pulled in using /// <reference path="babylonjs/babylon.d.ts" /> It's generated JavaScript can be loaded using either a script tag, or using a module loader from JavaScript. However, what was not yet supported is loading types and implementation using a module loader from Typescript, because babylon.d.ts was not a module. This adds support for that, following the example here: https://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#support-for-umd-module-definitions
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var gutil = require('gulp-util'); | ||
var through = require('through2'); | ||
|
||
module.exports = function (varName) { | ||
return through.obj(function (file, enc, cb) { | ||
|
||
var moduleExportsAddition = | ||
'\nexport as namespace ' + varName + ';\n' + | ||
'\nexport = ' + varName + ';\n'; | ||
|
||
if (file.isNull()) { | ||
cb(null, file); | ||
return; | ||
} | ||
|
||
if (file.isStream()) { | ||
//streams not supported, no need for now. | ||
return; | ||
} | ||
|
||
try { | ||
file.contents = new Buffer(String(file.contents) + moduleExportsAddition); | ||
this.push(file); | ||
|
||
} catch (err) { | ||
this.emit('error', new gutil.PluginError('gulp-add-module-exports', err, { fileName: file.path })); | ||
} | ||
cb(); | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b921855
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rehmsen we've just found an issue with your hack :(
If you go to loaders folders and try to compile them, you'll see that what you added breaks the compilation:
https://github.com/BabylonJS/Babylon.js/tree/master/loaders
b921855
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm reverting it for now
b921855
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.