0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-27 13:59:01 -05:00

fixed require for external libraries, closes #629, closes #559, closes #593, closes #365, closes #629

This commit is contained in:
liabru 2018-06-11 19:05:09 +01:00
parent 511de5b494
commit 0cf97f5c3c
4 changed files with 25 additions and 8 deletions

View file

@ -111,13 +111,16 @@ gulp.task('watch', function() {
var b = browserify({
entries: ['src/module/main.js'],
standalone: 'Matter',
plugin: [watchify],
transform: ['browserify-shim']
plugin: [watchify]
});
var bundle = function() {
gutil.log('Updated bundle build/matter-dev.js');
b.bundle()
.on('error', function(err) {
gutil.log('ERROR', err.message);
this.emit('end');
})
.pipe(through2({ objectMode: true }, function(chunk, encoding, callback) {
return callback(
null,

View file

@ -21,7 +21,6 @@
],
"devDependencies": {
"browserify": "^14.0.0",
"browserify-shim": "^3.8.13",
"cheerio": "^0.22.0",
"connect-livereload": "^0.6.0",
"event-stream": "^3.3.2",
@ -59,8 +58,5 @@
"src",
"build",
"CHANGELOG.md"
],
"browserify-shim": {
"poly-decomp": "global:decomp"
}
]
}

View file

@ -536,4 +536,18 @@ module.exports = Common;
));
};
/**
* Used to require external libraries outside of the bundle.
* It first looks for the `globalName` on the environment's global namespace.
* If the global is not found, it will fall back to using the standard `require` using the `moduleName`.
* @private
* @method _requireGlobal
* @param {string} globalName The global module name
* @param {string} moduleName The fallback CommonJS module name
* @return {} The loaded module
*/
Common._requireGlobal = function(globalName, moduleName) {
var obj = (typeof window !== 'undefined' ? window[globalName] : typeof global !== 'undefined' ? global[globalName] : null);
return obj || require(moduleName);
};
})();

View file

@ -18,7 +18,7 @@ var Common = require('../core/Common');
var Body = require('../body/Body');
var Bounds = require('../geometry/Bounds');
var Vector = require('../geometry/Vector');
var decomp = require('poly-decomp');
var decomp;
(function() {
@ -197,6 +197,10 @@ var decomp = require('poly-decomp');
* @return {body}
*/
Bodies.fromVertices = function(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea) {
if (!decomp) {
decomp = Common._requireGlobal('decomp', 'poly-decomp');
}
var body,
parts,
isConvex,