-
Notifications
You must be signed in to change notification settings - Fork 346
/
webpack.config.js
190 lines (185 loc) · 6.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
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const glob = require('glob');
const {BannerPlugin, DefinePlugin, EnvironmentPlugin} = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const {version} = require('./packages/webex/package.json');
const callingPackage = require('./packages/calling/package.json');
dotenv.config();
dotenv.config({path: '.env.default'});
/**
* Webpack Config
*
* @param {object} [env]
* @param {string} env.NODE_ENV
* @returns {object}
*/
module.exports = (env = {NODE_ENV: process.env.NODE_ENV || 'production'}) => ({
entry: {
webex: {
import:
env && env.NODE_ENV === 'development'
? `${path.resolve(__dirname)}/packages/webex/src/index.js`
: './packages/webex',
library: {
name: 'Webex',
type: 'umd',
},
},
meetings: {
import: `${path.resolve(__dirname)}/packages/webex/src/meetings.js`,
library: {
name: 'Webex',
type: 'umd',
},
},
calling: {
import: `${path.resolve(__dirname)}/packages/webex/src/calling.js`,
library: {
name: 'Calling',
type: 'umd',
export: 'default',
},
},
},
mode: env && env.NODE_ENV === 'development' ? 'development' : 'production',
output: {
filename: '[name].min.js',
sourceMapFilename: '[file].map',
path:
env && env.umd
? `${path.resolve(__dirname)}/packages/webex/umd`
: `${path.resolve(__dirname)}/docs/samples`,
},
devtool: env && env.NODE_ENV === 'development' ? 'eval-cheap-module-source-map' : 'source-map',
devServer: {
https: true,
port: process.env.PORT || 8000,
static: './docs',
},
resolve: {
fallback: {
fs: false,
os: require.resolve('os-browserify'),
stream: require.resolve('stream-browserify'),
querystring: require.resolve('querystring-es3'),
crypto: false,
},
extensions: ['.ts', '.js', '.json'],
alias: glob
.sync('**/package.json', {cwd: './packages'})
.map((p) => path.dirname(p))
.reduce((alias, packageName) => {
// Always use src as the entry point for local files so that we have the
// best opportunity for treeshaking; also makes developing easier since
// we don't need to manually rebuild after changing code.
alias[`./packages/${packageName}`] = path.resolve(
__dirname,
`./packages/${packageName}/src/index`
);
alias[`${packageName}`] = path.resolve(__dirname, `./packages/${packageName}/src/index`);
return alias;
}, {}),
},
module: {
rules: [
{
test: /\.(js|tsx|ts)$/,
include: [/packages/],
use: {
loader: 'babel-loader',
},
},
],
},
...(env !== 'development' && {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
cache: true,
extractComments: false,
parallel: true,
sourceMap: true,
terserOptions: {
output: {
preamble: `/*! Webex JS SDK v${process.env.VERSION || version} */`,
comments: false,
},
},
}),
],
},
}),
plugins: [
// If in integration and building for production (not testing) use production URLS
...(env && env.NODE_ENV === 'test'
? [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
// Environment Plugin doesn't override already defined Environment Variables (i.e. DotENV)
new EnvironmentPlugin({
WEBEX_LOG_LEVEL: 'log',
DEBUG: '',
NODE_ENV: 'production',
// The following environment variables are specific to our continuous
// integration process and should not be used in general
ATLAS_SERVICE_URL: 'https://atlas-intb.ciscospark.com/admin/api/v1',
CONVERSATION_SERVICE: 'https://conversation-intb.ciscospark.com/conversation/api/v1',
ENCRYPTION_SERVICE_URL: 'https://encryption-intb.ciscospark.com/encryption/api/v1',
HYDRA_SERVICE_URL: 'https://apialpha.ciscospark.com/v1/',
IDBROKER_BASE_URL: 'https://idbrokerbts.webex.com',
IDENTITY_BASE_URL: 'https://identitybts.webex.com',
U2C_SERVICE_URL: 'https://u2c-intb.ciscospark.com/u2c/api/v1',
WDM_SERVICE_URL: 'https://wdm-intb.ciscospark.com/wdm/api/v1',
WHISTLER_API_SERVICE_URL: 'https://whistler.allnint.ciscospark.com/api/v1',
WEBEX_CONVERSATION_DEFAULT_CLUSTER: 'urn:TEAM:us-east-1_int13:identityLookup',
}),
]
: [
new webpack.ProvidePlugin({
process: 'process/browser',
}),
new BannerPlugin({
banner: `Webex JS SDK v${process.env.VERSION || version}`,
}),
new EnvironmentPlugin({
WEBEX_LOG_LEVEL: 'log',
DEBUG: '',
NODE_ENV: env && env.NODE_ENV === 'development' ? 'development' : 'production',
}),
// This allows overwriting of process.env
new DefinePlugin({
'process.env': {
// Use production URLs with samples
ATLAS_SERVICE_URL: JSON.stringify('https://atlas-a.wbx2.com/admin/api/v1'),
CONVERSATION_SERVICE: JSON.stringify('https://conv-a.wbx2.com/conversation/api/v1'),
ENCRYPTION_SERVICE_URL: JSON.stringify('https://encryption-a.wbx2.com'),
HYDRA_SERVICE_URL: JSON.stringify('https://api.ciscospark.com/v1'),
IDBROKER_BASE_URL: JSON.stringify('https://idbroker.webex.com'),
IDENTITY_BASE_URL: JSON.stringify('https://identity.webex.com'),
U2C_SERVICE_URL: JSON.stringify('https://u2c.wbx2.com/u2c/api/v1'),
WDM_SERVICE_URL: JSON.stringify('https://wdm-a.wbx2.com/wdm/api/v1'),
WHISTLER_API_SERVICE_URL: JSON.stringify(
'https://whistler-prod.allnint.ciscospark.com/api/v1'
),
CALLING_SDK_VERSION: JSON.stringify(callingPackage.version),
},
}),
]),
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /a\.js|node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd(),
}),
],
});