forked from ringcentral/ringcentral-web-phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
127 lines (123 loc) · 2.66 KB
/
webpack.config.ts
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
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import { Configuration } from 'webpack';
const commonConfig = {
devtool: 'source-map',
resolve: {
extensions: ['.tsx', '.ts', '.js'],
fallback: {
querystring: require.resolve('querystring-es3'),
crypto: require.resolve('crypto-browserify'),
buffer: require.resolve('buffer/'),
stream: require.resolve('stream-browserify'),
},
},
};
const libConfig: Configuration = {
...commonConfig,
mode: 'development',
entry: {
'ringcentral-web-phone': './src/index.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
library: ['RingCentral', 'WebPhone'],
libraryTarget: 'umd',
libraryExport: 'default',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
'cache-loader',
{
loader: 'ts-loader',
options: {
onlyCompileBundledFiles: true,
},
},
],
include: path.resolve('src'),
},
{
test: /\.m?js?$/,
resolve: {
fullySpecified: false,
},
},
],
},
externals: {
'sip.js': {
commonjs: 'sip.js',
commonjs2: 'sip.js',
amd: 'sip.js',
root: 'SIP',
},
},
};
const demoConfig = {
...commonConfig,
mode: libConfig.mode,
entry: {
demo: './demo/index.js',
demoCallback: './demo/callback.js',
},
output: {
path: libConfig.output!.path,
filename: libConfig.output!.filename,
},
externals: {
'ringcentral-web-phone': {
commonjs: 'ringcentral-web-phone',
commonjs2: 'ringcentral-web-phone',
amd: 'ringcentral-web-phone',
root: ['RingCentral', 'WebPhone'],
},
},
module: {
rules: [
{
test: /\.m?js?$/,
resolve: {
fullySpecified: false,
},
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './demo/index.html',
inject: false,
chunks: ['demo', 'demoVendor'],
}),
new HtmlWebpackPlugin({
template: './demo/callback.html',
filename: 'callback.html',
chunks: ['demoCallback', 'demoVendor'],
}),
// FIXME Replace with file loader
new CopyPlugin({
patterns: [
{ from: 'audio', to: 'audio' },
{ from: 'demo/img', to: 'img' },
],
}),
],
optimization: {
minimize: true,
splitChunks: {
cacheGroups: {
vendor: {
test: /node_modules/,
name: 'demoVendor',
chunks: 'all',
},
},
},
},
};
export default [libConfig, demoConfig];