forked from fuzetsu/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.base.config.js
More file actions
184 lines (172 loc) · 4.58 KB
/
Copy pathwebpack.base.config.js
File metadata and controls
184 lines (172 loc) · 4.58 KB
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
const path = require("path")
var { merge } = require("webpack-merge")
var rulesConfig = require("./webpack.common.rules.js")
// const chalk = require("chalk")
// const ProgressBarPlugin = require("progress-bar-webpack-plugin")
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
const { entries } = require("./webpack.common.entries.js")
let terserPlugin = compiler => {
const TerserPlugin = require("terser-webpack-plugin")
new TerserPlugin({
parallel: true,
test: /\.(js|es6|cjs|mjs)(\?.*)?$/i,
extractComments: false,
terserOptions: {
warnings: false,
parse: {},
compress: false,
// compress: {},
mangle: false, // Note `mangle.properties` is `false` by default.
output: {
comments: false,
beautify: true,
inline_script: false,
},
toplevel: false,
nameCache: null,
ie8: false,
keep_fnames: true,
keep_classnames: true,
// drop_debugger: true,
},
}).apply(compiler)
}
let cssMinimizer = compiler => {
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
let opt = {
preset: [
"advanced",
{
//
cssDeclarationSorter: true,
calc: true,
colormin: true,
convertValues: true,
discardComments: { removeAll: true },
discardDuplicates: { removeAll: true },
discardEmpty: true,
discardOverridden: true,
discardUnused: true,
mergeIdents: true,
mergeLonghand: true,
mergeRules: true,
minifyFontValues: true,
minifyGradients: true,
minifyParams: true,
minifySelectors: true,
normalizeCharset: true,
normalizeDisplayValues: true,
normalizePositions: true,
normalizeRepeatStyle: true,
normalizeString: true,
normalizeTimingFunctions: true,
normalizeUnicode: true,
normalizeUrl: true,
normalizeWhitespace: true,
orderedValues: true,
reduceIdents: true,
reduceInitial: true,
reduceTransforms: true,
svgo: true,
uniqueSelectors: true,
zindex: true,
},
],
}
new CssMinimizerPlugin({
parallel: true,
test: /\.(sa|sc|le|c)ss$/i,
minimizerOptions: [opt, opt, opt, opt],
minify: [
CssMinimizerPlugin.cssnanoMinify, //
CssMinimizerPlugin.cleanCssMinify, //
CssMinimizerPlugin.cssoMinify, //
CssMinimizerPlugin.esbuildMinify,
],
}).apply(compiler)
}
module.exports = merge(rulesConfig, {
cache: {
type: "filesystem", // 使用文件缓存
},
mode: "production", //env.NODE_ENV === 'development' ? 'development' : 'production',
optimization: {
realContentHash: true,
removeAvailableModules: true,
// removeEmptyChunks: true,
emitOnErrors: true,
minimize: false,
minimizer: [
"...",
compiler => {
terserPlugin(compiler)
cssMinimizer(compiler)
},
],
usedExports: "global",
//removeEmptyChunks: true
},
entry: entries,
// watch: true,
stats: "normal",
// 'errors-only' none Only output when errors happen
// 'errors-warnings' none Only output errors and warnings happen
// 'minimal' none Only output when errors or new compilation happen
// 'none' false Output nothing
// 'normal' true Standard output
// 'verbose' none Output everything
// 'detailed' none Output everything except chunkModules and chunkRootModules
// 'summary' none Output webpack version, warnings count and errors
output: {
path: path.join(__dirname, "dist"),
publicPath: "/dist/",
filename: "[name].js",
// clean: true,
chunkFilename: "[name].js",
},
externals: {
jquery: "$",
// vue: "Vue",
axios: "axios",
"axios-userscript-adapter": "axiosGmxhrAdapter",
},
resolve: {
modules: [path.resolve(__dirname, "libs"), path.resolve(__dirname, "node_modules")],
extensions: [".es6", ".mjs", ".cjs", ".js", ".css", ".json", ".wasm"],
alias: {
// libs$: path.resolve('libs') // 直接引用src源码
},
},
target: "web",
devServer: {
devMiddleware: {
index: true,
mimeTypes: { "text/html": ["html"] },
publicPath: "/",
serverSideRender: true,
// writeToDisk: true,
},
bonjour: true,
compress: true,
allowedHosts: "all",
static: {
directory: path.join(__dirname, "dist"),
},
// watchFiles: {
// paths: ["dist/*.js", "public/**/*"],
// options: {
// usePolling: false,
// },
// },
// port: 8080,
webSocketServer: false,
},
plugins: [
// 进度条
// new ProgressBarPlugin({
// format: ` :msg [:bar] ${chalk.green.bold(":percent")} (:elapsed s)`,
// }),
// new BundleAnalyzerPlugin(),
],
devtool: "source-map",
})