Skip to content

Commit eb2c3c3

Browse files
committed
refactor webpack
1 parent eeb5ac9 commit eb2c3c3

File tree

1 file changed

+62
-70
lines changed

1 file changed

+62
-70
lines changed

webpack.config.js

Lines changed: 62 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -39,75 +39,6 @@ const filterCssImport = (url, ...args) => {
3939
return true;
4040
};
4141

42-
const plugins = [
43-
new VueLoaderPlugin(),
44-
// avoid generating useless js output files for css--only chunks
45-
new FixStyleOnlyEntriesPlugin({
46-
extensions: ['less', 'scss', 'css'],
47-
silent: true,
48-
}),
49-
new MiniCssExtractPlugin({
50-
filename: 'css/[name].css',
51-
chunkFilename: 'css/[name].css',
52-
}),
53-
new SourceMapDevToolPlugin({
54-
filename: '[file].map',
55-
include: [
56-
'js/index.js',
57-
'css/index.css',
58-
],
59-
}),
60-
new MonacoWebpackPlugin({
61-
filename: 'js/monaco-[name].worker.js',
62-
}),
63-
new LicenseWebpackPlugin({
64-
outputFilename: 'js/licenses.txt',
65-
perChunkOutput: false,
66-
addBanner: false,
67-
skipChildCompilers: true,
68-
modulesDirectories: [
69-
resolve(__dirname, 'node_modules'),
70-
],
71-
renderLicenses: (modules) => {
72-
const line = '-'.repeat(80);
73-
return modules.map((module) => {
74-
const {name, version} = module.packageJson;
75-
const {licenseId, licenseText} = module;
76-
const body = wrapAnsi(licenseText || '', 80);
77-
return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
78-
}).join('\n');
79-
},
80-
stats: {
81-
warnings: false,
82-
errors: true,
83-
},
84-
}),
85-
];
86-
87-
if (isProduction) {
88-
plugins.push(
89-
new CompressionPlugin({
90-
filename: '[path].gz',
91-
algorithm: 'gzip',
92-
test: /\.(js|css)$/,
93-
compressionOptions: {
94-
level: constants.Z_BEST_COMPRESSION,
95-
},
96-
threshold: 10240,
97-
}),
98-
new CompressionPlugin({
99-
filename: '[path].br',
100-
algorithm: 'brotliCompress',
101-
test: /\.(js|css)$/,
102-
compressionOptions: {
103-
[constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,
104-
},
105-
threshold: 10240,
106-
}),
107-
);
108-
}
109-
110-
11142
module.exports = {
11243
mode: isProduction ? 'production' : 'development',
11344
entry: {
@@ -326,7 +257,68 @@ module.exports = {
326257
},
327258
],
328259
},
329-
plugins,
260+
plugins: [
261+
new VueLoaderPlugin(),
262+
// avoid generating useless js output files for css--only chunks
263+
new FixStyleOnlyEntriesPlugin({
264+
extensions: ['less', 'scss', 'css'],
265+
silent: true,
266+
}),
267+
new MiniCssExtractPlugin({
268+
filename: 'css/[name].css',
269+
chunkFilename: 'css/[name].css',
270+
}),
271+
new SourceMapDevToolPlugin({
272+
filename: '[file].map',
273+
include: [
274+
'js/index.js',
275+
'css/index.css',
276+
],
277+
}),
278+
new MonacoWebpackPlugin({
279+
filename: 'js/monaco-[name].worker.js',
280+
}),
281+
new LicenseWebpackPlugin({
282+
outputFilename: 'js/licenses.txt',
283+
perChunkOutput: false,
284+
addBanner: false,
285+
skipChildCompilers: true,
286+
modulesDirectories: [
287+
resolve(__dirname, 'node_modules'),
288+
],
289+
renderLicenses: (modules) => {
290+
const line = '-'.repeat(80);
291+
return modules.map((module) => {
292+
const {name, version} = module.packageJson;
293+
const {licenseId, licenseText} = module;
294+
const body = wrapAnsi(licenseText || '', 80);
295+
return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
296+
}).join('\n');
297+
},
298+
stats: {
299+
warnings: false,
300+
errors: true,
301+
},
302+
}),
303+
isProduction && new CompressionPlugin({
304+
filename: '[path].gz',
305+
algorithm: 'gzip',
306+
test: /\.(js|css)$/,
307+
compressionOptions: {
308+
level: constants.Z_BEST_COMPRESSION,
309+
},
310+
threshold: 10240,
311+
}),
312+
isProduction && new CompressionPlugin({
313+
filename: '[path].br',
314+
algorithm: 'brotliCompress',
315+
test: /\.(js|css)$/,
316+
compressionOptions: {
317+
[constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,
318+
},
319+
threshold: 10240,
320+
}),
321+
].filter((plugin) => !!plugin),
330322
performance: {
331323
hints: false,
332324
maxEntrypointSize: Infinity,

0 commit comments

Comments
 (0)