-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
181 lines (175 loc) · 6.04 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
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
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const DuplicatePackageCheckerPlugin = require("duplicate-package-checker-webpack-plugin");
// const WebpackPwaManifest = require('webpack-pwa-manifest');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const MANIFEST = require('./app/manifest.json');
const OUTPUT_FOLDER = './build/app';
const APP_ICON = './app/favicon.png';
module.exports = (env, options) => {
const isProduction = options.mode === 'production';
let _basePath = '/';
const { BASE_URL } = process.env;
if (isProduction && BASE_URL && (typeof BASE_URL === 'string')) {
_basePath = BASE_URL;
if (_basePath.substr(-1) != '/') _basePath += '/';
console.log(`Base url of this build is: ${_basePath}`);
}
const plugins = [
new CleanWebpackPlugin([OUTPUT_FOLDER], { watch: false }),
// hope that we can get rid of this once WebpackPwaManifest supports favicon
new FaviconsWebpackPlugin({
logo: APP_ICON,
persistentCache: false,
icons: {
android: false,
appleIcon: false,
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
opengraph: false,
twitter: false,
yandex: false,
windows: false
}
}),
new HtmlWebpackPlugin({
template: './app/index.html',
title: MANIFEST.name,
description: MANIFEST.description,
}),
new webpack.DefinePlugin({
'MODE': JSON.stringify(options.mode)
}),
new ForkTsCheckerWebpackPlugin({
checkSyntacticErrors: true,
tslint: true
}),
(isProduction ?
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle_analyze.html',
openAnalyzer: false
})
:
new CleanTerminalPlugin()
),
new DuplicatePackageCheckerPlugin(),
/*
new WebpackPwaManifest({
name: MANIFEST.name,
short_name: MANIFEST.short_name,
description: MANIFEST.description,
background_color: MANIFEST.background_color,
crossorigin: MANIFEST.crossorigin,
ios: MANIFEST.ios,
icons: [
{
src: path.resolve(APP_ICON),
sizes: [96, 128, 192, 256, 512]
}
]
})
*/
];
return {
devtool: isProduction? '' : 'inline-source-map',
entry: {
vendor: ['react', 'react-dom', 'react-loadable', 'mobx'],
client: './app/index.ts',
},
output: {
filename: '[name].[chunkhash].js',
path: path.join(__dirname, OUTPUT_FOLDER),
chunkFilename: '[name].[chunkhash].js',
publicPath: _basePath,
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor',
test: 'vendor',
enforce: true,
}
}
},
runtimeChunk: true,
},
plugins,
module: {
rules: [
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{ loader: 'cache-loader' },
{
loader: 'thread-loader',
options: {
// there should be 1 cpu for the fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
happyPackMode: true, // IMPORTANT! use happyPackMode mode to speed-up compilation and reduce errors reported to webpack,
logLevel: 'warn'
}
}
]
},
{
test: /.*\.(gif|png|jpe?g|svg)$/i,
loader: 'file-loader',
exclude: /node_modules/,
options: {
name: '/[name]_[hash:7].[ext]',
outputPath: 'assets/'
}
}
]
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: {
'@': path.resolve(__dirname, 'app/'),
'#': path.resolve(__dirname, 'build/contracts/'),
'bn.js': path.resolve(__dirname, 'node_modules/bn.js'),
'eth-lib': path.resolve(__dirname, 'node_modules/eth-lib'),
}
},
devServer: {
stats: {
all: false,
// chunks: true,
assets: true,
errors: true,
// timings: true,
performance: true,
warnings: true,
},
/*
proxy: {
"/api": {
target: "http://localhost:1234/",
secure: false,
pathRewrite: {"^/api" : ""}
}
}
*/
}
}
};