-
Notifications
You must be signed in to change notification settings - Fork 56
/
webpack.config.js
145 lines (138 loc) · 3.72 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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const { BannerPlugin, ProvidePlugin } = require('webpack');
const banner = require('./src/fragments/license');
// 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', 'es2017'],
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 nativeScriptConfig = {
...baseConfig,
output: {
...baseConfig.output,
filename: 'ably-nativescript.js',
globalObject: 'global',
},
entry: {
index: platformPath('nativescript'),
},
resolve: {
...baseConfig.resolve,
fallback: {
crypto: 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',
globalObject: 'global',
},
entry: {
index: platformPath('react-native'),
},
resolve: {
extensions: ['.js', '.ts'],
plugins: [new TsconfigPathsPlugin()],
fallback: {
crypto: false,
},
},
externals: {
request: false,
ws: false,
'react-native': true,
fastestsmallesttextencoderdecoder: 'fastestsmallesttextencoderdecoder',
},
optimization: {
minimize: false,
},
};
/**
* We create a bundle that exposes the mocha-junit-reporter package to be able to use it in the browser. We need to do this for the following reasons:
* - This package is designed for Node only and hence requires polyfills of Node libraries (e.g. `stream`, `path`) — webpack takes care of this for us.
* - The package is not compatible with RequireJS and hence we don’t have any easy way to directly load it in our tests — the webpack bundle exposes it as a global named MochaJUnitReporter.
*/
function createMochaJUnitReporterConfig() {
const dir = path.join(__dirname, 'test', 'support', 'mocha_junit_reporter');
return {
mode: 'development',
entry: path.join(dir, 'index.js'),
externals: {
mocha: 'mocha.Mocha',
},
output: {
path: path.join(dir, 'build'),
filename: 'browser.js',
library: 'MochaJUnitReporter',
},
plugins: [
new ProvidePlugin({
process: 'process/browser.js',
}),
],
resolve: {
fallback: {
// These are the modules suggested by webpack, post v5-upgrade, to replace v4’s built-in shims.
path: require.resolve('path-browserify'),
stream: require.resolve('stream-browserify'),
},
modules: [
// Webpack doesn’t suggest any useful shim for the `fs` module, so we provide our own.
path.resolve(dir, 'shims'),
'node_modules',
],
},
};
}
module.exports = {
nativeScript: nativeScriptConfig,
reactNative: reactNativeConfig,
mochaJUnitReporterBrowser: createMochaJUnitReporterConfig(),
};