-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.js
126 lines (115 loc) · 2.73 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
let port = process.env.PORT || 8080;
let isProduction = process.env.IS_WEBPACK_PRODUCTION_MODE || false;
module.exports = {
mode: isProduction ? "production" : "development",
entry: ["react-hot-loader/patch", "./src/index.js"],
devtool: isProduction ? false : "eval",
devServer: {
static: "./build",
port: port,
hot: true, // default true since webpack v4.0.0
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new MiniCssExtractPlugin({ filename: "styles.css" }),
new CopyPlugin({
patterns: [
{
from: __dirname + "/public",
to: __dirname + "/build/public",
},
],
}),
],
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js",
publicPath: "",
clean: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [path.resolve(__dirname, "src")],
use: [
{
loader: "babel-loader", // babel-loader options are in .babelrc
},
],
},
{
test: /\.less$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "less-loader"],
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
dependency: { not: ["url"] }, // Disable asset modules feature provided by webpack 5
use: [
{
loader: "url-loader",
options: {
limit: 1,
name: "[name].[ext]",
},
},
],
type: "javascript/auto", // Disable asset modules feature provided by webpack 5
},
{
test: /\.(png|jpg)$/,
use: [
{
loader: "url-loader",
options: {
limit: 8192,
name: "images/[name].[ext]",
},
},
],
},
],
},
optimization: {
splitChunks: {
chunks: 'all',
minSize: 20000,
minRemainingSize: 0,
minChunks: 1,
maxAsyncRequests: 30,
maxInitialRequests: 30,
enforceSizeThreshold: 50000,
cacheGroups: {
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
resolve: {
extensions: ["*", ".js", ".jsx"],
fallback: {
fs: false,
http: false,
https: false,
zlib: false,
stream: false,
},
},
node: {
global: true,
},
};