This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
forked from aaani/WebSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
131 lines (125 loc) · 5.96 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
/**
* Copyright 2023 Phenix Real Time Solutions, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* global __dirname module */
const path = require('path');
const del = require('del');
const {merge} = require('webpack-merge');
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const {DuplicatesPlugin} = require('inspectpack/plugin');
const assert = require('phenix-web-assert/dist/phenix-web-assert.min');
const assertNames = '^' + Object.keys(assert.__proto__).join('$|^') + '$';
const uglifyManglePropRegex = new RegExp('^_[^_].*' + '|^global$|' + assertNames);
const outputPath = path.join(__dirname, 'dist');
del.sync([path.resolve(outputPath, '**/*')]);
const config = {
mode: 'production',
target: 'web',
entry: {'phenix-web-sdk': path.join(__dirname, 'src', 'web-sdk.js')},
output: {
library: 'phenix-web-sdk',
libraryTarget: 'umd',
umdNamedDefine: true,
path: outputPath,
filename: '[name].js'
},
plugins: [
new CaseSensitivePathsPlugin(),
new DuplicatesPlugin({
// Emit compilation warning or error? (Default: `false`)
emitErrors: true,
// Display full duplicates information? (Default: `false`)
verbose: false
})],
devtool: 'source-map',
performance: {hints: false},
optimization: {minimize: false},
resolve: {
alias: {
'phenix-web-assert': path.resolve(__dirname, 'node_modules', 'phenix-web-assert/dist/phenix-web-assert.js'),
'phenix-web-detect-browser': path.resolve(__dirname, 'node_modules', 'phenix-web-detect-browser/dist/phenix-web-detect-browser.js'),
'phenix-web-disposable': path.resolve(__dirname, 'node_modules', 'phenix-web-disposable/dist/phenix-web-disposable.js'),
'phenix-web-event': path.resolve(__dirname, 'node_modules', 'phenix-web-event/dist/phenix-web-event.js'),
'phenix-web-lodash-light': path.resolve(__dirname, 'node_modules', 'phenix-web-lodash-light/dist/phenix-web-lodash-light.js')
}
}
};
const externalizePhenixImports = (context, request, callback) => {
if (/^phenix-.*$/.test(request)){
return callback(null, true);
}
// Continue without externalizing the import
callback();
};
const noEdgeConfig = merge(config, {
output: {filename: config.output.filename.replace('.js', '-no-edge.js')},
resolve: {alias: {'webrtc-adapter': path.resolve(__dirname, 'node_modules', 'webrtc-adapter/out/adapter_no_edge_no_global.js')}}
});
const externalizedConfig = merge(config, {
output: {filename: '[name]-externalized.js'},
externals: [externalizePhenixImports, 'webrtc-adapter']
});
const reactNativeConfig = merge(config, {
entry: path.join(__dirname, 'src', 'react-native-sdk.js'),
output: {filename: 'phenix-web-sdk-react-native.js'},
resolve: {alias: {'phenix-rtc': path.resolve(__dirname, 'node_modules', 'phenix-rtc/dist/phenix-rtc-react-native')}}
});
const nodeConfig = merge(config, {
target: 'node',
entry: path.join(__dirname, 'src', 'node-sdk.js'),
output: {filename: 'phenix-node-sdk.js'},
resolve: {alias: {'webrtc-adapter': path.resolve(__dirname, 'node_modules', 'webrtc-adapter/out/adapter_no_edge_no_global.js')}}
});
const noPublishConfig = merge(config, {
output: {filename: config.output.filename.replace('.js', '-no-publish.js')},
resolve: {
alias: {
'./userMedia/UserMediaProvider': path.resolve(__dirname, 'src/dummy'),
'./sdk/userMedia/UserMediaResolver': path.resolve(__dirname, 'src/dummy'),
'../userMedia/UserMediaResolver': path.resolve(__dirname, 'src/dummy'),
'./sdk/bandwidth/BandwidthMonitor': path.resolve(__dirname, 'src/dummy'),
'./userMedia/ScreenShareExtensionManager': path.resolve(__dirname, 'src/dummy'),
'./sdk/audio/AudioSpeakerDetector': path.resolve(__dirname, 'src/dummy')
}
}
});
const minifiedConfigs = [config, noEdgeConfig, externalizedConfig, noPublishConfig].map(function(config) {
return merge(config, {
output: {filename: config.output.filename.replace('.js', '.min.js')},
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
mangle: {properties: {regex: uglifyManglePropRegex}},
output: {beautify: false},
compress: {passes: 2}
}
})
]
},
resolve: {
alias: {
'phenix-web-assert': path.resolve(__dirname, 'node_modules', 'phenix-web-assert/dist/phenix-web-assert.min.js'),
'phenix-web-detect-browser': path.resolve(__dirname, 'node_modules', 'phenix-web-detect-browser/dist/phenix-web-detect-browser.min.js'),
'phenix-web-disposable': path.resolve(__dirname, 'node_modules', 'phenix-web-disposable/dist/phenix-web-disposable.min.js'),
'phenix-web-event': path.resolve(__dirname, 'node_modules', 'phenix-web-event/dist/phenix-web-event.min.js'),
'phenix-web-lodash-light': path.resolve(__dirname, 'node_modules', 'phenix-web-lodash-light/dist/phenix-web-lodash-light.min.js')
}
}
});
});
module.exports = [config, noEdgeConfig, externalizedConfig, reactNativeConfig, nodeConfig, noPublishConfig].concat(minifiedConfigs);