-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.babel.js
202 lines (197 loc) · 5.91 KB
/
webpack.config.babel.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
import HtmlWebPackPlugin from 'html-webpack-plugin'
import webpack from 'webpack'
import InlineChunkHtmlPlugin from 'react-dev-utils/InlineChunkHtmlPlugin'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import PreloadWebpackPlugin from 'preload-webpack-plugin'
import FaviconsWebpackPlugin from 'favicons-webpack-plugin'
import markdownIt from 'markdown-it'
import linkAttributes from 'markdown-it-link-attributes'
import path from 'path'
import dotenv from 'dotenv'
import loadConfig from './src/loadConfig'
// Setup env vars
dotenv.config()
const isProduction = process.env.NODE_ENV == 'production'
const baseUrl = isProduction ? '' : '/'
const config = loadConfig()
const { name: appName } = config
module.exports = ({ stats = false } = {}) => ({
devtool: isProduction ? 'source-map' : 'eval-source-map',
output: {
path: __dirname + '/dist',
chunkFilename: isProduction ? '[name].[contenthash].js' : '[name].js',
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
publicPath: baseUrl,
},
module: {
rules: [
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
disable: !isProduction,
},
},
],
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: { cacheDirectory: true },
},
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: { cacheDirectory: true },
},
{
loader: 'ts-loader',
options: {
// disable type checker - we will use it in fork plugin
transpileOnly: true,
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(ttf|otf|eot|woff2?)(\?[a-z0-9]+)?$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
},
{
test: /\.md$/,
use: {
loader: 'frontmatter-markdown-loader',
options: {
mode: ['react-component'],
markdownIt: markdownIt({
html: true,
linkify: true,
breaks: true,
xhtmlOut: true,
}).use(linkAttributes, {
attrs: {
target: '_blank',
rel: 'noopener noreferrer',
},
}),
},
},
},
],
},
devServer: {
historyApiFallback: true,
},
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
'bn.js': path.resolve(__dirname, 'node_modules/bn.js'),
},
modules: ['custom', 'src', 'node_modules'],
extensions: ['.ts', '.tsx', '.js'],
},
// drop unused deps
// https://www.amcharts.com/docs/v4/getting-started/integrations/using-webpack/#Large_file_sizes
externals: function(context, request, callback) {
if (/xlsx|canvg|pdfmake/.test(request)) {
return callback(null, 'commonjs ' + request)
}
callback()
},
plugins: [
new HtmlWebPackPlugin({
template: config.templatePath,
title: appName,
ipfsHack: isProduction,
minify: isProduction && {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new FaviconsWebpackPlugin({
logo: config.logoPath,
mode: 'webapp', // optional can be 'webapp' or 'light' - 'webapp' by default
devMode: 'webapp', // optional can be 'webapp' or 'light' - 'light' by default
favicons: {
appName: appName,
appDescription: appName,
developerName: appName,
developerURL: null, // prevent retrieving from the nearest package.json
background: '#dfe6ef',
themeColor: '#476481',
icons: {
coast: false,
yandex: false,
},
},
}),
new PreloadWebpackPlugin({
rel: 'prefetch',
include: 'allAssets',
fileBlacklist: [/\.map/, /runtime~.+\.js$/],
}),
isProduction && new InlineChunkHtmlPlugin(HtmlWebPackPlugin, [/runtime/]),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
BASE_URL: baseUrl,
// MOCK: Use mock or real API implementation
MOCK: 'false',
MOCK_WALLET: process.env.MOCK || 'false',
MOCK_TOKEN_LIST: process.env.MOCK || 'false',
MOCK_ERC20: process.env.MOCK || 'false',
MOCK_WETH: process.env.MOCK || 'false',
MOCK_DEPOSIT: process.env.MOCK || 'false',
MOCK_EXCHANGE: process.env.MOCK || 'false',
MOCK_WEB3: process.env.MOCK || 'false',
// AUTOCONNECT: only applies for mock implementation
AUTOCONNECT: 'true',
PRICE_ESTIMATOR_URL: process.env.PRICE_ESTIMATOR_URL || 'develop',
}),
new ForkTsCheckerWebpackPlugin({ silent: stats }),
// define inside one plugin instance
new webpack.DefinePlugin({
VERSION: JSON.stringify(require('./package.json').version),
DEX_JS_VERSION: JSON.stringify(require('@gnosis.pm/dex-js/package.json').version),
DEX_JS_1_VERSION: JSON.stringify(require('@diadata.org/dex-js-1/package.json').version),
CONTRACT_VERSION: JSON.stringify(require('@gnosis.pm/dex-contracts/package.json').version),
CONFIG: JSON.stringify(config),
}),
].filter(Boolean),
optimization: {
moduleIds: 'hashed',
splitChunks: {
chunks: 'all',
minSize: 20000,
maxAsyncRequests: 10,
maxSize: 1000000,
},
runtimeChunk: true,
},
})