forked from ringcentral/ringcentral-embeddable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack-dev-server.config.js
More file actions
103 lines (92 loc) · 2.76 KB
/
webpack-dev-server.config.js
File metadata and controls
103 lines (92 loc) · 2.76 KB
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
require('@babel/register')({
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
ignore: [/node_modules/],
rootMode: 'upward',
});
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
require('dotenv').config();
const { version } = require('./package');
const getBaseConfig = require('./getWebpackBaseConfig');
const defaultBrand = process.env.BRAND || 'rc';
const { getBrandConfig, brandConfigs } = require('./getBrandConfig');
const buildPath = path.resolve(__dirname, 'src');
const apiConfigFile = path.resolve(__dirname, 'api.json');
let apiConfig;
if (fs.existsSync(apiConfigFile)) {
apiConfig = JSON.parse(fs.readFileSync(apiConfigFile));
} else {
apiConfig = {
appKey: process.env.API_KEY,
appSecret: process.env.API_SECRET,
server: process.env.API_SERVER,
};
}
const errorReportKey = process.env.ERROR_REPORT_KEY;
function getWebpackConfig({ brand, styleLoader }) {
const { prefix, brandFolder } = getBrandConfig(brand);
const config = getBaseConfig({ themeFolder: brandFolder, styleLoader });
config.devServer = {
contentBase: buildPath,
hot: true,
inline: true,
port: 8080,
};
config.output = {
path: buildPath,
filename: '[name].js',
};
config.plugins = [
...config.plugins,
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('development'),
API_CONFIG: JSON.stringify(apiConfig),
APP_VERSION: JSON.stringify(version),
PREFIX: JSON.stringify(prefix),
BRAND: JSON.stringify(brand),
BRAND_CONFIGS: JSON.stringify(brandConfigs),
ERROR_REPORT_KEY: JSON.stringify(errorReportKey),
RECORDING_LINK: JSON.stringify('https://ringcentral.github.io/ringcentral-media-reader/'),
ADAPTER_NAME: JSON.stringify('adapter.js'),
},
}),
];
config.devtool = 'eval-source-map';
config.mode = 'development';
config.resolve = {
...config.resolve,
alias: {
'brand-logo-path': brandFolder,
},
};
if (process.env.CI) {
config.watchOptions = {
ignored: /node_modules/,
};
}
return config;
}
function getAppWebpackConfig({ brand }) {
const config = getWebpackConfig({ brand, styleLoader: 'style-loader' });
config.entry = {
app: ['@babel/polyfill', './src/app.js'],
proxy: './src/proxy.js',
redirect: './src/redirect.js',
};
return config;
}
function getAdapterWebpackConfig({ brand }) {
const config = getWebpackConfig({ brand, styleLoader: 'style-loader' });
config.entry = {
'adapter': './src/adapter.js',
};
return config;
}
module.exports = [
getAppWebpackConfig({ brand: defaultBrand}),
getAdapterWebpackConfig({ brand: defaultBrand })
];