-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwebpack.config.js
114 lines (110 loc) · 3.04 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"use strict";
const webpack = require('webpack');
const path = require('path');
const pkg = require('./package.json');
const fs = require('fs');
const execSync = require('child_process').execSync;
const TerserPlugin = require('terser-webpack-plugin');
module.exports = (env = {}) => {
const isDevServer = Boolean(process.env.WEBPACK_DEV_SERVER);
const minimize = env.MINIMIZE || isDevServer || false;
const alpha = env.ALPHA || false;
const maxSize = 450 * 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');
const name = pkg.name;
const alphaInfo = 'Experimental pre-release build.\n ';
const banner =
`${pkg.name} ${version} by @liabru
${alpha ? alphaInfo : ''}${pkg.homepage}
License ${pkg.license}${!minimize ? '\n\n' + license : ''}`;
return {
entry: { [name]: './src/index' },
output: {
library: 'MatterTools',
publicPath: '/demo/lib/',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this',
path: path.resolve(__dirname, './build'),
filename: `${name}${alpha ? '.alpha' : ''}${minimize ? '.min' : ''}.js`
},
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: 'raw-loader',
options: {
esModule: false,
},
},
],
}
]
},
node: false,
optimization: {
minimize,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
output: {
comments: /license|copyright|\(c\)/ig,
},
}
})
]
},
performance: {
maxEntrypointSize: maxSize,
maxAssetSize: maxSize
},
plugins: [
new webpack.BannerPlugin(banner),
new webpack.DefinePlugin({
'%NAME%': name,
'%VERSION%': version
})
],
resolve: {
alias: {
'jquery': 'jquery/dist/jquery.min',
'jstree': 'jstree/dist/jstree.min',
'dat.gui': 'dat.gui/build/dat.gui.min',
'Demo': path.resolve(__dirname, 'src/tools/Demo'),
'Gui': path.resolve(__dirname, 'src/tools/Gui'),
'Inspector': path.resolve(__dirname, 'src/tools/Inspector'),
'Serializer': path.resolve(__dirname, 'src/tools/Serializer')
}
},
externals: {
'matter-js': {
commonjs: 'matter-js',
commonjs2: 'matter-js',
amd: 'matter-js',
root: 'Matter'
}
},
devServer: {
watchContentBase: true,
hot: false,
compress: true,
overlay: true,
port: 8080,
contentBase: [
path.resolve(__dirname, './docs'),
path.resolve(__dirname, './node_modules/matter-js/build')
],
proxy: {
'/demo/lib/matter.min.js': {
target: 'http://localhost:8080/',
pathRewrite: { '^/demo/lib/' : '/' }
}
}
}
};
};