-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
75 lines (74 loc) · 1.97 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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
mode: "production",
entry: "./src/index.js",
output: {
filename: "[name].[contenthash].js",
path: path.resolve(__dirname, "./dist"),
publicPath: "/",
},
resolve: {
extensions: [".json", ".js", ".jsx"],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
},
{
test: /\.(png|jpe?g|svg|gif)$/,
loader: "file-loader",
options: {
name: "assets/images/[name].[contenthash].[ext]",
},
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader",
options: {
name: "assets/fonts/[name].[contenthash].[ext]",
},
},
{
test: /\.(css)$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
title: "Razer Assignment",
description: "This is an assignment given by Razer Inc",
template: "./src/index.html",
}),
new MiniCssExtractPlugin({
// make css into a link url
filename: "assets/css/[name].[contenthash].css",
}),
],
optimization: {
minimizer: [
new OptimizeCssAssetsPlugin(), // Minimize CSS in production
new TerserPlugin({
cache: true,
extractComments: false,
exclude: [/\.min\.js$/gi],
parallel: true, // recommended to increase build time
sourceMap: true,
terserOptions: {
ecma: 5, // to es5
mangle: true,
compress: true,
},
}),
],
},
};