-
Notifications
You must be signed in to change notification settings - Fork 290
/
webpack.config.common.js
209 lines (202 loc) · 6.15 KB
/
webpack.config.common.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Wire
* Copyright (C) 2018 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DIST_PATH = path.resolve(__dirname, 'server/dist');
const ROOT_PATH = path.resolve(__dirname);
const SRC_PATH = path.resolve(__dirname, 'src');
const dist = path.resolve(DIST_PATH, 'static');
const auth = path.resolve(SRC_PATH, 'script/auth');
const checkBrowser = path.resolve(SRC_PATH, 'script/browser');
const srcScript = path.resolve(SRC_PATH, 'script');
const HOME_TEMPLATE_PATH = path.resolve(SRC_PATH, 'page/index.ejs');
const AUTH_TEMPLATE_PATH = path.resolve(SRC_PATH, 'page/auth.ejs');
const UNSUPPORTED_TEMPLATE_PATH = path.resolve(SRC_PATH, 'page/unsupported.ejs');
const {clientConfig, serverConfig} = require(path.resolve(DIST_PATH, 'config/index.js'));
const templateParameters = {
VERSION: clientConfig.VERSION,
BRAND_NAME: clientConfig.BRAND_NAME,
APP_BASE: clientConfig.APP_BASE,
OPEN_GRAPH_TITLE: serverConfig.OPEN_GRAPH.TITLE,
OPEN_GRAPH_DESCRIPTION: serverConfig.OPEN_GRAPH.DESCRIPTION,
OPEN_GRAPH_IMAGE_URL: serverConfig.OPEN_GRAPH.IMAGE_URL,
COUNTLY_API_KEY: serverConfig.COUNTLY_API_KEY,
COUNTLY_NONCE: serverConfig.COUNTLY_NONCE,
};
module.exports = {
cache: {
buildDependencies: {
// https://webpack.js.org/blog/2020-10-10-webpack-5-release/#persistent-caching
config: [__filename],
},
type: 'filesystem',
},
devtool: 'source-map',
entry: {
app: path.resolve(srcScript, 'main/index.tsx'),
auth: path.resolve(auth, 'main.tsx'),
checkBrowser: path.resolve(checkBrowser, 'CheckBrowser.ts'),
},
externals: {
'fs-extra': '{}',
worker_threads: '{}',
},
mode: 'production',
module: {
rules: [
{
exclude: /node_modules/,
include: srcScript,
loader: 'babel-loader',
test: /\.[tj]sx?$/,
},
{
loader: 'svg-inline-loader',
options: {
removeSVGTagAttrs: false,
},
test: /\.svg$/,
},
{
loader: 'raw-loader',
test: /\.glsl$/,
},
{
test: /\.less$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
url: false,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['autoprefixer'], [require('cssnano')()]],
},
},
},
{loader: 'less-loader'},
],
},
],
},
optimization: {
moduleIds: 'named',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
dexie: {
chunks: 'initial',
enforce: true,
name: 'dexie',
priority: 2,
test: /dexie/,
},
vendor: {
chunks: 'initial',
minChunks: 2,
name: 'vendor',
priority: 1,
test: /node_modules/,
},
},
},
},
output: {
chunkFilename: 'min/[name].js',
filename: 'min/[name].js',
path: dist,
publicPath: '/',
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new WorkboxPlugin.InjectManifest({
maximumFileSizeToCacheInBytes: process.env.NODE_ENV !== 'production' ? 10 * 1024 * 1024 : undefined,
swDest: path.resolve(dist, 'sw.js'),
swSrc: path.resolve(SRC_PATH, 'sw.js'),
}),
/* All wasm files will be ignored from webpack and copied over to the destination folder, they don't need any webpack processing */
new CopyPlugin({
patterns: [
{
context: 'node_modules/@wireapp/core-crypto/platforms/web',
from: '*.wasm',
to: `${dist}/min/core-crypto.wasm`,
},
{
context: 'node_modules/@mediapipe/tasks-vision/wasm',
from: '*',
to: `${dist}/min/mediapipe/wasm`,
},
// copying all static resources (audio, images, fonts...)
{from: 'resource', to: dist},
{from: `assets`, to: `${dist}/assets`},
{from: 'src/page/basicBrowserFeatureCheck.js', to: `${dist}/min/`},
{from: 'src/page/loader.js', to: `${dist}/min/`},
{from: 'src/page/countlyBoomerangCustom.js', to: `${dist}/min/`},
],
}),
new webpack.IgnorePlugin({resourceRegExp: /.*\.wasm/}),
// @todo: We should merge these when main & auth app are merged.
new HtmlWebpackPlugin({
inject: false,
template: HOME_TEMPLATE_PATH,
templateParameters,
}),
new HtmlWebpackPlugin({
inject: false,
filename: 'auth/index.html',
template: AUTH_TEMPLATE_PATH,
templateParameters,
}),
new HtmlWebpackPlugin({
inject: false,
filename: 'unsupported/index.html',
template: UNSUPPORTED_TEMPLATE_PATH,
templateParameters,
}),
],
resolve: {
alias: {
Components: path.resolve(srcScript, 'components'),
I18n: path.resolve(SRC_PATH, 'i18n'),
Resource: path.resolve(ROOT_PATH, 'resource'),
Util: path.resolve(srcScript, 'util'),
src: path.resolve(ROOT_PATH, 'src'),
test: path.resolve(ROOT_PATH, 'test'),
},
extensions: ['.js', '.jsx', '.ts', '.tsx', '.svg'],
fallback: {
crypto: false,
fs: false,
os: require.resolve('os-browserify'),
path: require.resolve('path-browserify'),
},
modules: [auth, 'node_modules'],
},
};