This repository was archived by the owner on Oct 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
125 lines (112 loc) · 3.67 KB
/
webpack.config.js
File metadata and controls
125 lines (112 loc) · 3.67 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { EnvironmentPlugin } = require('webpack');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const dev = process.env.NODE_ENV === 'development';
const isProfiling = process.argv.includes('--profiling');
module.exports = {
mode: dev ? 'development' : 'production',
// https://webpack.js.org/configuration/dev-server/
devServer: {
hot: true,
port: 3000,
compress: true,
// accessible externally
host: '0.0.0.0',
},
// Controls how source maps are generated.
// https://webpack.js.org/configuration/devtool
devtool: dev ? 'inline-cheap-source-map' : 'source-map',
// Where webpack looks to start building the bundle.
// https://webpack.js.org/configuration/entry-context/
entry: ['react-hot-loader/patch', './src'],
// Instructing webpack on how and where it should output your bundles
// https://webpack.js.org/configuration/output/
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
// Changes how modules are resolved
// https://webpack.js.org/configuration/resolve
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
static: path.resolve(__dirname, 'src/static/'),
},
extensions: ['.js', '.jsx', '.json'],
},
// Determines how the different types of modules within a project will be treated
// https://webpack.js.org/configuration/module/
module: {
rules: [
{
oneOf: [
{
test: /\.(js|mjs|jsx)$/,
loader: require.resolve('babel-loader'),
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 4000,
name: 'static/media/[name].[hash:8].[ext]',
},
},
{
test: /\.html$/,
loader: 'html-loader',
},
{
exclude: [/\.(js|jsx)$/, /\.css$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
options: { name: '[hash:8].[ext]' },
},
],
},
],
},
plugins: [
// https://github.com/jantimon/html-webpack-plugin/blob/master/README.md
new HtmlWebpackPlugin(
// eslint-disable-next-line prefer-object-spread
Object.assign(
{
title: 'react-boilerplate',
template: path.resolve(__dirname, './public/index.html'),
favicon: path.resolve(__dirname, './public/favicon.ico'),
},
!dev
? {
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}
: undefined
)
),
// https://github.com/johnagan/clean-webpack-plugin/blob/master/README.md
new CleanWebpackPlugin(),
// https://webpack.js.org/plugins/environment-plugin/
new EnvironmentPlugin({
NODE_ENV: 'development',
}),
// https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/README.md
isProfiling ? new BundleAnalyzerPlugin() : undefined,
].filter(Boolean),
};