-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.dvm.prod.conf.js
118 lines (106 loc) · 3.3 KB
/
webpack.dvm.prod.conf.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
/**
* @file Webpack prod config for DaVanMonet
*
*/
const path = require("path");
const utils = require("../utils/utils");
const webpack = require("webpack");
const buildSettings = require("../build-settings");
const { merge } = require("webpack-merge");
const baseWebpackConfig = require("./webpack.dvm.base.conf");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const HookPlugin = require("../plugins/hook-plugin");
const dvmConfig = require("../utils/load-config").dvmConfig();
var env =
process.env.NODE_ENV === "testing"
? require("../env/test.env")
: buildSettings.build.env;
var webpackConfig = merge(baseWebpackConfig, {
mode: "production",
devtool: buildSettings.build.productionSourceMap ? "source-map" : false,
output: {
path: buildSettings.build.assetsRoot,
filename: path.posix.join(
dvmConfig.directories.js_subDir,
"[name].[chunkhash].js"
),
chunkFilename: path.posix.join(
dvmConfig.directories.js_subDir,
"[id].[chunkhash].js"
)
},
optimization: {
usedExports: true,
minimizer: [
`...`,
new CssMinimizerPlugin()
]
},
plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({
"process.env": env
}),
// extract css into its own file
new MiniCssExtractPlugin({
filename: path.posix.join(
dvmConfig.directories.css_subDir,
"[name].[contenthash].css"
)
}),
// generate dist index.html with correct asset hash for caching.
// you can customize output by editing /index.html
// see https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename:
process.env.NODE_ENV === "testing"
? "index.html"
: buildSettings.build.index,
template: path.resolve(__dirname, "../../dvm-app/index.html"),
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
// more options:
// https://github.com/kangax/html-minifier#options-quick-reference
}
}),
// copy custom static assets
new CopyWebpackPlugin({
patterns:[
{
from: path.resolve(__dirname, "../../dvm-app/static"),
to: buildSettings.build.assetsSubDirectory
}
]
}),
new HookPlugin({
emit: require("../utils/copyutils").copyAdditionalWebResources
})
]
});
if (buildSettings.build.productionGzip) {
var CompressionWebpackPlugin = require("compression-webpack-plugin");
webpackConfig.plugins.push(
new CompressionWebpackPlugin({
asset: "[path].gz[query]",
algorithm: "gzip",
test: new RegExp(
"\\.(" + buildSettings.build.productionGzipExtensions.join("|") + ")$"
),
threshold: 10240,
minRatio: 0.8
})
);
}
if (buildSettings.build.bundleAnalyzerReport) {
var BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
webpackConfig.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = webpackConfig;