This repository has been archived by the owner on May 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack-build.config.js
196 lines (179 loc) · 5.09 KB
/
webpack-build.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const path = require("path");
const ChildProcess = require("child_process");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const Dotenv = require("dotenv-webpack");
const CompressionPlugin = require("compression-webpack-plugin");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
require("dotenv").config(); //include env file in here as well
const VERSION = ChildProcess.execSync("git rev-parse HEAD")
.toString()
.trim();
process.traceDeprecation = true; //https://github.com/webpack/loader-utils/issues/56
const context = __dirname;
module.exports = {
mode: "production",
context,
entry: [path.join(context, "src/index.jsx")],
devtool: "nosources-source-map",
output: {
path: path.join(context, "dist/"),
filename: "[name].[chunkhash].js",
publicPath: "/chainge/dist/"
},
optimization: {
splitChunks: {
chunks: "all"
},
minimize: true,
minimizer: [
new UglifyJSPlugin({
uglifyOptions: {
parallel: true,
sourceMap: true,
output: {
comments: false
},
compress: {
unsafe_comps: true,
properties: true,
keep_fargs: false,
pure_getters: true,
collapse_vars: true,
unsafe: true,
warnings: false,
sequences: true,
dead_code: true,
drop_debugger: true,
comparisons: true,
conditionals: true,
evaluate: true,
booleans: true,
loops: true,
unused: true,
hoist_funs: true,
if_return: true,
join_vars: true,
drop_console: false
},
exclude: [/\.min\.js$/gi] // skip pre-minified libs
}
})
]
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "disabled",
generateStatsFile: /*true*/ false
}),
new CleanWebpackPlugin(["dist/*.*"]),
new HtmlWebpackPlugin({
title: "Chainge",
template: "index.prod.ejs",
version: VERSION
}),
new webpack.NoEmitOnErrorsPlugin(),
new Dotenv({
path: "./.env", // Path to .env file (this is the default)
safe: true, // load .env.example (defaults to "false" which does not use dotenv-safe),
systemvars: false
}),
new MiniCssExtractPlugin({
filename: "[name].[chunkhash].css"
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new CompressionPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0
})
/*new FaviconsWebpackPlugin({
logo: "./img/logo-favicon.png",
persistentCache: true,
background: "#fff",
title: "Chainge"
})*/
],
resolve: {
modules: [
path.resolve(context, "src"),
path.resolve(context, "node_modules")
],
extensions: [".js", ".jsx", ".css", ".scss"]
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [path.resolve(context, "src")],
use: [
{
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
targets: {
browsers: ["> 1%", "last 2 major versions", "IE 10"]
}
}
],
"@babel/preset-react"
],
plugins: [
"babel-plugin-styled-components",
["@babel/plugin-proposal-class-properties", { loose: false }],
"@babel/plugin-proposal-object-rest-spread"
]
}
}
]
},
{
test: /\.css$/,
include: [
path.resolve(context, "src"),
path.resolve(context, "node_modules")
],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: { import: false, sourceMap: true, minimize: true }
},
{ loader: "postcss-loader", options: { sourceMap: true } }
]
},
{
test: /\.scss$/,
include: [
path.resolve(context, "src"),
path.resolve(context, "node_modules")
],
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: { import: false, sourceMap: true, minimize: true }
},
{ loader: "postcss-loader", options: { sourceMap: true } },
"resolve-url-loader",
{ loader: "sass-loader", options: { sourceMap: true } }
]
},
{
test: /\.(woff2?|png|jp(e*)g|svg)$/,
loader: "file-loader"
}
]
}
};