-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack-production.config.js
177 lines (172 loc) · 5 KB
/
webpack-production.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
const webpack = require('webpack');
const path = require('path');
const dotenv = require('dotenv');
const autoprefixer = require('autoprefixer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const packageConfig = require('./package');
const buildPath = path.resolve(__dirname, 'release');
dotenv.config();
const apiConfig = {
appKey: process.env.RINGCENTRAL_CLIENT_ID,
appSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
server: process.env.RINGCENTRAL_SERVER_URL,
redirectUri: process.env.REDIRECT_URI,
};
const version = packageConfig.version;
const config = {
mode: 'production',
entry: {
index: './src/index.js',
proxy: './src/proxy.js',
redirect: './src/redirect.js',
},
output: {
path: buildPath,
filename: '[name].js',
},
resolve: {
// webpack < 5 used to include polyfills for node.js core modules by default.
// This is no longer the case. Verify if you need this module and configure a polyfill for it.
//
// more doc: https://webpack.js.org/configuration/resolve/#resolvefallback
//
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
vm: require.resolve('vm-browserify'),
timers: require.resolve('timers-browserify'),
process: require.resolve('process/browser'),
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
console: require.resolve('console-browserify'),
constants: require.resolve('constants-browserify'),
domain: require.resolve('domain-browser'),
events: require.resolve('events'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
punycode: require.resolve('punycode'),
querystring: require.resolve('querystring-es3'),
string_decoder: require.resolve('string_decoder'),
sys: require.resolve('util'),
tty: require.resolve('tty-browserify'),
url: require.resolve('url'),
util: require.resolve('util'),
zlib: require.resolve('browserify-zlib'),
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser.js',
Buffer: ['buffer', 'Buffer'],
setImmediate: ['setimmediate', 'setImmedate'],
clearImmediate: ['setimmediate', 'clearImmedate'],
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
API_CONFIG: JSON.stringify(apiConfig),
APP_VERSION: JSON.stringify(version),
},
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/index.html', to: 'index.html' },
{ from: 'src/proxy.html', to: 'proxy.html' },
{ from: 'src/redirect.html', to: 'redirect.html' },
],
}),
],
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.md$/,
use: 'raw-loader',
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.svg/,
exclude: /font|src(\/|\\)assets(\/|\\)images/,
use: [
'babel-loader',
{
loader: 'react-svg-loader',
options: {
jsx: true,
svgo: {
plugins: [
{
removeViewBox: false,
},
],
},
},
},
],
},
{
test: /\.woff|\.woff2|.eot|\.ttf/,
// use:
// 'url-loader?limit=15000&publicPath=./&name=fonts/[name]_[hash].[ext]',
use: {
loader: 'url-loader',
options: {
limit: 15000,
name: 'fonts/[name]_[hash].[ext]',
// TODO: it should be upgrade css-loader and update config
esModule: false,
},
},
},
{
test: /\.png|\.jpg|\.gif|\.svg/,
exclude:
/@ringcentral-integration(\/|\\)widgets(\/|\\)assets(\/|\\)images(\/|\\).+\.svg/,
use: 'url-loader?limit=20000&publicPath=./&name=images/[name]_[hash].[ext]',
},
{
test: /\.sass|\.scss/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
localIdentName: '[folder]_[local]',
modules: true,
},
},
{
loader: 'postcss-loader',
options: {
plugins() {
return [autoprefixer];
},
},
},
{
loader: 'sass-loader',
options: {
outputStyle: 'expanded',
includePaths: ['src', 'node_modules'],
},
},
],
},
{
test: /\.ogg$/,
use: 'file-loader?publicPath=./&name=audio/[name]_[hash].[ext]',
},
],
},
};
module.exports = config;