-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
91 lines (88 loc) · 2.32 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
const path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'),
ESLintPlugin = require('eslint-webpack-plugin'),
{ merge } = require('webpack-merge'),
dotenv = require('dotenv').config(),
devConfig = require('./config/webpack.dev.config'),
prodConfig = require('./config/webpack.prod.config');
const APP_PATH = path.resolve(__dirname, '.', 'src');
const DIST_PATH = path.resolve(__dirname, '.', 'dist');
const TEMPLETE_PATH = path.resolve(__dirname, '.', 'public', 'index.html');
const { TITLE } = dotenv.parsed;
baseConfig = {
entry: APP_PATH,
output: {
path: DIST_PATH,
filename: 'js/[name].bundle.js',
},
resolve: {
modules: [APP_PATH, 'node_modules'],
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
module: {
rules: [
{
test: /\.(ts|tsx|js)$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.woff(2)?(\?v=[a-z0-9]\.[a-z0-9]\.[a-z0-9])?$/,
use: ['url-loader?limit=10000'],
},
{
test: /\.(ttf|eot)(\?v=[a-z0-9]\.[a-z0-9]\.[a-z0-9])?$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
},
],
},
plugins: [
new ESLintPlugin({
exclude: ['node_modules'],
}),
new HtmlWebpackPlugin({
template: TEMPLETE_PATH,
filename: 'index.html',
title: TITLE,
minify: {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
minifyCSS: true,
minifyURLs: true,
minifyJS: true,
removeComments: true,
removeRedundantAttributes: true,
},
}),
new ForkTsCheckerWebpackPlugin(),
],
};
module.exports = (env) => {
switch (env.MODE) {
case 'dev':
return merge(baseConfig, devConfig(env));
case 'prod':
return merge(baseConfig, prodConfig(env));
default:
throw new Error('No matching configuration was found!');
}
};