Skip to content

Commit

Permalink
fix poly-decomp external require
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 16, 2021
1 parent 5551cd5 commit 882e07c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 49 deletions.
74 changes: 41 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"json-stringify-pretty-compact": "^2.0.0",
"matter-tools": "^0.12.3",
"pathseg": "^1.2.0",
"poly-decomp": "^0.3.0",
"puppeteer-core": "^5.5.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.11",
Expand All @@ -38,6 +39,7 @@
"build-alpha": "webpack --mode=production --env.ALPHA & webpack --mode=production --env.MINIMIZE --env.ALPHA",
"build-examples": "webpack --config webpack.examples.config.js --mode=production & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE",
"build-examples-alpha": "webpack --config webpack.examples.config.js --mode=production --env.ALPHA & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE --env.ALPHA",
"build-demo": "mkdir -p demo/lib && cp node_modules/matter-tools/build/matter-tools.demo.js demo/lib & cp node_modules/matter-tools/build/matter-tools.gui.js demo/lib & cp node_modules/matter-tools/build/matter-tools.inspector.js demo/lib & cp node_modules/pathseg/pathseg.js demo/lib & cp node_modules/poly-decomp/build/decomp.js demo/lib",
"lint": "eslint 'src/**/*.js' 'demo/js/Demo.js' 'demo/js/Compare.js' 'examples/*.js' 'webpack.*.js'",
"doc": "yuidoc --config yuidoc.json --project-version $npm_package_version",
"test": "npm run test-node",
Expand Down
9 changes: 1 addition & 8 deletions src/factory/Bodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ var Vector = require('../geometry/Vector');
* @return {body}
*/
Bodies.fromVertices = function(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea, removeDuplicatePoints) {
var globals = typeof global !== 'undefined' ? global : window,
decomp,
var decomp = require('poly-decomp'),
body,
parts,
isConvex,
Expand All @@ -209,12 +208,6 @@ var Vector = require('../geometry/Vector');
v,
z;

try {
decomp = globals.decomp || require('poly-decomp');
} catch (e) {
// decomp is undefined
}

options = options || {};
parts = [];

Expand Down
18 changes: 10 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;

const entry = isDevServer ? './demo/js/Server.js' : './src/module/main.js';

const externals = isDevServer ? undefined : {
'poly-decomp': {
commonjs: 'poly-decomp',
commonjs2: 'poly-decomp',
amd: 'poly-decomp',
root: 'decomp'
}
};

return {
entry: { [name]: entry },
output: {
Expand All @@ -48,14 +57,7 @@ License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;
__MATTER_VERSION__: JSON.stringify(!isDevServer ? version : '*'),
})
],
externals: {
'poly-decomp': {
commonjs: 'poly-decomp',
commonjs2: 'poly-decomp',
amd: 'poly-decomp',
root: 'decomp'
}
},
externals,
devServer: {
contentBase: [
path.resolve(__dirname, './demo'),
Expand Down

0 comments on commit 882e07c

Please sign in to comment.