-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (95 loc) · 2.53 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
const { join, resolve } = require('path');
const Dotenv = require('dotenv-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { NODE_ENV, ANALYZE } = process.env;
const environment = NODE_ENV || 'development';
const isDev = environment === 'development';
module.exports = {
mode: environment,
devtool: isDev ? 'source-maps' : undefined,
entry: join(__dirname, 'src', 'index.js'),
output: {
path: join(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js',
},
resolve: {
alias: {
...(isDev
? {
'react-dom': '@hot-loader/react-dom',
}
: {}),
'react-router-dom': 'react-router-dom',
components: resolve(__dirname, 'src/components'),
containers: resolve(__dirname, 'src/containers'),
actions: resolve(__dirname, 'src/redux/actions'),
helpers: resolve(__dirname, 'src/helpers'),
api: resolve(__dirname, 'src/api'),
services: resolve(__dirname, 'src/services'),
config: resolve(__dirname, 'src/config'),
assets: resolve(__dirname, 'src/assets'),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
...(isDev
? {
plugins: ['react-hot-loader/babel'],
cacheDirectory: true,
}
: null),
},
},
],
},
{
test: /\.css$/,
exclude: [/node_modules/],
use: [
...(isDev ? ['css-hot-loader'] : []),
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader', options: { importLoaders: 1, modules: true } },
{ loader: 'postcss-loader' },
],
},
{
test: /\.(png|gif|jpg|jpeg|svg|xml)$/,
use: ['file-loader'],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['file-loader'],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: join(__dirname, 'src', 'index.html'),
}),
new MiniCssExtractPlugin({
filename: 'bundle.css',
}),
new Dotenv(),
...(ANALYZE ? [new BundleAnalyzerPlugin()] : []),
],
optimization: {
splitChunks: {
chunks: 'all',
minChunks: 2,
},
},
devServer: {
port: 3000,
historyApiFallback: true,
},
};