-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathwebpack.config.js
More file actions
68 lines (61 loc) · 1.66 KB
/
webpack.config.js
File metadata and controls
68 lines (61 loc) · 1.66 KB
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
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const Visualizer = require('webpack-visualizer-plugin');
const merge = require('webpack-merge');
const baseConfig = {
entry: {
index: path.resolve(__dirname, 'src/index'),
},
output: {
path: path.resolve(__dirname, 'lib'),
libraryTarget: 'commonjs2',
},
plugins: [
new UglifyJSPlugin({
sourceMap: false,
}),
],
};
// 只打包socket.io-client
const commonJsConfig = merge(baseConfig, {
output: {
filename: 'index.js',
},
externals: [
(context, request, callback) => {
if (/^socket\.io-client$/.test(request)) {
return callback();
}
if (/^engine\.io-client/.test(request)) {
return callback(null, `commonjs ${request.replace(/^engine\.io-client/, 'engine.io-mp-client')}`);
}
if (/^[^/\\]*$/.test(request)) {
return callback(null, `commonjs ${request}`);
}
callback();
},
],
plugins: [
new Visualizer({
filename: './statistics/commonJs.html',
}),
],
});
// 单文件打包配置
const singleConfig = merge(baseConfig, {
output: {
filename: 'socket.io-mp.js',
},
resolve: {
alias: {
debug: path.resolve(path.join(__dirname, 'node_modules', 'debug')),
'engine.io-client': 'engine.io-mp-client',
},
},
plugins: [
new Visualizer({
filename: './statistics/single.html',
}),
],
});
module.exports = [commonJsConfig, singleConfig];