-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
webpack.config.js
54 lines (52 loc) · 1.88 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
const webpack = require('webpack');
const path = require('path');
module.exports = (env = {}) => {
const target = env.target || 'Wechat';
const isWechat = target !== 'Alipay';
const isAlipay = !isWechat;
return {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'lib'),
filename: `weapp.socket.io.${isWechat ? 'wx' : 'my'}.js`,
libraryTarget: 'umd',
},
plugins: [
new webpack.DefinePlugin({
wx: isWechat ? 'wx' : 'my',
my: isAlipay ? 'my' : 'wx',
}),
new webpack.NormalModuleReplacementPlugin(/debug/, process.cwd() + '/support/noop.js'),
new webpack.NormalModuleReplacementPlugin(/^ws$/g, process.cwd() + '/src/wx-ws.js'),
new webpack.NormalModuleReplacementPlugin(/^.\/websocket-constructor$/g, process.cwd() + '/src/websocket-constructor.js'),
new webpack.NormalModuleReplacementPlugin(/^.\/transports\/index$/g, process.cwd() + '/src/transport.js'),
new webpack.NormalModuleReplacementPlugin(/^.\/util$/g, process.cwd() + '/src/util.js'),
new webpack.NormalModuleReplacementPlugin(/^.\/engine.io-client\/lib\/util$/g, process.cwd() + '/src/util.js'),
],
module: {
rules: [{
test: /engine.io-client\/lib\/socket.js$/,
loader: 'string-replace-loader',
options: {
multiple: [{
search: '["polling", "websocket"]',
replace: '["websocket"]',
}, {
search: "['polling', 'websocket']",
replace: "['websocket']",
}]
}
}, {
test: /engine.io-client\/lib\/transports\/websocket.js$/,
loader: 'string-replace-loader',
options: {
multiple: [{
search: "typeof window === 'undefined'",
replace: "typeof window === 'undefined' || typeof window !== 'undefined'",
}]
}
}]
}
}
};