-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
87 lines (77 loc) · 2.38 KB
/
webpack.prod.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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const paths = {
// Source files
src: path.resolve(__dirname, "./src"),
// Production build files
build: path.resolve(__dirname, "./dist"),
// Static files that get copied to build folder
public: path.resolve(__dirname, "./public"),
};
module.exports = {
// Where webpack looks to start building the bundle
entry: [paths.src + "/index.js"],
mode: "production",
devtool: false,
output: {
path: paths.build,
publicPath: "/",
filename: "js/[name].[contenthash].bundle.js",
},
module: {
rules: [
{
test: /\.(scss|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
importLoaders: 2,
sourceMap: false,
},
},
"postcss-loader",
"sass-loader",
],
},
// JavaScript: Use Babel to transpile JavaScript files
{ test: /\.js$/, exclude: /node_modules/, use: ["babel-loader"] },
// Images: Copy image files to build folder
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type: "asset/resource",
},
// Fonts and SVGs: Inline files
{ test: /\.(woff(2)?|eot|ttf|otf|svg|)$/, type: "asset/inline" },
],
},
plugins: [
// Removes/cleans build folders and unused assets when rebuilding
new CleanWebpackPlugin(),
// Extracts CSS into separate files
// Note: style-loader is for development, MiniCssExtractPlugin is for production
new MiniCssExtractPlugin({
filename: "styles/[name].[contenthash].css",
chunkFilename: "[id].css",
}),
],
optimization: {
minimize: true,
minimizer: [new CssMinimizerPlugin(), "..."],
// Once your build outputs multiple chunks, this option will ensure they share the webpack runtime
// instead of having their own. This also helps with long-term caching, since the chunks will only
// change when actual code changes, not the webpack runtime.
runtimeChunk: {
name: "runtime",
},
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};