@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,31 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = _default;
|
|
7
|
-
exports.pitch = pitch;
|
|
3
|
+
const path = require("path");
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
const {
|
|
6
|
+
findModuleById,
|
|
7
|
+
evalModuleCode,
|
|
8
|
+
AUTO_PUBLIC_PATH,
|
|
9
|
+
ABSOLUTE_PUBLIC_PATH,
|
|
10
|
+
SINGLE_DOT_PATH_SEGMENT,
|
|
11
|
+
stringifyRequest
|
|
12
|
+
} = require("./utils");
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
const schema = require("./loader-options.json");
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
const MiniCssExtractPlugin = require("./index");
|
|
17
|
+
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
/** @typedef {import("webpack").Compiler} Compiler */
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
/** @typedef {import("webpack").Compilation} Compilation */
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
/** @typedef {import("webpack").Chunk} Chunk */
|
|
24
|
+
|
|
25
|
+
/** @typedef {import("webpack").Module} Module */
|
|
26
|
+
|
|
27
|
+
/** @typedef {import("webpack").sources.Source} Source */
|
|
28
|
+
|
|
29
|
+
/** @typedef {import("webpack").AssetInfo} AssetInfo */
|
|
30
|
+
|
|
31
|
+
/** @typedef {import("webpack").NormalModule} NormalModule */
|
|
32
|
+
|
|
33
|
+
/** @typedef {import("./index.js").LoaderOptions} LoaderOptions */
|
|
34
|
+
|
|
35
|
+
/** @typedef {any} TODO */
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {Object} Dependency
|
|
39
|
+
* @property {string} identifier
|
|
40
|
+
* @property {string | null} context
|
|
41
|
+
* @property {Buffer} content
|
|
42
|
+
* @property {string} media
|
|
43
|
+
* @property {string} [supports]
|
|
44
|
+
* @property {string} [layer]
|
|
45
|
+
* @property {Buffer} [sourceMap]
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} content
|
|
50
|
+
* @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: {[key: string]: string } | undefined }} context
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
20
53
|
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
54
|
|
|
23
55
|
function hotLoader(content, context) {
|
|
24
56
|
const accept = context.locals ? "" : "module.hot.accept(undefined, cssReload);";
|
|
25
57
|
return `${content}
|
|
26
58
|
if(module.hot) {
|
|
27
59
|
// ${Date.now()}
|
|
28
|
-
var cssReload = require(${
|
|
60
|
+
var cssReload = require(${stringifyRequest(context.loaderContext, path.join(__dirname, "hmr/hotModuleReplacement.js"))})(module.id, ${JSON.stringify({ ...context.options,
|
|
29
61
|
locals: !!context.locals
|
|
30
62
|
})});
|
|
31
63
|
module.hot.dispose(cssReload);
|
|
@@ -33,11 +65,21 @@ function hotLoader(content, context) {
|
|
|
33
65
|
}
|
|
34
66
|
`;
|
|
35
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* @this {import("webpack").LoaderContext<LoaderOptions>}
|
|
70
|
+
* @param {string} request
|
|
71
|
+
*/
|
|
72
|
+
|
|
36
73
|
|
|
37
74
|
function pitch(request) {
|
|
38
|
-
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
const options = this.getOptions(
|
|
77
|
+
/** @type {Schema} */
|
|
78
|
+
schema);
|
|
39
79
|
const callback = this.async();
|
|
40
|
-
const optionsFromPlugin =
|
|
80
|
+
const optionsFromPlugin =
|
|
81
|
+
/** @type {TODO} */
|
|
82
|
+
this[MiniCssExtractPlugin.pluginSymbol];
|
|
41
83
|
|
|
42
84
|
if (!optionsFromPlugin) {
|
|
43
85
|
callback(new Error("You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"));
|
|
@@ -46,12 +88,25 @@ function pitch(request) {
|
|
|
46
88
|
|
|
47
89
|
const {
|
|
48
90
|
webpack
|
|
49
|
-
} =
|
|
91
|
+
} =
|
|
92
|
+
/** @type {Compiler} */
|
|
93
|
+
this._compiler;
|
|
94
|
+
/**
|
|
95
|
+
* @param {TODO} originalExports
|
|
96
|
+
* @param {Compilation} [compilation]
|
|
97
|
+
* @param {{ [name: string]: Source }} [assets]
|
|
98
|
+
* @param {Map<string, AssetInfo>} [assetsInfo]
|
|
99
|
+
* @returns {void}
|
|
100
|
+
*/
|
|
50
101
|
|
|
51
102
|
const handleExports = (originalExports, compilation, assets, assetsInfo) => {
|
|
103
|
+
/** @type {{[key: string]: string } | undefined} */
|
|
52
104
|
let locals;
|
|
53
105
|
let namedExport;
|
|
54
106
|
const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
|
|
107
|
+
/**
|
|
108
|
+
* @param {Dependency[] | [null, object][]} dependencies
|
|
109
|
+
*/
|
|
55
110
|
|
|
56
111
|
const addDependencies = dependencies => {
|
|
57
112
|
if (!Array.isArray(dependencies) && dependencies != null) {
|
|
@@ -63,18 +118,28 @@ function pitch(request) {
|
|
|
63
118
|
let lastDep;
|
|
64
119
|
|
|
65
120
|
for (const dependency of dependencies) {
|
|
66
|
-
if (!
|
|
121
|
+
if (!
|
|
122
|
+
/** @type {Dependency} */
|
|
123
|
+
dependency.identifier || !emit) {
|
|
67
124
|
// eslint-disable-next-line no-continue
|
|
68
125
|
continue;
|
|
69
126
|
}
|
|
70
127
|
|
|
71
|
-
const count = identifierCountMap.get(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
128
|
+
const count = identifierCountMap.get(
|
|
129
|
+
/** @type {Dependency} */
|
|
130
|
+
dependency.identifier) || 0;
|
|
131
|
+
const CssDependency = MiniCssExtractPlugin.getCssDependency(webpack);
|
|
132
|
+
/** @type {NormalModule} */
|
|
133
|
+
|
|
134
|
+
this._module.addDependency(lastDep = new CssDependency(
|
|
135
|
+
/** @type {Dependency} */
|
|
136
|
+
dependency,
|
|
137
|
+
/** @type {Dependency} */
|
|
138
|
+
dependency.context, count));
|
|
139
|
+
|
|
140
|
+
identifierCountMap.set(
|
|
141
|
+
/** @type {Dependency} */
|
|
142
|
+
dependency.identifier, count + 1);
|
|
78
143
|
}
|
|
79
144
|
|
|
80
145
|
if (lastDep && assets) {
|
|
@@ -102,6 +167,8 @@ function pitch(request) {
|
|
|
102
167
|
} else {
|
|
103
168
|
locals = exports && exports.locals;
|
|
104
169
|
}
|
|
170
|
+
/** @type {Dependency[] | [null, object][]} */
|
|
171
|
+
|
|
105
172
|
|
|
106
173
|
let dependencies;
|
|
107
174
|
|
|
@@ -113,7 +180,9 @@ function pitch(request) {
|
|
|
113
180
|
let context;
|
|
114
181
|
|
|
115
182
|
if (compilation) {
|
|
116
|
-
const module =
|
|
183
|
+
const module =
|
|
184
|
+
/** @type {Module} */
|
|
185
|
+
findModuleById(compilation, id);
|
|
117
186
|
identifier = module.identifier();
|
|
118
187
|
({
|
|
119
188
|
context
|
|
@@ -138,22 +207,29 @@ function pitch(request) {
|
|
|
138
207
|
|
|
139
208
|
addDependencies(dependencies);
|
|
140
209
|
} catch (e) {
|
|
141
|
-
|
|
210
|
+
callback(
|
|
211
|
+
/** @type {Error} */
|
|
212
|
+
e);
|
|
213
|
+
return;
|
|
142
214
|
}
|
|
143
215
|
|
|
144
|
-
const result = locals ? namedExport ? Object.keys(locals).map(key => `\nexport var ${key} = ${JSON.stringify(
|
|
145
|
-
|
|
216
|
+
const result = locals ? namedExport ? Object.keys(locals).map(key => `\nexport var ${key} = ${JSON.stringify(
|
|
217
|
+
/** @type {{[key: string]: string }} */
|
|
218
|
+
locals[key])};`).join("") : `\n${esModule ? "export default" : "module.exports ="} ${JSON.stringify(locals)};` : esModule ? `\nexport {};` : "";
|
|
219
|
+
let resultSource = `// extracted by ${MiniCssExtractPlugin.pluginName}`;
|
|
146
220
|
resultSource += this.hot ? hotLoader(result, {
|
|
147
|
-
|
|
221
|
+
loaderContext: this,
|
|
148
222
|
options,
|
|
149
223
|
locals
|
|
150
224
|
}) : result;
|
|
151
|
-
|
|
225
|
+
callback(null, resultSource);
|
|
152
226
|
};
|
|
153
227
|
|
|
154
228
|
let {
|
|
155
229
|
publicPath
|
|
156
|
-
} =
|
|
230
|
+
} =
|
|
231
|
+
/** @type {Compilation} */
|
|
232
|
+
this._compilation.outputOptions;
|
|
157
233
|
|
|
158
234
|
if (typeof options.publicPath === "string") {
|
|
159
235
|
// eslint-disable-next-line prefer-destructuring
|
|
@@ -163,7 +239,7 @@ function pitch(request) {
|
|
|
163
239
|
}
|
|
164
240
|
|
|
165
241
|
if (publicPath === "auto") {
|
|
166
|
-
publicPath =
|
|
242
|
+
publicPath = AUTO_PUBLIC_PATH;
|
|
167
243
|
}
|
|
168
244
|
|
|
169
245
|
if (typeof optionsFromPlugin.experimentalUseImportModule === "undefined" && typeof this.importModule === "function" || optionsFromPlugin.experimentalUseImportModule) {
|
|
@@ -172,12 +248,26 @@ function pitch(request) {
|
|
|
172
248
|
return;
|
|
173
249
|
}
|
|
174
250
|
|
|
175
|
-
|
|
176
|
-
|
|
251
|
+
let publicPathForExtract;
|
|
252
|
+
|
|
253
|
+
if (typeof publicPath === "string") {
|
|
254
|
+
const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
|
|
255
|
+
publicPathForExtract = isAbsolutePublicPath ? publicPath : `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(/\./g, SINGLE_DOT_PATH_SEGMENT)}`;
|
|
256
|
+
} else {
|
|
257
|
+
publicPathForExtract = publicPath;
|
|
258
|
+
}
|
|
259
|
+
|
|
177
260
|
this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, {
|
|
178
261
|
layer: options.layer,
|
|
179
|
-
publicPath:
|
|
180
|
-
|
|
262
|
+
publicPath:
|
|
263
|
+
/** @type {string} */
|
|
264
|
+
publicPathForExtract
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* @param {Error | null | undefined} error
|
|
268
|
+
* @param {object} exports
|
|
269
|
+
*/
|
|
270
|
+
(error, exports) => {
|
|
181
271
|
if (error) {
|
|
182
272
|
callback(error);
|
|
183
273
|
return;
|
|
@@ -196,7 +286,9 @@ function pitch(request) {
|
|
|
196
286
|
publicPath
|
|
197
287
|
};
|
|
198
288
|
|
|
199
|
-
const childCompiler =
|
|
289
|
+
const childCompiler =
|
|
290
|
+
/** @type {Compilation} */
|
|
291
|
+
this._compilation.createChildCompiler(`${MiniCssExtractPlugin.pluginName} ${request}`, outputOptions); // The templates are compiled and executed by NodeJS - similar to server side rendering
|
|
200
292
|
// Unfortunately this causes issues as some loaders require an absolute URL to support ES Modules
|
|
201
293
|
// The following config enables relative URL support for the child compiler
|
|
202
294
|
|
|
@@ -242,13 +334,18 @@ function pitch(request) {
|
|
|
242
334
|
const {
|
|
243
335
|
NormalModule
|
|
244
336
|
} = webpack;
|
|
245
|
-
childCompiler.hooks.thisCompilation.tap(`${
|
|
337
|
+
childCompiler.hooks.thisCompilation.tap(`${MiniCssExtractPlugin.pluginName} loader`,
|
|
338
|
+
/**
|
|
339
|
+
* @param {Compilation} compilation
|
|
340
|
+
*/
|
|
341
|
+
compilation => {
|
|
246
342
|
const normalModuleHook = NormalModule.getCompilationHooks(compilation).loader;
|
|
247
|
-
normalModuleHook.tap(`${
|
|
343
|
+
normalModuleHook.tap(`${MiniCssExtractPlugin.pluginName} loader`, (loaderContext, module) => {
|
|
248
344
|
if (module.request === request) {
|
|
249
345
|
// eslint-disable-next-line no-param-reassign
|
|
250
346
|
module.loaders = loaders.map(loader => {
|
|
251
347
|
return {
|
|
348
|
+
type: null,
|
|
252
349
|
loader: loader.path,
|
|
253
350
|
options: loader.options,
|
|
254
351
|
ident: loader.ident
|
|
@@ -257,9 +354,15 @@ function pitch(request) {
|
|
|
257
354
|
}
|
|
258
355
|
});
|
|
259
356
|
});
|
|
357
|
+
/** @type {string | Buffer} */
|
|
358
|
+
|
|
260
359
|
let source;
|
|
261
|
-
childCompiler.hooks.compilation.tap(
|
|
262
|
-
|
|
360
|
+
childCompiler.hooks.compilation.tap(MiniCssExtractPlugin.pluginName,
|
|
361
|
+
/**
|
|
362
|
+
* @param {Compilation} compilation
|
|
363
|
+
*/
|
|
364
|
+
compilation => {
|
|
365
|
+
compilation.hooks.processAssets.tap(MiniCssExtractPlugin.pluginName, () => {
|
|
263
366
|
source = compilation.assets[childFilename] && compilation.assets[childFilename].source(); // Remove all chunk assets
|
|
264
367
|
|
|
265
368
|
compilation.chunks.forEach(chunk => {
|
|
@@ -271,45 +374,65 @@ function pitch(request) {
|
|
|
271
374
|
});
|
|
272
375
|
childCompiler.runAsChild((error, entries, compilation) => {
|
|
273
376
|
if (error) {
|
|
274
|
-
|
|
377
|
+
callback(error);
|
|
378
|
+
return;
|
|
275
379
|
}
|
|
276
380
|
|
|
277
|
-
if (
|
|
278
|
-
|
|
381
|
+
if (
|
|
382
|
+
/** @type {Compilation} */
|
|
383
|
+
compilation.errors.length > 0) {
|
|
384
|
+
callback(
|
|
385
|
+
/** @type {Compilation} */
|
|
386
|
+
compilation.errors[0]);
|
|
387
|
+
return;
|
|
279
388
|
}
|
|
389
|
+
/** @type {{ [name: string]: Source }} */
|
|
390
|
+
|
|
280
391
|
|
|
281
392
|
const assets = Object.create(null);
|
|
393
|
+
/** @type {Map<string, AssetInfo>} */
|
|
394
|
+
|
|
282
395
|
const assetsInfo = new Map();
|
|
283
396
|
|
|
284
|
-
for (const asset of
|
|
397
|
+
for (const asset of
|
|
398
|
+
/** @type {Compilation} */
|
|
399
|
+
compilation.getAssets()) {
|
|
285
400
|
assets[asset.name] = asset.source;
|
|
286
401
|
assetsInfo.set(asset.name, asset.info);
|
|
287
402
|
}
|
|
403
|
+
/** @type {Compilation} */
|
|
404
|
+
|
|
288
405
|
|
|
289
406
|
compilation.fileDependencies.forEach(dep => {
|
|
290
407
|
this.addDependency(dep);
|
|
291
408
|
}, this);
|
|
409
|
+
/** @type {Compilation} */
|
|
410
|
+
|
|
292
411
|
compilation.contextDependencies.forEach(dep => {
|
|
293
412
|
this.addContextDependency(dep);
|
|
294
413
|
}, this);
|
|
295
414
|
|
|
296
415
|
if (!source) {
|
|
297
|
-
|
|
416
|
+
callback(new Error("Didn't get a result from child compiler"));
|
|
417
|
+
return;
|
|
298
418
|
}
|
|
299
419
|
|
|
300
420
|
let originalExports;
|
|
301
421
|
|
|
302
422
|
try {
|
|
303
|
-
originalExports =
|
|
423
|
+
originalExports = evalModuleCode(this, source, request);
|
|
304
424
|
} catch (e) {
|
|
305
|
-
|
|
425
|
+
callback(
|
|
426
|
+
/** @type {Error} */
|
|
427
|
+
e);
|
|
428
|
+
return;
|
|
306
429
|
}
|
|
307
430
|
|
|
308
|
-
|
|
431
|
+
handleExports(originalExports, compilation, assets, assetsInfo);
|
|
309
432
|
});
|
|
310
|
-
}
|
|
311
|
-
|
|
433
|
+
}
|
|
312
434
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
435
|
+
module.exports = {
|
|
436
|
+
default: function loader() {},
|
|
437
|
+
pitch
|
|
438
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"mini-css-extract-plugin","author":"Tobias Koppers @sokra","license":"MIT"}
|
|
1
|
+
{"name":"mini-css-extract-plugin","author":"Tobias Koppers @sokra","license":"MIT","types":"types/index.d.ts"}
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SINGLE_DOT_PATH_SEGMENT = exports.MODULE_TYPE = exports.AUTO_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = void 0;
|
|
7
|
-
exports.compareModulesByIdentifier = compareModulesByIdentifier;
|
|
8
|
-
exports.evalModuleCode = evalModuleCode;
|
|
9
|
-
exports.findModuleById = findModuleById;
|
|
10
|
-
exports.getUndoPath = getUndoPath;
|
|
11
|
-
exports.stringifyRequest = stringifyRequest;
|
|
12
|
-
exports.trueFn = trueFn;
|
|
3
|
+
const NativeModule = require("module");
|
|
13
4
|
|
|
14
|
-
|
|
5
|
+
const path = require("path");
|
|
6
|
+
/** @typedef {import("webpack").Compilation} Compilation */
|
|
15
7
|
|
|
16
|
-
|
|
8
|
+
/** @typedef {import("webpack").Module} Module */
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("webpack").LoaderContext<any>} LoaderContext */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
17
15
|
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
16
|
|
|
20
17
|
function trueFn() {
|
|
21
18
|
return true;
|
|
22
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @param {Compilation} compilation
|
|
22
|
+
* @param {string | number} id
|
|
23
|
+
* @returns {null | Module}
|
|
24
|
+
*/
|
|
25
|
+
|
|
23
26
|
|
|
24
27
|
function findModuleById(compilation, id) {
|
|
25
28
|
const {
|
|
@@ -37,18 +40,33 @@ function findModuleById(compilation, id) {
|
|
|
37
40
|
|
|
38
41
|
return null;
|
|
39
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* @param {LoaderContext} loaderContext
|
|
45
|
+
* @param {string | Buffer} code
|
|
46
|
+
* @param {string} filename
|
|
47
|
+
* @returns {object}
|
|
48
|
+
*/
|
|
49
|
+
|
|
40
50
|
|
|
41
51
|
function evalModuleCode(loaderContext, code, filename) {
|
|
42
|
-
|
|
43
|
-
module
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
const module = new NativeModule(filename, loaderContext); // @ts-ignore
|
|
54
|
+
|
|
55
|
+
module.paths = NativeModule._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
|
|
44
56
|
|
|
45
|
-
module.filename = filename;
|
|
57
|
+
module.filename = filename; // @ts-ignore
|
|
46
58
|
|
|
47
59
|
module._compile(code, filename); // eslint-disable-line no-underscore-dangle
|
|
48
60
|
|
|
49
61
|
|
|
50
62
|
return module.exports;
|
|
51
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} a
|
|
66
|
+
* @param {string} b
|
|
67
|
+
* @returns {0 | 1 | -1}
|
|
68
|
+
*/
|
|
69
|
+
|
|
52
70
|
|
|
53
71
|
function compareIds(a, b) {
|
|
54
72
|
if (typeof a !== typeof b) {
|
|
@@ -65,30 +83,46 @@ function compareIds(a, b) {
|
|
|
65
83
|
|
|
66
84
|
return 0;
|
|
67
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {Module} a
|
|
88
|
+
* @param {Module} b
|
|
89
|
+
* @returns {0 | 1 | -1}
|
|
90
|
+
*/
|
|
91
|
+
|
|
68
92
|
|
|
69
93
|
function compareModulesByIdentifier(a, b) {
|
|
70
94
|
return compareIds(a.identifier(), b.identifier());
|
|
71
95
|
}
|
|
72
96
|
|
|
73
97
|
const MODULE_TYPE = "css/mini-extract";
|
|
74
|
-
exports.MODULE_TYPE = MODULE_TYPE;
|
|
75
98
|
const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
|
|
76
|
-
exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
|
|
77
99
|
const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/";
|
|
78
|
-
exports.ABSOLUTE_PUBLIC_PATH = ABSOLUTE_PUBLIC_PATH;
|
|
79
100
|
const SINGLE_DOT_PATH_SEGMENT = "__mini_css_extract_plugin_single_dot_path_segment__";
|
|
80
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @param {string} str
|
|
103
|
+
* @returns {boolean}
|
|
104
|
+
*/
|
|
81
105
|
|
|
82
106
|
function isAbsolutePath(str) {
|
|
83
|
-
return
|
|
107
|
+
return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
|
|
84
108
|
}
|
|
85
109
|
|
|
86
110
|
const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
|
|
111
|
+
/**
|
|
112
|
+
* @param {string} str
|
|
113
|
+
* @returns {boolean}
|
|
114
|
+
*/
|
|
87
115
|
|
|
88
116
|
function isRelativePath(str) {
|
|
89
117
|
return RELATIVE_PATH_REGEXP.test(str);
|
|
90
118
|
} // TODO simplify for the next major release
|
|
91
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @param {LoaderContext} loaderContext
|
|
122
|
+
* @param {string} request
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
125
|
+
|
|
92
126
|
|
|
93
127
|
function stringifyRequest(loaderContext, request) {
|
|
94
128
|
if (typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function") {
|
|
@@ -106,7 +140,7 @@ function stringifyRequest(loaderContext, request) {
|
|
|
106
140
|
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
107
141
|
|
|
108
142
|
if (isAbsolutePath(singlePath) && context) {
|
|
109
|
-
singlePath =
|
|
143
|
+
singlePath = path.relative(context, singlePath);
|
|
110
144
|
|
|
111
145
|
if (isAbsolutePath(singlePath)) {
|
|
112
146
|
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
|
@@ -124,6 +158,13 @@ function stringifyRequest(loaderContext, request) {
|
|
|
124
158
|
return singlePath.replace(/\\/g, "/") + query;
|
|
125
159
|
}).join("!"));
|
|
126
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} filename
|
|
163
|
+
* @param {string} outputPath
|
|
164
|
+
* @param {boolean} enforceRelative
|
|
165
|
+
* @returns {string}
|
|
166
|
+
*/
|
|
167
|
+
|
|
127
168
|
|
|
128
169
|
function getUndoPath(filename, outputPath, enforceRelative) {
|
|
129
170
|
let depth = -1;
|
|
@@ -156,4 +197,17 @@ function getUndoPath(filename, outputPath, enforceRelative) {
|
|
|
156
197
|
}
|
|
157
198
|
|
|
158
199
|
return depth > 0 ? `${"../".repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
|
|
159
|
-
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = {
|
|
203
|
+
trueFn,
|
|
204
|
+
findModuleById,
|
|
205
|
+
evalModuleCode,
|
|
206
|
+
compareModulesByIdentifier,
|
|
207
|
+
MODULE_TYPE,
|
|
208
|
+
AUTO_PUBLIC_PATH,
|
|
209
|
+
ABSOLUTE_PUBLIC_PATH,
|
|
210
|
+
SINGLE_DOT_PATH_SEGMENT,
|
|
211
|
+
stringifyRequest,
|
|
212
|
+
getUndoPath
|
|
213
|
+
};
|