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;
|
2021-02-09 18:35:13 -05:00
|
|
|
const sizeThreshold = minimize ? 100 * 1024 : 512 * 1024;
|
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');
|
2021-02-09 18:35:13 -05:00
|
|
|
const resolve = relativePath => path.resolve(__dirname, relativePath);
|
|
|
|
|
2020-03-09 18:07:34 -04:00
|
|
|
const alphaInfo = 'Experimental pre-release build.\n ';
|
|
|
|
const banner =
|
2021-02-09 18:35:13 -05:00
|
|
|
`${pkg.name} ${version} by @liabru
|
2020-11-24 18:45:18 -05:00
|
|
|
${alpha ? alphaInfo : ''}${pkg.homepage}
|
|
|
|
License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;
|
2019-09-14 13:36:22 -04:00
|
|
|
|
|
|
|
return {
|
2021-02-09 18:35:13 -05:00
|
|
|
entry: { 'matter': './src/module/main.js' },
|
|
|
|
node: false,
|
2019-09-14 13:36:22 -04:00
|
|
|
output: {
|
|
|
|
library: 'Matter',
|
|
|
|
libraryTarget: 'umd',
|
|
|
|
umdNamedDefine: true,
|
|
|
|
globalObject: 'this',
|
2021-02-09 18:35:13 -05:00
|
|
|
path: resolve('./build'),
|
2020-03-09 18:07:34 -04:00
|
|
|
filename: `[name]${alpha ? '.alpha' : ''}${minimize ? '.min' : ''}.js`
|
2019-09-14 13:36:22 -04:00
|
|
|
},
|
|
|
|
optimization: { minimize },
|
|
|
|
performance: {
|
2021-02-09 18:35:13 -05:00
|
|
|
maxEntrypointSize: sizeThreshold,
|
|
|
|
maxAssetSize: sizeThreshold
|
2019-09-14 13:36:22 -04:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.BannerPlugin(banner),
|
|
|
|
new webpack.DefinePlugin({
|
2021-02-09 18:35:13 -05:00
|
|
|
__MATTER_VERSION__: JSON.stringify(version),
|
2019-09-14 13:36:22 -04:00
|
|
|
})
|
|
|
|
],
|
2021-02-09 18:35:13 -05:00
|
|
|
externals: {
|
|
|
|
'poly-decomp': {
|
|
|
|
commonjs: 'poly-decomp',
|
|
|
|
commonjs2: 'poly-decomp',
|
|
|
|
amd: 'poly-decomp',
|
|
|
|
root: 'decomp'
|
|
|
|
},
|
|
|
|
'matter-wrap': {
|
|
|
|
commonjs: 'matter-wrap',
|
|
|
|
commonjs2: 'matter-wrap',
|
|
|
|
amd: 'matter-wrap',
|
|
|
|
root: 'MatterWrap'
|
2019-09-14 13:36:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|