-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
webpack.config.dev.js
63 lines (62 loc) · 2.12 KB
/
webpack.config.dev.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
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: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: `weapp.socket.io.dev.${isWechat ? 'wx' : 'my'}.js`,
libraryTarget: 'umd',
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
wx: isWechat ? 'wx' : 'my',
my: isAlipay ? 'my' : 'wx',
}),
new webpack.NormalModuleReplacementPlugin(/debug/g, process.cwd() + '/support/debug.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'",
}]
}
}, {
test: /src\/wx-ws.js$/,
loader: 'string-replace-loader',
options: {
multiple: [{
search: "PLATFORM_VAR",
replace: "my",
}]
}
}]
}
}
}