forked from jmrossy/celo-web-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
151 lines (147 loc) · 4.48 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
const webpack = require('webpack')
const path = require('path')
const CopyPlugin = require('copy-webpack-plugin')
const packageJson = require('./package.json')
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isDevelopment = process.env.NODE_ENV === 'development'
const isProduction = process.env.NODE_ENV === 'production'
const targetElectron = process.env.BUILD_TARGET === 'electron'
console.log(`Building with webpack. isProduction:${isProduction}, targetElectron:${targetElectron}`)
const config = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
chunkFilename: 'bundle-[name].js',
},
optimization: {
splitChunks: {
minChunks: 3, // Prevents the ledger dynamic bundle from getting split up into separate vendors + local
minSize: 90000, // Prevent a fourth bundle with walletconnect + ledger common libs
enforceSizeThreshold: 100000,
},
},
externals: {
'node-hid': 'commonjs node-hid',
ws: 'ws', // Exclude WS to work around walletconnect client bundling issue
},
// https://github.com/webpack/webpack-dev-server/issues/2758
// TODO remove when fixed, should be in v4 upgrade
target: targetElectron ? 'electron-renderer' : isDevelopment ? 'web' : 'browserslist',
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: [
{
loader: 'babel-loader',
options: { cacheDirectory: true },
},
{
loader: 'eslint-loader',
},
],
exclude: /node_modules/,
},
{
test: /\.ts(x)?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { cacheDirectory: true },
},
{
loader: 'ts-loader',
},
{
loader: 'eslint-loader',
},
],
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 0,
modules: false,
},
},
],
exclude: /node_modules/,
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg|)$/,
type: 'asset/inline',
},
],
},
resolve: {
alias: {
'src/features/storage/storageProvider$': targetElectron
? 'src/features/storage/storageProvider-electron.ts'
: 'src/features/storage/storageProvider.ts',
'src/features/ledger/ledgerTransport$': targetElectron
? 'src/features/ledger/ledgerTransport-electron.ts'
: 'src/features/ledger/ledgerTransport.ts',
'src/app/update$': targetElectron ? 'src/app/update-electron.ts' : 'src/app/update.ts',
'src/app/deepLink$': targetElectron ? 'src/app/deepLink-electron.ts' : 'src/app/deepLink.ts',
},
extensions: ['.js', '.jsx', '.tsx', '.ts'],
modules: [path.resolve('./node_modules'), path.resolve('./')],
},
// Note about react fast refresh: I tried to enable this but it doesn't seem to work with webpack 5 yet.
plugins: [
// Copy over static files
new CopyPlugin(
targetElectron
? {
patterns: [
{ from: './package-electron.json', to: 'package.json' },
{ from: './src/index.html', to: 'index.html' },
{ from: './electron/main.js', to: 'main.js' },
{ from: './static/*', to: 'static/[name][ext]' },
],
}
: {
patterns: [
{ from: './src/index.html', to: 'index.html' },
{ from: './netlify/*', to: '[name][ext]' },
{ from: './static/*', to: 'static/[name][ext]' },
],
}
),
// Inject some constants into the built code
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(packageJson.version),
__DEBUG__: isDevelopment,
__IS_ELECTRON__: targetElectron,
}),
// Bundle analyzer, don't leave enabled
// new BundleAnalyzerPlugin(),
],
devServer: {
historyApiFallback: true,
hot: true,
open: { target: '/', app: 'Google Chrome' },
},
// Show some extra info during build
stats: {
assets: true,
assetsSort: 'size',
nestedModules: true,
chunks: true,
chunkGroups: true,
chunkModules: true,
chunkOrigins: true,
modules: true,
modulesSort: 'size',
assetsSpace: 200,
modulesSpace: 200,
nestedModulesSpace: 50,
},
}
module.exports = config