mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-30 14:29:04 -05:00
fixed require for external libraries, closes #629, closes #559, closes #593, closes #365, closes #629
This commit is contained in:
parent
511de5b494
commit
0cf97f5c3c
4 changed files with 25 additions and 8 deletions
|
@ -111,13 +111,16 @@ gulp.task('watch', function() {
|
||||||
var b = browserify({
|
var b = browserify({
|
||||||
entries: ['src/module/main.js'],
|
entries: ['src/module/main.js'],
|
||||||
standalone: 'Matter',
|
standalone: 'Matter',
|
||||||
plugin: [watchify],
|
plugin: [watchify]
|
||||||
transform: ['browserify-shim']
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var bundle = function() {
|
var bundle = function() {
|
||||||
gutil.log('Updated bundle build/matter-dev.js');
|
gutil.log('Updated bundle build/matter-dev.js');
|
||||||
b.bundle()
|
b.bundle()
|
||||||
|
.on('error', function(err) {
|
||||||
|
gutil.log('ERROR', err.message);
|
||||||
|
this.emit('end');
|
||||||
|
})
|
||||||
.pipe(through2({ objectMode: true }, function(chunk, encoding, callback) {
|
.pipe(through2({ objectMode: true }, function(chunk, encoding, callback) {
|
||||||
return callback(
|
return callback(
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^14.0.0",
|
"browserify": "^14.0.0",
|
||||||
"browserify-shim": "^3.8.13",
|
|
||||||
"cheerio": "^0.22.0",
|
"cheerio": "^0.22.0",
|
||||||
"connect-livereload": "^0.6.0",
|
"connect-livereload": "^0.6.0",
|
||||||
"event-stream": "^3.3.2",
|
"event-stream": "^3.3.2",
|
||||||
|
@ -59,8 +58,5 @@
|
||||||
"src",
|
"src",
|
||||||
"build",
|
"build",
|
||||||
"CHANGELOG.md"
|
"CHANGELOG.md"
|
||||||
],
|
]
|
||||||
"browserify-shim": {
|
|
||||||
"poly-decomp": "global:decomp"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -18,7 +18,7 @@ var Common = require('../core/Common');
|
||||||
var Body = require('../body/Body');
|
var Body = require('../body/Body');
|
||||||
var Bounds = require('../geometry/Bounds');
|
var Bounds = require('../geometry/Bounds');
|
||||||
var Vector = require('../geometry/Vector');
|
var Vector = require('../geometry/Vector');
|
||||||
var decomp = require('poly-decomp');
|
var decomp;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
@ -197,6 +197,10 @@ var decomp = require('poly-decomp');
|
||||||
* @return {body}
|
* @return {body}
|
||||||
*/
|
*/
|
||||||
Bodies.fromVertices = function(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea) {
|
Bodies.fromVertices = function(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea) {
|
||||||
|
if (!decomp) {
|
||||||
|
decomp = Common._requireGlobal('decomp', 'poly-decomp');
|
||||||
|
}
|
||||||
|
|
||||||
var body,
|
var body,
|
||||||
parts,
|
parts,
|
||||||
isConvex,
|
isConvex,
|
||||||
|
|
Loading…
Reference in a new issue