-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
97 lines (94 loc) · 2.66 KB
/
webpack.config.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
88
89
90
91
92
93
94
95
96
97
var path = require("path")
var webpack = require("webpack")
var HtmlWebpackPlugin = require("html-webpack-plugin")
var HtmlWebpackInlineSourcePlugin = require("html-webpack-inline-source-plugin")
var PKG_VERSION = require("./package.json").version
// Assert this just to be safe.
// Development builds of React are slow and not intended for production.
if (process.env.NODE_ENV !== "production") {
throw new Error("Production builds must have NODE_ENV=production.")
}
module.exports = {
entry: ["./src/index"],
output: {
path: path.join(__dirname, "dist"),
filename: "bundle.js",
},
bail: true,
resolve: {
extensions: [".js", ".jsx", ".json"],
alias: {
config: path.join(__dirname, "src", "config", "production"),
},
},
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify("production"),
}),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
template: path.join(__dirname, "public", "index.html"),
inlineSource: ".(js|css)$",
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyCSS: true,
minifyURLs: true,
},
}),
new HtmlWebpackInlineSourcePlugin(),
],
module: {
rules: [
{
test: /\.js$/,
loaders: ["babel-loader"],
include: path.join(__dirname, "src"),
},
{
test: /\.css$/,
include: [
path.join(__dirname, "public"),
path.join(__dirname, "node_modules"),
],
use: ["style-loader", "css-loader"],
},
{
test: /\.(ico|jpg|png|gif|eot|otf|svg|ttf|woff|woff2)(\?.*)?$/,
exclude: /\/favicon.ico$/,
include: [
path.join(__dirname, "src"),
path.join(__dirname, "node_modules"),
],
loader: "file-loader",
query: {
name: "/files/[name].[ext]",
},
},
// A special case for favicon.ico to place it into build root directory.
{
test: /\/favicon.ico$/,
include: [path.join(__dirname, "public")],
loader: "file-loader",
query: {
name: "/favicon.ico",
},
},
// "html" loader is used to process template page (index.html) to resolve
// resources linked with <link href="./relative/path"> HTML tags.
{
test: /\.html$/,
loader: "html-loader",
query: {
attrs: ["link:href"],
},
},
],
},
}