diff --git a/Gulpfile.js b/Gulpfile.js index 3464897..e790aea 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -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, diff --git a/package.json b/package.json index 58644b2..7ceeb48 100644 --- a/package.json +++ b/package.json @@ -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" - } + ] } diff --git a/src/core/Common.js b/src/core/Common.js index db530c3..28e29be 100644 --- a/src/core/Common.js +++ b/src/core/Common.js @@ -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); + }; })(); diff --git a/src/factory/Bodies.js b/src/factory/Bodies.js index d384722..d1edd68 100644 --- a/src/factory/Bodies.js +++ b/src/factory/Bodies.js @@ -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,