-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
141 lines (128 loc) · 3.72 KB
/
webpack.config.js
File metadata and controls
141 lines (128 loc) · 3.72 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* eslint-disable global-require */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';
// The default port value can be overridden at the command line
const port = process.env.PORT || 3000;
const config = {
entry: {
/* babel-polyfill is used for promises and whatnot. Stated differently,
babel-loader handles all of the transpiled features, while the babel
polyfill is used to extend the browser to feature that cannot be
transpiled. Meaning, index.js below is the primary application entry
point */
app: ['babel-polyfill', './src/index.js'],
// Split out a vendor specific packages into a vendor module
vendor: ['axios', 'react', 'react-dom', 'react-router-dom'],
},
output: {
path: path.resolve(__dirname, 'dist'),
/* Add a hash to each emitted blob, allowing it to be dynamically
updated */
filename: 'static/[name].[hash].js',
publicPath: '/',
},
devtool: devMode ? 'source-map' /* A full source map is emitted as a
separate file in development. */
: 'hidden-source-map', /* In production, capture the output and send
it to a third party service for you to
examine. This way you can capture errors
and fix them. */
module: {
rules: [
/* babel-loader handles all of the new fangled ES6+ translations
as we all the JSX translations. See the babel configuration block
in package.json */
{
test: /\.(js[x]?)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
// Basic CSS loader --- Intentionally commented out
// {
// test: /\.css$/,
// exclude: /node_modules/,
// use: ['style-loader', 'css-loader'],
// },
/* Loader for styling */
{
test: /\.(sa|sc|c)ss$/,
exclude: /node_modules/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader',
{
loader: 'postcss-loader',
options: {
plugins: () => [require('autoprefixer')({
browsers: ['> 1%', 'last 2 versions'],
})],
},
},
],
},
/* Loader for images */
{
test: /\.(jpg|png|svg)$/,
exclude: /node_modules/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
context: './src/images',
outputPath: 'images/',
},
},
},
/* Loader for fonts */
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
exclude: /node_modules/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
context: './src/fonts',
outputPath: 'fonts/',
},
}],
},
],
},
// Used only by webpack-dev-server
devServer: {
historyApiFallback: true, /* Without this, a browser refresh will cause
an http request to the server */
port, // port: port,
},
/* This optimization section is "magic" to my brain at least. It apparently
makes sure the vendor bundle size is as small as possible. See:
https://github.com/webpack/webpack/issues/6357 */
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
test: 'vendor',
name: 'vendor',
enforce: true,
},
},
},
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico',
}),
new MiniCssExtractPlugin({
filename: devMode ? 'styles/[name].css' : 'styles/[name].[hash].css',
chunkFilename: devMode ? 'styles/[id].css' : 'styles/[id].[hash].css',
}),
],
// Webpack 4 handles all of the minification during production
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
};
module.exports = config;