-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
103 lines (101 loc) · 3.37 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
/* eslint-env node */
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
// For production build, set this env var to the server public path.
const publicPath = process.env.APP_PUBLIC_PATH || '/';
module.exports = function (env, argv) {
const { hot, mode } = argv;
const isDevelopment = mode === 'development';
return {
// entry: './src/index.js', // The default entry works fine, but this can be customized.
output: {
filename: `[name]-[${hot ? 'hash' : 'chunkhash'}].js`, // Default '[name].js'
// path: path.resolve(__dirname, 'build'), // Default 'dist'
// If you change path, you probably want to change the contentBase path in
// devServer to match.
publicPath,
},
devServer: {
// host: '0.0.0.0', // Uncomment to allow connections from local network.
contentBase: path.join(__dirname, 'dist'),
https: true,
historyApiFallback: true, // Default to expecting React Router.
// Setup a proxy:
// proxy: {
// // All requests which start with `/api`.
// '/api': {
// target: 'http://localhost:3000',
// changeOrigin: true,
// },
// },
},
module: {
rules: [
{
test: /\.m?jsx?/,
include: path.resolve(__dirname, 'src/'),
use: ['babel-loader'],
},
{
// For production, we output a separately cachable stylesheet.
test: /\.css$/,
use: [
// Uses style-loader in development to enable hot style replacement (HMR).
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
// Remove or comment out the `modules` property (or set it to `false`) to disable css-modules.
{
loader: 'css-loader',
options: { importLoaders: 1, modules: 'local' },
},
'postcss-loader',
],
},
{
// Any file types which you want to add loaders for should be added to this
// exclusion list. Otherwise the files will be turned into static links.
exclude: [
/\.html$/,
/\.(m?js|jsx)$/,
/\.scss$/,
/\.css$/,
/\.json$/,
/\.bmp$/,
/\.gif$/,
/\.jpe?g$/,
/\.png$/,
],
loader: 'file-loader',
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
// "url" loader works just like "file" loader but it also embeds
// assets smaller than specified size as data URLs to avoid requests.
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]',
},
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name]-[contenthash].css',
chunkFilename: '[id]-[contenthash].css',
}),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
template: 'src/index.html',
}),
new ManifestPlugin({
writeToFileEmit: true,
}),
],
};
};