forked from GamesDoneQuick/donation-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
136 lines (132 loc) · 3.65 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
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WebpackManifestPlugin = require('webpack-yam-plugin');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const PROD = process.env.NODE_ENV === 'production';
const SOURCE_MAPS = +(process.env.SOURCE_MAPS || 0);
const NO_MANIFEST = +(process.env.NO_MANIFEST || 0);
const NO_HMR = PROD || +(process.env.NO_HMR || 0);
console.log(PROD ? 'PRODUCTION BUILD' : 'DEVELOPMENT BUILD');
function compact(array) {
return [...array].filter(n => !!n);
}
module.exports = {
context: __dirname,
mode: PROD ? 'production' : 'development',
entry: {
admin: './bundles/admin',
tracker: './bundles/tracker',
},
output: {
filename: PROD ? 'tracker-[name]-[hash].js' : 'tracker-[name].js',
pathinfo: true,
path: __dirname + '/tracker/static/gen',
publicPath: '/static/gen',
},
stats: 'minimal',
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: compact([!NO_HMR && 'react-hot-loader/webpack', 'babel-loader']),
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// only enable hot in development
hmr: !PROD,
},
},
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: {
mode: 'local',
localIdentName: '[local]--[hash:base64:10]',
},
},
},
'postcss-loader',
],
},
{
test: /\.(png|jpg|svg)$/,
use: ['url-loader'],
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['url-loader?limit=10000&mimetype=application/font-woff'],
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: ['file-loader'],
},
],
},
node: {
fs: 'empty',
},
resolve: {
alias: {
'@admin': path.resolve('bundles', 'admin'),
'@common': path.resolve('bundles', 'common'),
'@public': path.resolve('bundles', 'public'),
'@tracker': path.resolve('bundles', 'tracker'),
'@uikit': path.resolve('bundles', 'uikit'),
...(NO_HMR ? {} : { 'react-dom': '@hot-loader/react-dom' }),
},
extensions: ['.js', '.ts', '.tsx'],
},
optimization: {
splitChunks: {
chunks: 'async',
},
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
output: {
comments: /@license/i,
},
},
}),
],
},
devServer: PROD
? {}
: {
proxy: [
{
context: ['/admin', '/logout', '/api', '/ui', '/static', '/tracker', '/donate', '/media'],
target: process.env.TRACKER_HOST || 'http://localhost:8000/',
ws: true,
},
],
allowedHosts: ['localhost', '127.0.0.1', '.ngrok.io'],
},
plugins: compact([
new webpack.optimize.OccurrenceOrderPlugin(),
!NO_MANIFEST &&
new WebpackManifestPlugin({
manifestPath: __dirname + '/tracker/ui-tracker.manifest.json',
outputRoot: __dirname + '/tracker/static',
}),
new MiniCssExtractPlugin({
filename: PROD ? 'tracker-[name]-[hash].css' : 'tracker-[name].css',
chunkFilename: PROD ? '[id].[hash].css' : '[id].css',
ignoreOrder: false,
}),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
}),
]),
devtool: SOURCE_MAPS ? (PROD ? 'source-map' : 'eval-source-map') : false,
};