-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathwebpack.config.js
235 lines (222 loc) · 4.66 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const { BannerPlugin } = require('webpack');
const banner = require('./src/fragments/license');
const CopyPlugin = require('copy-webpack-plugin');
// This is needed for baseUrl to resolve correctly from tsconfig
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const baseConfig = {
mode: 'production',
entry: {
index: path.resolve(__dirname, 'src', 'common', 'lib', 'index.js'),
},
resolve: {
extensions: ['.js', '.ts'],
plugins: [new TsconfigPathsPlugin()],
},
output: {
path: path.resolve(__dirname, 'build'),
library: 'Ably',
libraryTarget: 'umd',
libraryExport: 'default',
},
module: {
rules: [
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.ts$/, loader: 'ts-loader' },
],
},
target: 'web',
externals: {
request: false,
ws: false,
},
plugins: [new BannerPlugin({ banner })],
performance: {
hints: false,
},
stats: {
modules: false,
},
};
function platformPath(platform, ...dir) {
return path.resolve(__dirname, 'src', 'platform', platform, ...dir);
}
const nodeConfig = {
...baseConfig,
entry: {
index: platformPath('nodejs'),
},
output: {
...baseConfig.output,
filename: 'ably-node.js',
},
target: 'node',
externals: {
got: true,
ws: true,
},
optimization: {
minimize: false,
},
};
const browserConfig = {
...baseConfig,
output: {
...baseConfig.output,
filename: 'ably.js',
},
entry: {
index: platformPath('web'),
},
node: {
crypto: 'empty',
Buffer: false,
},
externals: {
'crypto-js': true,
},
optimization: {
minimize: false,
},
};
const nativeScriptConfig = {
...baseConfig,
output: {
...baseConfig.output,
filename: 'ably-nativescript.js',
globalObject: 'global',
},
entry: {
index: platformPath('nativescript'),
},
node: {
crypto: 'empty',
Buffer: false,
},
externals: {
request: false,
ws: false,
'nativescript-websockets': true,
'@nativescript/core/application-settings': true,
},
optimization: {
minimize: false,
},
};
const reactNativeConfig = {
...baseConfig,
output: {
...baseConfig.output,
filename: 'ably-reactnative.js',
},
entry: {
index: platformPath('react-native'),
},
resolve: {
extensions: ['.js', '.ts'],
plugins: [new TsconfigPathsPlugin()],
},
node: {
crypto: 'empty',
Buffer: false,
},
externals: {
request: false,
ws: false,
'react-native': true,
},
optimization: {
minimize: false,
},
};
const browserMinConfig = {
...browserConfig,
output: {
...baseConfig.output,
filename: 'ably.min.js',
},
optimization: {
minimize: true,
},
performance: {
hints: 'warning',
},
devtool: 'source-map',
};
const webworkerConfig = {
target: 'webworker',
...browserConfig,
entry: {
index: platformPath('web', 'index-webworker.ts'),
},
output: {
...baseConfig.output,
filename: 'ably-webworker.min.js',
globalObject: 'this',
},
optimization: {
minimize: true,
},
performance: {
hints: 'warning',
},
plugins: [
new CopyPlugin({
patterns: [
{
from: path.resolve(__dirname, 'src', 'fragments', 'ably.d.ts'),
to: path.resolve(__dirname, 'build', 'ably-webworker.min.d.ts'),
},
],
}),
],
};
const noEncryptionConfig = {
...browserConfig,
entry: {
index: platformPath('web-noencryption'),
},
output: {
...baseConfig.output,
filename: 'ably.noencryption.js',
},
};
const noEncryptionMinConfig = {
...browserMinConfig,
entry: {
index: platformPath('web-noencryption'),
},
output: {
...baseConfig.output,
filename: 'ably.noencryption.min.js',
},
devtool: 'source-map',
};
// We are using UMD in ably.js now so there is no need to build separately for CommonJS. These files are still being distributed to avoid breaking changes but should no longer be used.
const commonJsConfig = {
...browserConfig,
output: {
...baseConfig.output,
filename: 'ably-commonjs.js',
},
};
const commonJsNoEncryptionConfig = {
...noEncryptionConfig,
output: {
...baseConfig.output,
filename: 'ably-commonjs.noencryption.js',
},
};
module.exports = {
node: nodeConfig,
browser: browserConfig,
browserMin: browserMinConfig,
webworker: webworkerConfig,
nativeScript: nativeScriptConfig,
reactNative: reactNativeConfig,
noEncryption: noEncryptionConfig,
noEncryptionMin: noEncryptionMinConfig,
commonJs: commonJsConfig,
commonJsNoEncryption: commonJsNoEncryptionConfig,
};