-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwebpack.split.config.js
128 lines (124 loc) · 3.48 KB
/
webpack.split.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"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 Case = require('case');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = (env = {}) => {
const minimize = env.MINIMIZE || false;
const alpha = env.ALPHA || false;
const maxSize = 350 * 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: {
Inspector: './src/tools/Inspector',
Demo: './src/tools/Demo',
Gui: './src/tools/Gui',
Serializer: './src/tools/Serializer'
},
output: {
library: ['MatterTools', '[name]'],
publicPath: '/demo/lib/',
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: 'this',
path: path.resolve(__dirname, './build'),
filename: params => `${name}.${Case.camel(params.chunk.name)}${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'
}
},
externals: {
'matter-js': {
commonjs: 'matter-js',
commonjs2: 'matter-js',
amd: 'matter-js',
root: 'Matter'
},
'matter-tools': {
commonjs: 'matter-tools',
commonjs2: 'matter-tools',
amd: 'matter-tools',
root: 'MatterTools'
},
'Demo': {
commonjs: 'matter-tools/src/tools/Demo',
commonjs2: 'matter-tools/src/tools/Demo',
amd: 'matter-tools/src/tools/Demo',
root: ['MatterTools', 'Demo']
},
'Gui': {
commonjs: 'matter-tools/src/tools/Gui',
commonjs2: 'matter-tools/src/tools/Gui',
amd: 'matter-tools/src/tools/Gui',
root: ['MatterTools', 'Gui']
},
'Inspector': {
commonjs: 'matter-tools/src/tools/Inspector',
commonjs2: 'matter-tools/src/tools/Inspector',
amd: 'matter-tools/src/tools/Inspector',
root: ['MatterTools', 'Inspector']
},
'Serializer': {
commonjs: 'matter-tools/src/tools/Serializer',
commonjs2: 'matter-tools/src/tools/Serializer',
amd: 'matter-tools/src/tools/Serializer',
root: ['MatterTools', 'Serializer']
}
}
};
};