0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00
liabru-matter-js/webpack.examples.config.js

55 lines
1.7 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');
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;
const alpha = env.ALPHA || false;
2019-09-14 13:36:22 -04:00
const maxSize = minimize ? 100 * 1024 : 512 * 1024;
const commitHash = execSync('git rev-parse --short HEAD').toString().trim();
const version = !alpha ? pkg.version : `${pkg.version}-alpha+${commitHash}`;
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-js-examples';
const alphaInfo = 'Experimental pre-release build.\n ';
const banner =
`${name} ${version} by @liabru ${date}
${alpha ? alphaInfo : ''}${pkg.homepage}
License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;
2019-09-14 13:36:22 -04:00
return {
entry: './examples/index.js',
output: {
library: 'Example',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this',
path: path.resolve(__dirname, './demo/js'),
filename: `Examples${minimize ? '.min' : ''}.js`
},
node: false,
optimization: { minimize },
performance: {
maxEntrypointSize: maxSize,
maxAssetSize: maxSize
},
plugins: [
new webpack.BannerPlugin(banner)
],
externals: {
'matter-js': {
commonjs: 'matter-js',
commonjs2: 'matter-js',
amd: 'matter-js',
root: 'Matter'
}
}
};
};