0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00
liabru-matter-js/webpack.config.js

99 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-09-28 10:15:54 -04:00
/* eslint-env es6 */
2019-09-14 13:36:22 -04:00
"use strict";
const webpack = require('webpack');
const path = require('path');
const pkg = require('./package.json');
2020-11-24 18:45:18 -05:00
const fs = require('fs');
2019-09-14 13:36:22 -04:00
const execSync = require('child_process').execSync;
module.exports = (env = {}) => {
const minimize = env.MINIMIZE || false;
2020-03-09 18:07:34 -04:00
const alpha = env.ALPHA || false;
2019-09-14 13:36:22 -04:00
const maxSize = minimize ? 100 * 1024 : 512 * 1024;
2019-09-28 09:53:10 -04:00
const isDevServer = process.env.WEBPACK_DEV_SERVER;
2019-09-14 13:36:22 -04:00
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
2020-03-09 18:07:34 -04:00
const version = !alpha ? pkg.version : `${pkg.version}-alpha+${commitHash}`;
2020-11-24 18:45:18 -05:00
const license = fs.readFileSync('LICENSE', 'utf8');
2019-09-14 13:36:22 -04:00
const date = new Date().toISOString().slice(0, 10);
const name = 'matter';
2020-03-09 18:07:34 -04:00
const alphaInfo = 'Experimental pre-release build.\n ';
const banner =
2020-11-24 18:45:18 -05:00
`${pkg.name} ${version} by @liabru ${date}
${alpha ? alphaInfo : ''}${pkg.homepage}
License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;
2019-09-14 13:36:22 -04:00
const entry = isDevServer ? './demo/js/Server.js' : './src/module/main.js';
2019-09-14 13:36:22 -04:00
return {
entry: { [name]: entry },
2019-09-14 13:36:22 -04:00
output: {
library: 'Matter',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this',
path: path.resolve(__dirname, './build'),
2020-03-09 18:07:34 -04:00
filename: `[name]${alpha ? '.alpha' : ''}${minimize ? '.min' : ''}.js`
2019-09-14 13:36:22 -04:00
},
node: false,
optimization: { minimize },
performance: {
maxEntrypointSize: maxSize,
maxAssetSize: maxSize
},
plugins: [
new webpack.BannerPlugin(banner),
new webpack.DefinePlugin({
2019-09-28 09:53:10 -04:00
__MATTER_VERSION__: JSON.stringify(!isDevServer ? version : '*'),
2019-09-14 13:36:22 -04:00
})
],
externals: {
'poly-decomp': {
commonjs: 'poly-decomp',
commonjs2: 'poly-decomp',
amd: 'poly-decomp',
root: 'decomp'
}
},
devServer: {
contentBase: [
path.resolve(__dirname, './demo'),
2019-09-30 18:28:17 -04:00
path.resolve(__dirname, './examples'),
2021-01-12 18:17:38 -05:00
path.resolve(__dirname, './node_modules/matter-tools/build'),
path.resolve(__dirname, './node_modules/pathseg')
],
2019-09-14 13:36:22 -04:00
open: true,
openPage: '',
2019-09-14 13:36:22 -04:00
compress: true,
port: 8000,
proxy: {
'/build': {
target: 'http://localhost:8000/',
pathRewrite: { '^/build' : '/' }
},
'/examples': {
target: 'http://localhost:8000/',
pathRewrite: { '^/examples' : '/' }
2021-01-12 18:04:12 -05:00
},
'/lib/matter-tools.demo.js': {
target: 'http://localhost:8000/',
pathRewrite: { '^/lib/matter-tools.demo.js' : '/matter-tools.demo.js' }
},
'/lib/matter-tools.inspector.js': {
target: 'http://localhost:8000/',
2021-01-12 18:17:38 -05:00
pathRewrite: { '^/lib/matter-tools.inspector.js' : '/matter-tools.inspector.js' }
2021-01-12 18:04:12 -05:00
},
'/lib/matter-tools.gui.js': {
target: 'http://localhost:8000/',
2021-01-12 18:17:38 -05:00
pathRewrite: { '^/lib/matter-tools.gui.js' : '/matter-tools.gui.js' }
},
'/lib/pathseg.js': {
target: 'http://localhost:8000/',
pathRewrite: { '^/lib/pathseg.js' : '/pathseg.js' }
2019-09-14 13:36:22 -04:00
}
}
}
};
};