@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.2
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/autoprefixer/browserslist/index.d.ts +4 -0
- package/compiled/autoprefixer/index.js +3 -3
- package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/copy-webpack-plugin/576.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
- package/compiled/cssnano/index.js +12 -11
- package/compiled/express/index.js +57 -74
- package/compiled/fork-ts-checker-webpack-plugin/index.js +14 -15
- package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
- package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
- package/compiled/http-proxy-middleware/index.js +10 -10
- package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
- package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
- package/compiled/mini-css-extract-plugin/index.js +4427 -3979
- package/compiled/mini-css-extract-plugin/loader.js +177 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +77 -23
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/terser-webpack-plugin/index.js +296 -297
- package/compiled/terser-webpack-plugin/minify.js +4 -2
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +180 -146
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +1 -3
- package/compiled/terser-webpack-plugin/utils.js +9 -12
- package/compiled/webpack/index.js +8652 -3904
- package/compiled/webpack-dev-middleware/index.js +7 -7
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/webpack-manifest-plugin/index.js +1 -1
- package/compiled/webpack-sources/index.js +1 -1
- package/compiled/ws/index.d.ts +1 -2
- package/compiled/ws/index.js +1 -1
- package/dist/build.d.ts +2 -1
- package/dist/build.js +1 -1
- package/dist/config/config.js +4 -3
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +120 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +71 -0
- package/dist/config/javaScriptRules.js +3 -6
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +7 -5
- package/dist/loader/swc.js +14 -18
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +2 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +11 -16
- package/dist/types.d.ts +9 -12
- package/dist/utils/depMatch.js +1 -1
- package/package.json +31 -31
- package/dist/esbuildHandler/autoCssModules.d.ts +0 -2
- package/dist/esbuildHandler/autoCssModules.js +0 -23
- package/dist/loader/esbuild.d.ts +0 -5
- package/dist/loader/esbuild.js +0 -53
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
|
|
4
|
+
|
|
5
|
+
/** @typedef {import("source-map").RawSourceMap} RawSourceMap */
|
|
6
|
+
|
|
7
|
+
/** @typedef {import("./index.js").InternalResult} InternalResult */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @template T
|
|
11
|
+
* @param {import("./index.js").InternalOptions<T>} options
|
|
12
|
+
* @returns {Promise<InternalResult>}
|
|
13
|
+
*/
|
|
3
14
|
const minify = async options => {
|
|
4
|
-
const minifyFns =
|
|
15
|
+
const minifyFns = Array.isArray(options.minimizer.implementation) ? options.minimizer.implementation : [options.minimizer.implementation];
|
|
16
|
+
/** @type {InternalResult} */
|
|
17
|
+
|
|
5
18
|
const result = {
|
|
6
19
|
outputs: [],
|
|
7
20
|
warnings: [],
|
|
@@ -11,7 +24,7 @@ const minify = async options => {
|
|
|
11
24
|
|
|
12
25
|
for (let i = 0; i <= minifyFns.length - 1; i++) {
|
|
13
26
|
const minifyFn = minifyFns[i];
|
|
14
|
-
const minifyOptions = Array.isArray(options.
|
|
27
|
+
const minifyOptions = Array.isArray(options.minimizer.options) ? options.minimizer.options[i] : options.minimizer.options;
|
|
15
28
|
const prevResult = result.outputs.length > 0 ? result.outputs[result.outputs.length - 1] : {
|
|
16
29
|
code: options.input,
|
|
17
30
|
map: options.inputSourceMap
|
|
@@ -53,20 +66,21 @@ const minify = async options => {
|
|
|
53
66
|
|
|
54
67
|
return result;
|
|
55
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} options
|
|
71
|
+
* @returns {Promise<InternalResult>}
|
|
72
|
+
*/
|
|
73
|
+
|
|
56
74
|
|
|
57
75
|
async function transform(options) {
|
|
58
76
|
// 'use strict' => this === undefined (Clean Scope)
|
|
59
77
|
// Safer for possible security issues, albeit not critical at all here
|
|
60
78
|
// eslint-disable-next-line no-new-func, no-param-reassign
|
|
61
79
|
const evaluatedOptions = new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (result.error) {
|
|
65
|
-
throw result.error;
|
|
66
|
-
} else {
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
80
|
+
return minify(evaluatedOptions);
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
module.exports
|
|
72
|
-
|
|
83
|
+
module.exports = {
|
|
84
|
+
minify,
|
|
85
|
+
transform
|
|
86
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT"}
|
|
1
|
+
{"name":"css-minimizer-webpack-plugin","author":"Loann Neveu","license":"MIT","types":"types/index.d.ts"}
|
|
@@ -1,17 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.cssnanoMinify = cssnanoMinify;
|
|
7
|
-
exports.cssoMinify = cssoMinify;
|
|
8
|
-
exports.cleanCssMinify = cleanCssMinify;
|
|
9
|
-
exports.esbuildMinify = esbuildMinify;
|
|
3
|
+
/** @typedef {import("./index.js").Input} Input */
|
|
10
4
|
|
|
5
|
+
/** @typedef {import("source-map").RawSourceMap} RawSourceMap */
|
|
6
|
+
|
|
7
|
+
/** @typedef {import("source-map").SourceMapGenerator} SourceMapGenerator */
|
|
8
|
+
|
|
9
|
+
/** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
|
|
10
|
+
|
|
11
|
+
/** @typedef {import("./index.js").CustomOptions} CustomOptions */
|
|
12
|
+
|
|
13
|
+
/** @typedef {import("postcss").ProcessOptions} ProcessOptions */
|
|
14
|
+
|
|
15
|
+
/** @typedef {import("postcss").Postcss} Postcss */
|
|
16
|
+
const notSettled = Symbol(`not-settled`);
|
|
17
|
+
/**
|
|
18
|
+
* @template T
|
|
19
|
+
* @typedef {() => Promise<T>} Task
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Run tasks with limited concurency.
|
|
24
|
+
* @template T
|
|
25
|
+
* @param {number} limit - Limit of tasks that run at once.
|
|
26
|
+
* @param {Task<T>[]} tasks - List of tasks to run.
|
|
27
|
+
* @returns {Promise<T[]>} A promise that fulfills to an array of the results
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
function throttleAll(limit, tasks) {
|
|
31
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
32
|
+
throw new TypeError(`Expected \`limit\` to be a finite number > 0, got \`${limit}\` (${typeof limit})`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!Array.isArray(tasks) || !tasks.every(task => typeof task === `function`)) {
|
|
36
|
+
throw new TypeError(`Expected \`tasks\` to be a list of functions returning a promise`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const result = Array(tasks.length).fill(notSettled);
|
|
41
|
+
const entries = tasks.entries();
|
|
42
|
+
|
|
43
|
+
const next = () => {
|
|
44
|
+
const {
|
|
45
|
+
done,
|
|
46
|
+
value
|
|
47
|
+
} = entries.next();
|
|
48
|
+
|
|
49
|
+
if (done) {
|
|
50
|
+
const isLast = !result.includes(notSettled);
|
|
51
|
+
if (isLast) resolve(result);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const [index, task] = value;
|
|
56
|
+
/**
|
|
57
|
+
* @param {T} x
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
const onFulfilled = x => {
|
|
61
|
+
result[index] = x;
|
|
62
|
+
next();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
task().then(onFulfilled, reject);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
Array(limit).fill(0).forEach(next);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
11
71
|
/* istanbul ignore next */
|
|
12
|
-
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {Input} input
|
|
75
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
76
|
+
* @param {CustomOptions} minimizerOptions
|
|
77
|
+
* @return {Promise<MinimizedResult>}
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
async function cssnanoMinify(input, sourceMap, minimizerOptions = {
|
|
13
82
|
preset: "default"
|
|
14
83
|
}) {
|
|
84
|
+
/**
|
|
85
|
+
* @template T
|
|
86
|
+
* @param {string} module
|
|
87
|
+
* @returns {Promise<T>}
|
|
88
|
+
*/
|
|
15
89
|
const load = async module => {
|
|
16
90
|
let exports;
|
|
17
91
|
|
|
@@ -29,7 +103,9 @@ async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
|
|
|
29
103
|
importESM = null;
|
|
30
104
|
}
|
|
31
105
|
|
|
32
|
-
if (
|
|
106
|
+
if (
|
|
107
|
+
/** @type {Error & {code: string}} */
|
|
108
|
+
requireError.code === "ERR_REQUIRE_ESM" && importESM) {
|
|
33
109
|
exports = await importESM(module);
|
|
34
110
|
return exports.default;
|
|
35
111
|
}
|
|
@@ -39,8 +115,9 @@ async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
|
|
|
39
115
|
};
|
|
40
116
|
|
|
41
117
|
const [[name, code]] = Object.entries(input);
|
|
118
|
+
/** @type {ProcessOptions} */
|
|
119
|
+
|
|
42
120
|
const postcssOptions = {
|
|
43
|
-
to: name,
|
|
44
121
|
from: name,
|
|
45
122
|
...minimizerOptions.processorOptions
|
|
46
123
|
};
|
|
@@ -49,7 +126,9 @@ async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
|
|
|
49
126
|
try {
|
|
50
127
|
postcssOptions.parser = await load(postcssOptions.parser);
|
|
51
128
|
} catch (error) {
|
|
52
|
-
throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${
|
|
129
|
+
throw new Error(`Loading PostCSS "${postcssOptions.parser}" parser failed: ${
|
|
130
|
+
/** @type {Error} */
|
|
131
|
+
error.message}\n\n(@${name})`);
|
|
53
132
|
}
|
|
54
133
|
}
|
|
55
134
|
|
|
@@ -57,7 +136,9 @@ async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
|
|
|
57
136
|
try {
|
|
58
137
|
postcssOptions.stringifier = await load(postcssOptions.stringifier);
|
|
59
138
|
} catch (error) {
|
|
60
|
-
throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${
|
|
139
|
+
throw new Error(`Loading PostCSS "${postcssOptions.stringifier}" stringifier failed: ${
|
|
140
|
+
/** @type {Error} */
|
|
141
|
+
error.message}\n\n(@${name})`);
|
|
61
142
|
}
|
|
62
143
|
}
|
|
63
144
|
|
|
@@ -65,73 +146,125 @@ async function cssnanoMinify(input, inputSourceMap, minimizerOptions = {
|
|
|
65
146
|
try {
|
|
66
147
|
postcssOptions.syntax = await load(postcssOptions.syntax);
|
|
67
148
|
} catch (error) {
|
|
68
|
-
throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${
|
|
149
|
+
throw new Error(`Loading PostCSS "${postcssOptions.syntax}" syntax failed: ${
|
|
150
|
+
/** @type {Error} */
|
|
151
|
+
error.message}\n\n(@${name})`);
|
|
69
152
|
}
|
|
70
153
|
}
|
|
71
154
|
|
|
72
|
-
if (
|
|
155
|
+
if (sourceMap) {
|
|
73
156
|
postcssOptions.map = {
|
|
74
157
|
annotation: false
|
|
75
158
|
};
|
|
76
|
-
}
|
|
159
|
+
}
|
|
160
|
+
/** @type {Postcss} */
|
|
161
|
+
// eslint-disable-next-line global-require
|
|
77
162
|
|
|
78
163
|
|
|
79
|
-
const postcss = require('postcss'); //
|
|
164
|
+
const postcss = require('postcss').default; // @ts-ignore
|
|
165
|
+
// eslint-disable-next-line global-require
|
|
80
166
|
|
|
81
167
|
|
|
82
|
-
const cssnano = require('@umijs/bundler-webpack/compiled/cssnano');
|
|
168
|
+
const cssnano = require('@umijs/bundler-webpack/compiled/cssnano'); // @ts-ignore
|
|
169
|
+
// Types are broken
|
|
170
|
+
|
|
83
171
|
|
|
84
172
|
const result = await postcss([cssnano(minimizerOptions)]).process(code, postcssOptions);
|
|
85
173
|
return {
|
|
86
174
|
code: result.css,
|
|
87
|
-
map: result.map
|
|
175
|
+
map: result.map ? result.map.toJSON() : // eslint-disable-next-line no-undefined
|
|
176
|
+
undefined,
|
|
88
177
|
warnings: result.warnings().map(String)
|
|
89
178
|
};
|
|
90
179
|
}
|
|
91
180
|
/* istanbul ignore next */
|
|
92
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @param {Input} input
|
|
184
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
185
|
+
* @param {CustomOptions} minimizerOptions
|
|
186
|
+
* @return {Promise<MinimizedResult>}
|
|
187
|
+
*/
|
|
188
|
+
|
|
93
189
|
|
|
94
|
-
async function cssoMinify(input,
|
|
190
|
+
async function cssoMinify(input, sourceMap, minimizerOptions) {
|
|
95
191
|
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
|
|
96
192
|
const csso = require("csso");
|
|
97
193
|
|
|
98
194
|
const [[filename, code]] = Object.entries(input);
|
|
99
195
|
const result = csso.minify(code, {
|
|
100
196
|
filename,
|
|
101
|
-
sourceMap: Boolean(
|
|
197
|
+
sourceMap: Boolean(sourceMap),
|
|
102
198
|
...minimizerOptions
|
|
103
199
|
});
|
|
104
200
|
return {
|
|
105
201
|
code: result.css,
|
|
106
|
-
map: result.map
|
|
202
|
+
map: result.map ?
|
|
203
|
+
/** @type {SourceMapGenerator & { toJSON(): RawSourceMap }} */
|
|
204
|
+
result.map.toJSON() : // eslint-disable-next-line no-undefined
|
|
205
|
+
undefined
|
|
107
206
|
};
|
|
108
207
|
}
|
|
109
208
|
/* istanbul ignore next */
|
|
110
209
|
|
|
210
|
+
/**
|
|
211
|
+
* @param {Input} input
|
|
212
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
213
|
+
* @param {CustomOptions} minimizerOptions
|
|
214
|
+
* @return {Promise<MinimizedResult>}
|
|
215
|
+
*/
|
|
216
|
+
|
|
111
217
|
|
|
112
|
-
async function cleanCssMinify(input,
|
|
218
|
+
async function cleanCssMinify(input, sourceMap, minimizerOptions) {
|
|
113
219
|
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
|
|
114
220
|
const CleanCSS = require("clean-css");
|
|
115
221
|
|
|
116
222
|
const [[name, code]] = Object.entries(input);
|
|
117
223
|
const result = await new CleanCSS({
|
|
118
|
-
sourceMap: Boolean(
|
|
119
|
-
...minimizerOptions
|
|
224
|
+
sourceMap: Boolean(sourceMap),
|
|
225
|
+
...minimizerOptions,
|
|
226
|
+
returnPromise: true
|
|
120
227
|
}).minify({
|
|
121
228
|
[name]: {
|
|
122
229
|
styles: code
|
|
123
230
|
}
|
|
124
231
|
});
|
|
232
|
+
const generatedSourceMap = result.sourceMap &&
|
|
233
|
+
/** @type {SourceMapGenerator & { toJSON(): RawSourceMap }} */
|
|
234
|
+
result.sourceMap.toJSON(); // workaround for source maps on windows
|
|
235
|
+
|
|
236
|
+
if (generatedSourceMap) {
|
|
237
|
+
// eslint-disable-next-line global-require
|
|
238
|
+
const isWindowsPathSep = require("path").sep === "\\";
|
|
239
|
+
generatedSourceMap.sources = generatedSourceMap.sources.map(
|
|
240
|
+
/**
|
|
241
|
+
* @param {string} item
|
|
242
|
+
* @returns {string}
|
|
243
|
+
*/
|
|
244
|
+
item => isWindowsPathSep ? item.replace(/\\/g, "/") : item);
|
|
245
|
+
}
|
|
246
|
+
|
|
125
247
|
return {
|
|
126
248
|
code: result.styles,
|
|
127
|
-
map:
|
|
249
|
+
map: generatedSourceMap,
|
|
128
250
|
warnings: result.warnings
|
|
129
251
|
};
|
|
130
252
|
}
|
|
131
253
|
/* istanbul ignore next */
|
|
132
254
|
|
|
255
|
+
/**
|
|
256
|
+
* @param {Input} input
|
|
257
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
258
|
+
* @param {CustomOptions} minimizerOptions
|
|
259
|
+
* @return {Promise<MinimizedResult>}
|
|
260
|
+
*/
|
|
261
|
+
|
|
133
262
|
|
|
134
263
|
async function esbuildMinify(input, sourceMap, minimizerOptions) {
|
|
264
|
+
/**
|
|
265
|
+
* @param {import("esbuild").TransformOptions} [esbuildOptions={}]
|
|
266
|
+
* @returns {import("esbuild").TransformOptions}
|
|
267
|
+
*/
|
|
135
268
|
const buildEsbuildOptions = (esbuildOptions = {}) => {
|
|
136
269
|
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
|
|
137
270
|
return {
|
|
@@ -160,7 +293,71 @@ async function esbuildMinify(input, sourceMap, minimizerOptions) {
|
|
|
160
293
|
return {
|
|
161
294
|
code: result.code,
|
|
162
295
|
// eslint-disable-next-line no-undefined
|
|
163
|
-
map: result.map ? result.map : undefined,
|
|
164
|
-
warnings: result.warnings ? result.warnings.map(item =>
|
|
296
|
+
map: result.map ? JSON.parse(result.map) : undefined,
|
|
297
|
+
warnings: result.warnings.length > 0 ? result.warnings.map(item => {
|
|
298
|
+
return {
|
|
299
|
+
source: item.location && item.location.file,
|
|
300
|
+
// eslint-disable-next-line no-undefined
|
|
301
|
+
line: item.location && item.location.line ? item.location.line : undefined,
|
|
302
|
+
// eslint-disable-next-line no-undefined
|
|
303
|
+
column: item.location && item.location.column ? item.location.column : undefined,
|
|
304
|
+
plugin: item.pluginName,
|
|
305
|
+
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
|
+
};
|
|
307
|
+
}) : []
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/* istanbul ignore next */
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @param {Input} input
|
|
314
|
+
* @param {RawSourceMap | undefined} sourceMap
|
|
315
|
+
* @param {CustomOptions} minimizerOptions
|
|
316
|
+
* @return {Promise<MinimizedResult>}
|
|
317
|
+
*/
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
async function parcelCssMinify(input, sourceMap, minimizerOptions) {
|
|
321
|
+
const [[filename, code]] = Object.entries(input);
|
|
322
|
+
/**
|
|
323
|
+
* @param {Partial<import("@parcel/css").TransformOptions>} [parcelCssOptions={}]
|
|
324
|
+
* @returns {import("@parcel/css").TransformOptions}
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
const buildParcelCssOptions = (parcelCssOptions = {}) => {
|
|
328
|
+
// Need deep copy objects to avoid https://github.com/terser/terser/issues/366
|
|
329
|
+
return {
|
|
330
|
+
minify: true,
|
|
331
|
+
...parcelCssOptions,
|
|
332
|
+
sourceMap: false,
|
|
333
|
+
filename,
|
|
334
|
+
code: Buffer.from(code)
|
|
335
|
+
};
|
|
336
|
+
}; // eslint-disable-next-line import/no-extraneous-dependencies, global-require
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
const parcelCss = require("@parcel/css"); // Copy `esbuild` options
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
const parcelCssOptions = buildParcelCssOptions(minimizerOptions); // Let `esbuild` generate a SourceMap
|
|
343
|
+
|
|
344
|
+
if (sourceMap) {
|
|
345
|
+
parcelCssOptions.sourceMap = true;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const result = await parcelCss.transform(parcelCssOptions);
|
|
349
|
+
return {
|
|
350
|
+
code: result.code.toString(),
|
|
351
|
+
// eslint-disable-next-line no-undefined
|
|
352
|
+
map: result.map ? JSON.parse(result.map.toString()) : undefined
|
|
165
353
|
};
|
|
166
|
-
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
module.exports = {
|
|
357
|
+
throttleAll,
|
|
358
|
+
cssnanoMinify,
|
|
359
|
+
cssoMinify,
|
|
360
|
+
cleanCssMinify,
|
|
361
|
+
esbuildMinify,
|
|
362
|
+
parcelCssMinify
|
|
363
|
+
};
|