@umijs/bundler-webpack 4.0.88 → 4.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
- package/compiled/css-minimizer-webpack-plugin/minify.js +4 -17
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +141 -87
- package/dist/config/compressPlugin.js +1 -1
- package/package.json +7 -7
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
|
|
4
|
-
|
|
5
|
-
/** @typedef {import("source-map").RawSourceMap} RawSourceMap */
|
|
6
|
-
|
|
7
4
|
/** @typedef {import("./index.js").InternalResult} InternalResult */
|
|
8
5
|
|
|
9
6
|
/**
|
|
@@ -13,15 +10,14 @@
|
|
|
13
10
|
*/
|
|
14
11
|
const minify = async options => {
|
|
15
12
|
const minifyFns = Array.isArray(options.minimizer.implementation) ? options.minimizer.implementation : [options.minimizer.implementation];
|
|
16
|
-
/** @type {InternalResult} */
|
|
17
13
|
|
|
14
|
+
/** @type {InternalResult} */
|
|
18
15
|
const result = {
|
|
19
16
|
outputs: [],
|
|
20
17
|
warnings: [],
|
|
21
18
|
errors: []
|
|
22
19
|
};
|
|
23
20
|
let needSourceMap = false;
|
|
24
|
-
|
|
25
21
|
for (let i = 0; i <= minifyFns.length - 1; i++) {
|
|
26
22
|
const minifyFn = minifyFns[i];
|
|
27
23
|
const minifyOptions = Array.isArray(options.minimizer.options) ? options.minimizer.options[i] : options.minimizer.options;
|
|
@@ -32,46 +28,38 @@ const minify = async options => {
|
|
|
32
28
|
const {
|
|
33
29
|
code,
|
|
34
30
|
map
|
|
35
|
-
} = prevResult;
|
|
36
|
-
|
|
31
|
+
} = prevResult;
|
|
32
|
+
// eslint-disable-next-line no-await-in-loop
|
|
37
33
|
const minifyResult = await minifyFn({
|
|
38
34
|
[options.name]: code
|
|
39
35
|
}, map, minifyOptions);
|
|
40
|
-
|
|
41
36
|
if (typeof minifyResult.code !== "string") {
|
|
42
37
|
throw new Error("minimizer function doesn't return the 'code' property or result is not a string value");
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
if (minifyResult.map) {
|
|
46
40
|
needSourceMap = true;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
if (minifyResult.errors) {
|
|
50
43
|
result.errors = result.errors.concat(minifyResult.errors);
|
|
51
44
|
}
|
|
52
|
-
|
|
53
45
|
if (minifyResult.warnings) {
|
|
54
46
|
result.warnings = result.warnings.concat(minifyResult.warnings);
|
|
55
47
|
}
|
|
56
|
-
|
|
57
48
|
result.outputs.push({
|
|
58
49
|
code: minifyResult.code,
|
|
59
50
|
map: minifyResult.map
|
|
60
51
|
});
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
if (!needSourceMap) {
|
|
64
54
|
result.outputs = [result.outputs[result.outputs.length - 1]];
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
return result;
|
|
68
57
|
};
|
|
58
|
+
|
|
69
59
|
/**
|
|
70
60
|
* @param {string} options
|
|
71
61
|
* @returns {Promise<InternalResult>}
|
|
72
62
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
63
|
async function transform(options) {
|
|
76
64
|
// 'use strict' => this === undefined (Clean Scope)
|
|
77
65
|
// Safer for possible security issues, albeit not critical at all here
|
|
@@ -79,7 +67,6 @@ async function transform(options) {
|
|
|
79
67
|
const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
|
80
68
|
return minify(evaluatedOptions);
|
|
81
69
|
}
|
|
82
|
-
|
|
83
70
|
module.exports = {
|
|
84
71
|
minify,
|
|
85
72
|
transform
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
|
|
1
|
+
{"name":"css-minimizer-webpack-plugin","version":"5.0.1","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
|
|
@@ -1,83 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/** @typedef {import("./index.js").Input} Input */
|
|
4
|
-
|
|
5
|
-
/** @typedef {import("source-map").RawSourceMap} RawSourceMap */
|
|
6
|
-
|
|
7
|
-
/** @typedef {import("source-map").SourceMapGenerator} SourceMapGenerator */
|
|
8
|
-
|
|
4
|
+
/** @typedef {import("@jridgewell/trace-mapping").EncodedSourceMap} RawSourceMap */
|
|
9
5
|
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
|
|
10
|
-
|
|
11
6
|
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
|
|
12
|
-
|
|
13
7
|
/** @typedef {import("postcss").ProcessOptions} ProcessOptions */
|
|
14
|
-
|
|
15
8
|
/** @typedef {import("postcss").Postcss} Postcss */
|
|
9
|
+
|
|
16
10
|
const notSettled = Symbol(`not-settled`);
|
|
11
|
+
|
|
17
12
|
/**
|
|
18
13
|
* @template T
|
|
19
14
|
* @typedef {() => Promise<T>} Task
|
|
20
15
|
*/
|
|
21
16
|
|
|
22
17
|
/**
|
|
23
|
-
* Run tasks with limited
|
|
18
|
+
* Run tasks with limited concurrency.
|
|
24
19
|
* @template T
|
|
25
20
|
* @param {number} limit - Limit of tasks that run at once.
|
|
26
21
|
* @param {Task<T>[]} tasks - List of tasks to run.
|
|
27
22
|
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
|
|
28
23
|
*/
|
|
29
|
-
|
|
30
24
|
function throttleAll(limit, tasks) {
|
|
31
25
|
if (!Number.isInteger(limit) || limit < 1) {
|
|
32
26
|
throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
|
|
36
29
|
throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
|
|
37
30
|
}
|
|
38
|
-
|
|
39
31
|
return new Promise((resolve, reject) => {
|
|
40
32
|
const result = Array(tasks.length).fill(notSettled);
|
|
41
33
|
const entries = tasks.entries();
|
|
42
|
-
|
|
43
34
|
const next = () => {
|
|
44
35
|
const {
|
|
45
36
|
done,
|
|
46
37
|
value
|
|
47
38
|
} = entries.next();
|
|
48
|
-
|
|
49
39
|
if (done) {
|
|
50
40
|
const isLast = !result.includes(notSettled);
|
|
51
41
|
if (isLast) resolve(result);
|
|
52
42
|
return;
|
|
53
43
|
}
|
|
54
|
-
|
|
55
44
|
const [index, task] = value;
|
|
45
|
+
|
|
56
46
|
/**
|
|
57
47
|
* @param {T} x
|
|
58
48
|
*/
|
|
59
|
-
|
|
60
49
|
const onFulfilled = x => {
|
|
61
50
|
result[index] = x;
|
|
62
51
|
next();
|
|
63
52
|
};
|
|
64
|
-
|
|
65
53
|
task().then(onFulfilled, reject);
|
|
66
54
|
};
|
|
67
|
-
|
|
68
55
|
Array(limit).fill(0).forEach(next);
|
|
69
56
|
});
|
|
70
57
|
}
|
|
71
|
-
/* istanbul ignore next */
|
|
72
58
|
|
|
59
|
+
/* istanbul ignore next */
|
|
73
60
|
/**
|
|
74
61
|
* @param {Input} input
|
|
75
62
|
* @param {RawSourceMap | undefined} sourceMap
|
|
76
63
|
* @param {CustomOptions} minimizerOptions
|
|
77
64
|
* @return {Promise<MinimizedResult>}
|
|
78
65
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
66
|
async function cssnanoMinify(input, sourceMap, minimizerOptions = {
|
|
82
67
|
preset: "default"
|
|
83
68
|
}) {
|
|
@@ -88,109 +73,91 @@ async function cssnanoMinify(input, sourceMap, minimizerOptions = {
|
|
|
88
73
|
*/
|
|
89
74
|
const load = async module => {
|
|
90
75
|
let exports;
|
|
91
|
-
|
|
92
76
|
try {
|
|
93
77
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
94
78
|
exports = require(module);
|
|
95
79
|
return exports;
|
|
96
80
|
} catch (requireError) {
|
|
97
81
|
let importESM;
|
|
98
|
-
|
|
99
82
|
try {
|
|
100
83
|
// eslint-disable-next-line no-new-func
|
|
101
84
|
importESM = new Function("id", "return import(id);");
|
|
102
85
|
} catch (e) {
|
|
103
86
|
importESM = null;
|
|
104
87
|
}
|
|
105
|
-
|
|
106
|
-
if (
|
|
107
|
-
/** @type {Error & {code: string}} */
|
|
88
|
+
if ( /** @type {Error & {code: string}} */
|
|
108
89
|
requireError.code === "ERR_REQUIRE_ESM" && importESM) {
|
|
109
90
|
exports = await importESM(module);
|
|
110
91
|
return exports.default;
|
|
111
92
|
}
|
|
112
|
-
|
|
113
93
|
throw requireError;
|
|
114
94
|
}
|
|
115
95
|
};
|
|
116
|
-
|
|
117
96
|
const [[name, code]] = Object.entries(input);
|
|
118
97
|
/** @type {ProcessOptions} */
|
|
119
|
-
|
|
120
98
|
const postcssOptions = {
|
|
121
99
|
from: name,
|
|
122
100
|
...minimizerOptions.processorOptions
|
|
123
101
|
};
|
|
124
|
-
|
|
125
102
|
if (typeof postcssOptions.parser === "string") {
|
|
126
103
|
try {
|
|
127
104
|
postcssOptions.parser = await load(postcssOptions.parser);
|
|
128
105
|
} catch (error) {
|
|
129
106
|
throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${
|
|
130
|
-
/** @type {Error} */
|
|
131
|
-
error.message}\n\n(@${name})`);
|
|
107
|
+
/** @type {Error} */error.message}\n\n(@${name})`);
|
|
132
108
|
}
|
|
133
109
|
}
|
|
134
|
-
|
|
135
110
|
if (typeof postcssOptions.stringifier === "string") {
|
|
136
111
|
try {
|
|
137
112
|
postcssOptions.stringifier = await load(postcssOptions.stringifier);
|
|
138
113
|
} catch (error) {
|
|
139
114
|
throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${
|
|
140
|
-
/** @type {Error} */
|
|
141
|
-
error.message}\n\n(@${name})`);
|
|
115
|
+
/** @type {Error} */error.message}\n\n(@${name})`);
|
|
142
116
|
}
|
|
143
117
|
}
|
|
144
|
-
|
|
145
118
|
if (typeof postcssOptions.syntax === "string") {
|
|
146
119
|
try {
|
|
147
120
|
postcssOptions.syntax = await load(postcssOptions.syntax);
|
|
148
121
|
} catch (error) {
|
|
149
122
|
throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${
|
|
150
|
-
/** @type {Error} */
|
|
151
|
-
error.message}\n\n(@${name})`);
|
|
123
|
+
/** @type {Error} */error.message}\n\n(@${name})`);
|
|
152
124
|
}
|
|
153
125
|
}
|
|
154
|
-
|
|
155
126
|
if (sourceMap) {
|
|
156
127
|
postcssOptions.map = {
|
|
157
128
|
annotation: false
|
|
158
129
|
};
|
|
159
130
|
}
|
|
131
|
+
|
|
160
132
|
/** @type {Postcss} */
|
|
161
133
|
// eslint-disable-next-line global-require
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const postcss = require('postcss').default; // @ts-ignore
|
|
134
|
+
const postcss = require('postcss').default;
|
|
135
|
+
// @ts-ignore
|
|
165
136
|
// eslint-disable-next-line global-require
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const cssnano = require('@umijs/bundler-webpack/compiled/cssnano'); // @ts-ignore
|
|
137
|
+
const cssnano = require('@umijs/bundler-webpack/compiled/cssnano');
|
|
138
|
+
// @ts-ignore
|
|
169
139
|
// Types are broken
|
|
170
|
-
|
|
171
|
-
|
|
172
140
|
const result = await postcss([cssnano(minimizerOptions)]).process(code, postcssOptions);
|
|
173
141
|
return {
|
|
174
142
|
code: result.css,
|
|
175
|
-
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
map: result.map ? result.map.toJSON() :
|
|
145
|
+
// eslint-disable-next-line no-undefined
|
|
176
146
|
undefined,
|
|
177
147
|
warnings: result.warnings().map(String)
|
|
178
148
|
};
|
|
179
149
|
}
|
|
180
|
-
/* istanbul ignore next */
|
|
181
150
|
|
|
151
|
+
/* istanbul ignore next */
|
|
182
152
|
/**
|
|
183
153
|
* @param {Input} input
|
|
184
154
|
* @param {RawSourceMap | undefined} sourceMap
|
|
185
155
|
* @param {CustomOptions} minimizerOptions
|
|
186
156
|
* @return {Promise<MinimizedResult>}
|
|
187
157
|
*/
|
|
188
|
-
|
|
189
|
-
|
|
190
158
|
async function cssoMinify(input, sourceMap, minimizerOptions) {
|
|
191
159
|
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
|
|
192
160
|
const csso = require("csso");
|
|
193
|
-
|
|
194
161
|
const [[filename, code]] = Object.entries(input);
|
|
195
162
|
const result = csso.minify(code, {
|
|
196
163
|
filename,
|
|
@@ -199,26 +166,23 @@ async function cssoMinify(input, sourceMap, minimizerOptions) {
|
|
|
199
166
|
});
|
|
200
167
|
return {
|
|
201
168
|
code: result.css,
|
|
202
|
-
map: result.map ?
|
|
203
|
-
|
|
204
|
-
|
|
169
|
+
map: result.map ? /** @type {any & { toJSON(): RawSourceMap }} */
|
|
170
|
+
result.map.toJSON() :
|
|
171
|
+
// eslint-disable-next-line no-undefined
|
|
205
172
|
undefined
|
|
206
173
|
};
|
|
207
174
|
}
|
|
208
|
-
/* istanbul ignore next */
|
|
209
175
|
|
|
176
|
+
/* istanbul ignore next */
|
|
210
177
|
/**
|
|
211
178
|
* @param {Input} input
|
|
212
179
|
* @param {RawSourceMap | undefined} sourceMap
|
|
213
180
|
* @param {CustomOptions} minimizerOptions
|
|
214
181
|
* @return {Promise<MinimizedResult>}
|
|
215
182
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
183
|
async function cleanCssMinify(input, sourceMap, minimizerOptions) {
|
|
219
184
|
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
|
|
220
185
|
const CleanCSS = require("clean-css");
|
|
221
|
-
|
|
222
186
|
const [[name, code]] = Object.entries(input);
|
|
223
187
|
const result = await new CleanCSS({
|
|
224
188
|
sourceMap: Boolean(sourceMap),
|
|
@@ -229,10 +193,10 @@ async function cleanCssMinify(input, sourceMap, minimizerOptions) {
|
|
|
229
193
|
styles: code
|
|
230
194
|
}
|
|
231
195
|
});
|
|
232
|
-
const generatedSourceMap = result.sourceMap &&
|
|
233
|
-
|
|
234
|
-
result.sourceMap.toJSON(); // workaround for source maps on windows
|
|
196
|
+
const generatedSourceMap = result.sourceMap && /** @type {any & { toJSON(): RawSourceMap }} */
|
|
197
|
+
result.sourceMap.toJSON();
|
|
235
198
|
|
|
199
|
+
// workaround for source maps on windows
|
|
236
200
|
if (generatedSourceMap) {
|
|
237
201
|
// eslint-disable-next-line global-require
|
|
238
202
|
const isWindowsPathSep = require("path").sep === "\\";
|
|
@@ -243,23 +207,20 @@ async function cleanCssMinify(input, sourceMap, minimizerOptions) {
|
|
|
243
207
|
*/
|
|
244
208
|
item => isWindowsPathSep ? item.replace(/\\/g, "/") : item);
|
|
245
209
|
}
|
|
246
|
-
|
|
247
210
|
return {
|
|
248
211
|
code: result.styles,
|
|
249
212
|
map: generatedSourceMap,
|
|
250
213
|
warnings: result.warnings
|
|
251
214
|
};
|
|
252
215
|
}
|
|
253
|
-
/* istanbul ignore next */
|
|
254
216
|
|
|
217
|
+
/* istanbul ignore next */
|
|
255
218
|
/**
|
|
256
219
|
* @param {Input} input
|
|
257
220
|
* @param {RawSourceMap | undefined} sourceMap
|
|
258
221
|
* @param {CustomOptions} minimizerOptions
|
|
259
222
|
* @return {Promise<MinimizedResult>}
|
|
260
223
|
*/
|
|
261
|
-
|
|
262
|
-
|
|
263
224
|
async function esbuildMinify(input, sourceMap, minimizerOptions) {
|
|
264
225
|
/**
|
|
265
226
|
* @param {import("esbuild").TransformOptions} [esbuildOptions={}]
|
|
@@ -274,19 +235,19 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
|
|
|
274
235
|
...esbuildOptions,
|
|
275
236
|
sourcemap: false
|
|
276
237
|
};
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const esbuild = require('@umijs/bundler-utils/compiled/esbuild'); // Copy `esbuild` options
|
|
238
|
+
};
|
|
281
239
|
|
|
240
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
241
|
+
const esbuild = require('@umijs/bundler-utils/compiled/esbuild');
|
|
282
242
|
|
|
283
|
-
|
|
243
|
+
// Copy `esbuild` options
|
|
244
|
+
const esbuildOptions = buildEsbuildOptions(minimizerOptions);
|
|
284
245
|
|
|
246
|
+
// Let `esbuild` generate a SourceMap
|
|
285
247
|
if (sourceMap) {
|
|
286
248
|
esbuildOptions.sourcemap = true;
|
|
287
249
|
esbuildOptions.sourcesContent = false;
|
|
288
250
|
}
|
|
289
|
-
|
|
290
251
|
const [[filename, code]] = Object.entries(input);
|
|
291
252
|
esbuildOptions.sourcefile = filename;
|
|
292
253
|
const result = await esbuild.transform(code, esbuildOptions);
|
|
@@ -297,33 +258,33 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
|
|
|
297
258
|
warnings: result.warnings.length > 0 ? result.warnings.map(item => {
|
|
298
259
|
return {
|
|
299
260
|
source: item.location && item.location.file,
|
|
261
|
+
line: item.location && item.location.line ? item.location.line :
|
|
300
262
|
// eslint-disable-next-line no-undefined
|
|
301
|
-
|
|
263
|
+
undefined,
|
|
264
|
+
column: item.location && item.location.column ? item.location.column :
|
|
302
265
|
// eslint-disable-next-line no-undefined
|
|
303
|
-
|
|
266
|
+
undefined,
|
|
304
267
|
plugin: item.pluginName,
|
|
305
268
|
message: `${item.text}${item.detail ? `\nDetails:\n${item.detail}` : ""}${item.notes.length > 0 ? `\n\nNotes:\n${item.notes.map(note => `${note.location ? `[${note.location.file}:${note.location.line}:${note.location.column}] ` : ""}${note.text}${note.location ? `\nSuggestion: ${note.location.suggestion}` : ""}${note.location ? `\nLine text:\n${note.location.lineText}\n` : ""}`).join("\n")}` : ""}`
|
|
306
269
|
};
|
|
307
270
|
}) : []
|
|
308
271
|
};
|
|
309
272
|
}
|
|
310
|
-
/* istanbul ignore next */
|
|
311
273
|
|
|
274
|
+
// TODO remove in the next major release
|
|
275
|
+
/* istanbul ignore next */
|
|
312
276
|
/**
|
|
313
277
|
* @param {Input} input
|
|
314
278
|
* @param {RawSourceMap | undefined} sourceMap
|
|
315
279
|
* @param {CustomOptions} minimizerOptions
|
|
316
280
|
* @return {Promise<MinimizedResult>}
|
|
317
281
|
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
282
|
async function parcelCssMinify(input, sourceMap, minimizerOptions) {
|
|
321
283
|
const [[filename, code]] = Object.entries(input);
|
|
322
284
|
/**
|
|
323
|
-
* @param {Partial<import("@parcel/css").TransformOptions
|
|
324
|
-
* @returns {import("@parcel/css").TransformOptions}
|
|
285
|
+
* @param {Partial<import("@parcel/css").TransformOptions<any>>} [parcelCssOptions={}]
|
|
286
|
+
* @returns {import("@parcel/css").TransformOptions<any>}
|
|
325
287
|
*/
|
|
326
|
-
|
|
327
288
|
const buildParcelCssOptions = (parcelCssOptions = {}) => {
|
|
328
289
|
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
|
|
329
290
|
return {
|
|
@@ -333,18 +294,18 @@ async function parcelCssMinify(input, sourceMap, minimizerOptions) {
|
|
|
333
294
|
filename,
|
|
334
295
|
code: Buffer.from(code)
|
|
335
296
|
};
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const parcelCss = require("@parcel/css"); // Copy `esbuild` options
|
|
297
|
+
};
|
|
340
298
|
|
|
299
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
300
|
+
const parcelCss = require("@parcel/css");
|
|
341
301
|
|
|
342
|
-
|
|
302
|
+
// Copy `parcel-css` options
|
|
303
|
+
const parcelCssOptions = buildParcelCssOptions(minimizerOptions);
|
|
343
304
|
|
|
305
|
+
// Let `esbuild` generate a SourceMap
|
|
344
306
|
if (sourceMap) {
|
|
345
307
|
parcelCssOptions.sourceMap = true;
|
|
346
308
|
}
|
|
347
|
-
|
|
348
309
|
const result = await parcelCss.transform(parcelCssOptions);
|
|
349
310
|
return {
|
|
350
311
|
code: result.code.toString(),
|
|
@@ -353,11 +314,104 @@ async function parcelCssMinify(input, sourceMap, minimizerOptions) {
|
|
|
353
314
|
};
|
|
354
315
|
}
|
|
355
316
|
|
|
317
|
+
/* istanbul ignore next */
|
|
318
|
+
/**
|
|
319
|
+
* @param {Input} input
|
|
320
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
321
|
+
* @param {CustomOptions} minimizerOptions
|
|
322
|
+
* @return {Promise<MinimizedResult>}
|
|
323
|
+
*/
|
|
324
|
+
async function lightningCssMinify(input, sourceMap, minimizerOptions) {
|
|
325
|
+
const [[filename, code]] = Object.entries(input);
|
|
326
|
+
/**
|
|
327
|
+
* @param {Partial<import("lightningcss").TransformOptions<any>>} [lightningCssOptions={}]
|
|
328
|
+
* @returns {import("lightningcss").TransformOptions<any>}
|
|
329
|
+
*/
|
|
330
|
+
const buildLightningCssOptions = (lightningCssOptions = {}) => {
|
|
331
|
+
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
|
|
332
|
+
return {
|
|
333
|
+
minify: true,
|
|
334
|
+
...lightningCssOptions,
|
|
335
|
+
sourceMap: false,
|
|
336
|
+
filename,
|
|
337
|
+
code: Buffer.from(code)
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
342
|
+
const lightningCss = require("lightningcss");
|
|
343
|
+
|
|
344
|
+
// Copy `lightningCss` options
|
|
345
|
+
const lightningCssOptions = buildLightningCssOptions(minimizerOptions);
|
|
346
|
+
|
|
347
|
+
// Let `esbuild` generate a SourceMap
|
|
348
|
+
if (sourceMap) {
|
|
349
|
+
lightningCssOptions.sourceMap = true;
|
|
350
|
+
}
|
|
351
|
+
const result = await lightningCss.transform(lightningCssOptions);
|
|
352
|
+
return {
|
|
353
|
+
code: result.code.toString(),
|
|
354
|
+
// eslint-disable-next-line no-undefined
|
|
355
|
+
map: result.map ? JSON.parse(result.map.toString()) : undefined
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/* istanbul ignore next */
|
|
360
|
+
/**
|
|
361
|
+
* @param {Input} input
|
|
362
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
363
|
+
* @param {CustomOptions} minimizerOptions
|
|
364
|
+
* @return {Promise<MinimizedResult>}
|
|
365
|
+
*/
|
|
366
|
+
async function swcMinify(input, sourceMap, minimizerOptions) {
|
|
367
|
+
const [[filename, code]] = Object.entries(input);
|
|
368
|
+
/**
|
|
369
|
+
* @param {Partial<import("@swc/css").Options>} [swcOptions={}]
|
|
370
|
+
* @returns {import("@swc/css").Options}
|
|
371
|
+
*/
|
|
372
|
+
const buildSwcOptions = (swcOptions = {}) => {
|
|
373
|
+
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
|
|
374
|
+
return {
|
|
375
|
+
...swcOptions,
|
|
376
|
+
filename
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
381
|
+
const swc = require("@swc/css");
|
|
382
|
+
|
|
383
|
+
// Copy `swc` options
|
|
384
|
+
const swcOptions = buildSwcOptions(minimizerOptions);
|
|
385
|
+
|
|
386
|
+
// Let `swc` generate a SourceMap
|
|
387
|
+
if (sourceMap) {
|
|
388
|
+
swcOptions.sourceMap = true;
|
|
389
|
+
}
|
|
390
|
+
const result = await swc.minify(Buffer.from(code), swcOptions);
|
|
391
|
+
return {
|
|
392
|
+
code: result.code.toString(),
|
|
393
|
+
// eslint-disable-next-line no-undefined
|
|
394
|
+
map: result.map ? JSON.parse(result.map.toString()) : undefined,
|
|
395
|
+
errors: result.errors ? result.errors.map(diagnostic => {
|
|
396
|
+
const error = new Error(diagnostic.message);
|
|
397
|
+
|
|
398
|
+
// @ts-ignore
|
|
399
|
+
error.span = diagnostic.span;
|
|
400
|
+
// @ts-ignore
|
|
401
|
+
error.level = diagnostic.level;
|
|
402
|
+
return error;
|
|
403
|
+
}) :
|
|
404
|
+
// eslint-disable-next-line no-undefined
|
|
405
|
+
undefined
|
|
406
|
+
};
|
|
407
|
+
}
|
|
356
408
|
module.exports = {
|
|
357
409
|
throttleAll,
|
|
358
410
|
cssnanoMinify,
|
|
359
411
|
cssoMinify,
|
|
360
412
|
cleanCssMinify,
|
|
361
413
|
esbuildMinify,
|
|
362
|
-
parcelCssMinify
|
|
414
|
+
parcelCssMinify,
|
|
415
|
+
lightningCssMinify,
|
|
416
|
+
swcMinify
|
|
363
417
|
};
|
|
@@ -107,7 +107,7 @@ async function addCompressPlugin(opts) {
|
|
|
107
107
|
} else if (cssMinifier === import_types.CSSMinifier.cssnano) {
|
|
108
108
|
cssMinify = import_css_minimizer_webpack_plugin.default.cssnanoMinify;
|
|
109
109
|
} else if (cssMinifier === import_types.CSSMinifier.parcelCSS) {
|
|
110
|
-
cssMinify = import_css_minimizer_webpack_plugin.default.
|
|
110
|
+
cssMinify = import_css_minimizer_webpack_plugin.default.lightningCssMinify;
|
|
111
111
|
} else if (cssMinifier !== import_types.CSSMinifier.none) {
|
|
112
112
|
throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
|
|
113
113
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.90",
|
|
4
4
|
"description": "@umijs/bundler-webpack",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"es5-imcompatible-versions": "^0.1.78",
|
|
33
33
|
"fork-ts-checker-webpack-plugin": "8.0.0",
|
|
34
34
|
"jest-worker": "29.4.3",
|
|
35
|
-
"lightningcss": "1.
|
|
35
|
+
"lightningcss": "1.22.1",
|
|
36
36
|
"node-libs-browser": "2.2.1",
|
|
37
37
|
"postcss": "^8.4.21",
|
|
38
38
|
"postcss-preset-env": "7.5.0",
|
|
39
39
|
"react-error-overlay": "6.0.9",
|
|
40
40
|
"react-refresh": "0.14.0",
|
|
41
|
-
"@umijs/babel-preset-umi": "4.0.
|
|
42
|
-
"@umijs/
|
|
43
|
-
"@umijs/utils": "4.0.
|
|
44
|
-
"@umijs/
|
|
41
|
+
"@umijs/babel-preset-umi": "4.0.90",
|
|
42
|
+
"@umijs/bundler-utils": "4.0.90",
|
|
43
|
+
"@umijs/utils": "4.0.90",
|
|
44
|
+
"@umijs/mfsu": "4.0.90"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@swc/core": "1.3.67",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"compression": "1.7.4",
|
|
55
55
|
"connect-history-api-fallback": "1.6.0",
|
|
56
56
|
"copy-webpack-plugin": "10.2.4",
|
|
57
|
-
"css-minimizer-webpack-plugin": "
|
|
57
|
+
"css-minimizer-webpack-plugin": "5.0.1",
|
|
58
58
|
"cssnano": "5.1.7",
|
|
59
59
|
"file-loader": "6.2.0",
|
|
60
60
|
"less-loader": "11.1.0",
|