forked from Chia-Network/chia-blockchain-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.react.babel.ts
178 lines (175 loc) · 4.6 KB
/
webpack.react.babel.ts
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
import webpack from 'webpack';
import path from 'path';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import LoadablePlugin from '@loadable/webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
const PORT = 3000;
const CONTEXT = __dirname;
const DEV = process.env.NODE_ENV !== 'production';
const LOOSE = false;
const babelQuery = {
babelrc: false,
presets: [
['@babel/preset-env', {
useBuiltIns: 'entry',
corejs: 3,
loose: LOOSE,
}],
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
'lodash',
'@loadable/babel-plugin',
'babel-plugin-styled-components',
['@babel/plugin-proposal-class-properties', { loose: LOOSE }],
'@babel/plugin-proposal-export-default-from',
['babel-plugin-transform-imports', {
'@material-ui/core': {
// Use "transform: '@material-ui/core/${member}'," if your bundler does not support ES modules
'transform': '@material-ui/core/${member}',
'preventFullImport': true,
},
'@material-ui/icons': {
// Use "transform: '@material-ui/icons/${member}'," if your bundler does not support ES modules
'transform': '@material-ui/icons/${member}',
'preventFullImport': true,
},
}],
DEV && require.resolve('react-refresh/babel'),
].filter(Boolean),
};
export default {
mode: DEV ? 'development' : 'production',
context: CONTEXT,
devtool: DEV ? 'inline-source-map' : 'source-map',
entry: path.join(CONTEXT, '/src/index'),
target: 'electron-renderer',
stats: 'errors-only',
devServer: DEV ? {
client: {
overlay: false,
},
static: {
directory: path.join(__dirname, '../dist/renderer'),
},
historyApiFallback: true,
compress: true,
hot: true,
port: PORT,
devMiddleware: {
publicPath: '/',
},
} : undefined,
output: {
path: path.resolve(__dirname, './build/renderer'),
filename: 'js/[name].js',
publicPath: './',
hashFunction: "sha256",
},
resolve: {
extensions: ['.wasm', '.mjs', '.ts', '.tsx', '.js', '.jsx', '.json'],
modules: [
path.resolve(CONTEXT, 'node_modules'),
path.resolve(CONTEXT, '../../node_modules'),
'node_modules',
],
alias: {
"@chia/core": `${__dirname}/src/components/core`,
"@chia/icons": `${__dirname}/src/components/icons`,
crypto: 'crypto-browserify',
stream: 'stream-browserify',
},
},
optimization: {
splitChunks: {
chunks: 'all',
},
usedExports: true,
minimize: !DEV,
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {
// collapse_vars: false,
// drop_console: true,
},
mangle: true, // Note `mangle.properties` is `false` by default.
module: false,
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: true,
},
}),
],
},
plugins: [
new LoadablePlugin(),
new LodashModuleReplacementPlugin({
paths: true,
flattening: true,
shorthands: true,
collections: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(DEV ? 'development' : 'production'),
'process.env.BROWSER': true,
IS_BROWSER: true,
}),
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body',
}),
DEV && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
module: {
rules: [{
test: /node_modules[\/\\](iconv-lite)[\/\\].+/,
resolve: {
aliasFields: ['main'],
},
}, {
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
}, {
test: /\.[jt]sx?$/,
exclude: DEV ? /node_modules/ : undefined,
use: [{
loader: 'babel-loader',
options: babelQuery,
}],
}, {
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
}, {
test: /\.(woff|woff2?|ttf|eot)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10000,
},
},
generator: {
filename: '[name]-[contenthash:8][ext]',
},
}, {
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
}, {
test: /\.(gif|png|jpe?g)$/i,
use: [{
loader: 'file-loader',
}],
}],
},
};