@shuvi/toolpack 0.0.1-rc.9 → 1.0.0-rc.10
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/lib/babel/plugins/auto-css-modules.js +1 -1
- package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
- package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +9 -9
- package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
- package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
- package/lib/babel/preset.js +25 -5
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +5 -1
- package/lib/utils/bundle-require.d.ts +33 -0
- package/lib/utils/bundle-require.js +143 -0
- package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +17 -14
- package/lib/webpack/config/base.d.ts +17 -4
- package/lib/webpack/config/base.js +144 -99
- package/lib/webpack/config/browser.d.ts +3 -4
- package/lib/webpack/config/browser.js +132 -56
- package/lib/webpack/config/index.js +18 -7
- package/lib/webpack/config/node.d.ts +3 -4
- package/lib/webpack/config/node.js +21 -28
- package/lib/webpack/config/parts/external.d.ts +3 -2
- package/lib/webpack/config/parts/external.js +16 -10
- package/lib/webpack/config/parts/helpers.d.ts +3 -1
- package/lib/webpack/config/parts/helpers.js +14 -1
- package/lib/webpack/config/parts/resolve.js +1 -0
- package/lib/webpack/config/parts/style.d.ts +5 -2
- package/lib/webpack/config/parts/style.js +125 -60
- package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
- package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
- package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
- package/lib/webpack/dynamic-dll/constants.js +9 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
- package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
- package/lib/webpack/dynamic-dll/dep/index.js +43 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
- package/lib/webpack/dynamic-dll/index.d.ts +35 -0
- package/lib/webpack/dynamic-dll/index.js +198 -0
- package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
- package/lib/webpack/dynamic-dll/metadata.js +62 -0
- package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
- package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +70 -0
- package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
- package/lib/webpack/dynamic-dll/utils.js +29 -0
- package/lib/webpack/index.d.ts +15 -0
- package/lib/webpack/index.js +110 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +11 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +40 -0
- package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
- package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
- package/lib/webpack/loaders/route-component-loader.js +25 -5
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +2 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.js +119 -0
- package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
- package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
- package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
- package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
- package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +7 -6
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +56 -33
- package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
- package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
- package/lib/webpack/types.d.ts +40 -0
- package/lib/webpack/types.js +2 -0
- package/package.json +46 -40
- package/lib/utils/emptyComponent.d.ts +0 -1
- package/lib/utils/emptyComponent.js +0 -7
- package/lib/utils/errorOverlayMiddleware.d.ts +0 -1
- package/lib/utils/errorOverlayMiddleware.js +0 -21
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -63
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -289
- package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
- package/lib/utils/verifyTypeScriptSetup.js +0 -229
- package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
- package/lib/webpack/loaders/export-global-loader.js +0 -26
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.isDataUrl = exports.stringifyRequest = exports.combineRequests = exports.isURLRequestable = exports.resolveRequests = exports.getExportCode = exports.getParcelCssModuleCode = exports.getImportCode = exports.getPreRequester = exports.normalizeSourceMap = exports.requestify = exports.normalizeUrl = exports.shouldUseIcssPlugin = exports.normalizeOptions = void 0;
|
|
16
|
+
/*
|
|
17
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
18
|
+
Author Tobias Koppers @sokra
|
|
19
|
+
*/
|
|
20
|
+
const url_1 = require("url");
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const matchRelativePath = /^\.\.?[/\\]/;
|
|
23
|
+
function isAbsolutePath(str) {
|
|
24
|
+
return path_1.default.posix.isAbsolute(str) || path_1.default.win32.isAbsolute(str);
|
|
25
|
+
}
|
|
26
|
+
function isRelativePath(str) {
|
|
27
|
+
return matchRelativePath.test(str);
|
|
28
|
+
}
|
|
29
|
+
// TODO simplify for the next major release
|
|
30
|
+
function stringifyRequest(loaderContext, request) {
|
|
31
|
+
if (typeof loaderContext.utils !== 'undefined' &&
|
|
32
|
+
typeof loaderContext.utils.contextify === 'function') {
|
|
33
|
+
return JSON.stringify(loaderContext.utils.contextify(loaderContext.context || loaderContext.rootContext, request));
|
|
34
|
+
}
|
|
35
|
+
const splitted = request.split('!');
|
|
36
|
+
const { context } = loaderContext;
|
|
37
|
+
return JSON.stringify(splitted
|
|
38
|
+
.map(part => {
|
|
39
|
+
// First, separate singlePath from query, because the query might contain paths again
|
|
40
|
+
const splittedPart = part.match(/^(.*?)(\?.*)/);
|
|
41
|
+
const query = splittedPart ? splittedPart[2] : '';
|
|
42
|
+
let singlePath = splittedPart ? splittedPart[1] : part;
|
|
43
|
+
if (isAbsolutePath(singlePath) && context) {
|
|
44
|
+
singlePath = path_1.default.relative(context, singlePath);
|
|
45
|
+
if (isAbsolutePath(singlePath)) {
|
|
46
|
+
// If singlePath still matches an absolute path, singlePath was on a different drive than context.
|
|
47
|
+
// In this case, we leave the path platform-specific without replacing any separators.
|
|
48
|
+
// @see https://github.com/webpack/loader-utils/pull/14
|
|
49
|
+
return singlePath + query;
|
|
50
|
+
}
|
|
51
|
+
if (isRelativePath(singlePath) === false) {
|
|
52
|
+
// Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
|
|
53
|
+
singlePath = `./${singlePath}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return singlePath.replace(/\\/g, '/') + query;
|
|
57
|
+
})
|
|
58
|
+
.join('!'));
|
|
59
|
+
}
|
|
60
|
+
exports.stringifyRequest = stringifyRequest;
|
|
61
|
+
// We can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
|
|
62
|
+
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
|
|
63
|
+
const IS_MODULE_REQUEST = /^[^?]*~/;
|
|
64
|
+
function urlToRequest(url, root) {
|
|
65
|
+
let request;
|
|
66
|
+
if (IS_NATIVE_WIN32_PATH.test(url)) {
|
|
67
|
+
// absolute windows path, keep it
|
|
68
|
+
request = url;
|
|
69
|
+
}
|
|
70
|
+
else if (typeof root !== 'undefined' && /^\//.test(url)) {
|
|
71
|
+
request = root + url;
|
|
72
|
+
}
|
|
73
|
+
else if (/^\.\.?\//.test(url)) {
|
|
74
|
+
// A relative url stays
|
|
75
|
+
request = url;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
// every other url is threaded like a relative url
|
|
79
|
+
request = `./${url}`;
|
|
80
|
+
}
|
|
81
|
+
// A `~` makes the url an module
|
|
82
|
+
if (IS_MODULE_REQUEST.test(request)) {
|
|
83
|
+
request = request.replace(IS_MODULE_REQUEST, '');
|
|
84
|
+
}
|
|
85
|
+
return request;
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line no-useless-escape
|
|
88
|
+
const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
|
|
89
|
+
const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
|
|
90
|
+
const preserveCamelCase = string => {
|
|
91
|
+
let result = string;
|
|
92
|
+
let isLastCharLower = false;
|
|
93
|
+
let isLastCharUpper = false;
|
|
94
|
+
let isLastLastCharUpper = false;
|
|
95
|
+
for (let i = 0; i < result.length; i++) {
|
|
96
|
+
const character = result[i];
|
|
97
|
+
if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
|
98
|
+
result = `${result.slice(0, i)}-${result.slice(i)}`;
|
|
99
|
+
isLastCharLower = false;
|
|
100
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
101
|
+
isLastCharUpper = true;
|
|
102
|
+
i += 1;
|
|
103
|
+
}
|
|
104
|
+
else if (isLastCharUpper &&
|
|
105
|
+
isLastLastCharUpper &&
|
|
106
|
+
/[\p{Ll}]/u.test(character)) {
|
|
107
|
+
result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
|
|
108
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
109
|
+
isLastCharUpper = false;
|
|
110
|
+
isLastCharLower = true;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
isLastCharLower =
|
|
114
|
+
character.toLowerCase() === character &&
|
|
115
|
+
character.toUpperCase() !== character;
|
|
116
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
117
|
+
isLastCharUpper =
|
|
118
|
+
character.toUpperCase() === character &&
|
|
119
|
+
character.toLowerCase() !== character;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
};
|
|
124
|
+
function camelCase(input) {
|
|
125
|
+
let result = input.trim();
|
|
126
|
+
if (result.length === 0) {
|
|
127
|
+
return '';
|
|
128
|
+
}
|
|
129
|
+
if (result.length === 1) {
|
|
130
|
+
return result.toLowerCase();
|
|
131
|
+
}
|
|
132
|
+
const hasUpperCase = result !== result.toLowerCase();
|
|
133
|
+
if (hasUpperCase) {
|
|
134
|
+
result = preserveCamelCase(result);
|
|
135
|
+
}
|
|
136
|
+
return result
|
|
137
|
+
.replace(/^[_.\- ]+/, '')
|
|
138
|
+
.toLowerCase()
|
|
139
|
+
.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase())
|
|
140
|
+
.replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
|
|
141
|
+
}
|
|
142
|
+
function escape(string) {
|
|
143
|
+
let output = '';
|
|
144
|
+
let counter = 0;
|
|
145
|
+
while (counter < string.length) {
|
|
146
|
+
// eslint-disable-next-line no-plusplus
|
|
147
|
+
const character = string.charAt(counter++);
|
|
148
|
+
let value;
|
|
149
|
+
// eslint-disable-next-line no-control-regex
|
|
150
|
+
if (/[\t\n\f\r\x0B]/.test(character)) {
|
|
151
|
+
const codePoint = character.charCodeAt();
|
|
152
|
+
value = `\\${codePoint.toString(16).toUpperCase()} `;
|
|
153
|
+
}
|
|
154
|
+
else if (character === '\\' || regexSingleEscape.test(character)) {
|
|
155
|
+
value = `\\${character}`;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
value = character;
|
|
159
|
+
}
|
|
160
|
+
output += value;
|
|
161
|
+
}
|
|
162
|
+
const firstChar = string.charAt(0);
|
|
163
|
+
if (/^-[-\d]/.test(output)) {
|
|
164
|
+
output = `\\-${output.slice(1)}`;
|
|
165
|
+
}
|
|
166
|
+
else if (/\d/.test(firstChar)) {
|
|
167
|
+
output = `\\3${firstChar} ${output.slice(1)}`;
|
|
168
|
+
}
|
|
169
|
+
// Remove spaces after `\HEX` escapes that are not followed by a hex digit,
|
|
170
|
+
// since they’re redundant. Note that this is only possible if the escape
|
|
171
|
+
// sequence isn’t preceded by an odd number of backslashes.
|
|
172
|
+
output = output.replace(regexExcessiveSpaces, ($0, $1, $2) => {
|
|
173
|
+
if ($1 && $1.length % 2) {
|
|
174
|
+
// It’s not safe to remove the space, so don’t.
|
|
175
|
+
return $0;
|
|
176
|
+
}
|
|
177
|
+
// Strip the space.
|
|
178
|
+
return ($1 || '') + $2;
|
|
179
|
+
});
|
|
180
|
+
return output;
|
|
181
|
+
}
|
|
182
|
+
function gobbleHex(str) {
|
|
183
|
+
const lower = str.toLowerCase();
|
|
184
|
+
let hex = '';
|
|
185
|
+
let spaceTerminated = false;
|
|
186
|
+
// eslint-disable-next-line no-undefined
|
|
187
|
+
for (let i = 0; i < 6 && lower[i] !== undefined; i++) {
|
|
188
|
+
const code = lower.charCodeAt(i);
|
|
189
|
+
// check to see if we are dealing with a valid hex char [a-f|0-9]
|
|
190
|
+
const valid = (code >= 97 && code <= 102) || (code >= 48 && code <= 57);
|
|
191
|
+
// https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
|
|
192
|
+
spaceTerminated = code === 32;
|
|
193
|
+
if (!valid) {
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
hex += lower[i];
|
|
197
|
+
}
|
|
198
|
+
if (hex.length === 0) {
|
|
199
|
+
// eslint-disable-next-line no-undefined
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const codePoint = parseInt(hex, 16);
|
|
203
|
+
const isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff;
|
|
204
|
+
// Add special case for
|
|
205
|
+
// "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
|
|
206
|
+
// https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
|
|
207
|
+
if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
|
|
208
|
+
return ['\uFFFD', hex.length + (spaceTerminated ? 1 : 0)];
|
|
209
|
+
}
|
|
210
|
+
return [
|
|
211
|
+
String.fromCodePoint(codePoint),
|
|
212
|
+
hex.length + (spaceTerminated ? 1 : 0)
|
|
213
|
+
];
|
|
214
|
+
}
|
|
215
|
+
const CONTAINS_ESCAPE = /\\/;
|
|
216
|
+
function unescape(str) {
|
|
217
|
+
const needToProcess = CONTAINS_ESCAPE.test(str);
|
|
218
|
+
if (!needToProcess) {
|
|
219
|
+
return str;
|
|
220
|
+
}
|
|
221
|
+
let ret = '';
|
|
222
|
+
for (let i = 0; i < str.length; i++) {
|
|
223
|
+
if (str[i] === '\\') {
|
|
224
|
+
const gobbled = gobbleHex(str.slice(i + 1, i + 7));
|
|
225
|
+
// eslint-disable-next-line no-undefined
|
|
226
|
+
if (gobbled !== undefined) {
|
|
227
|
+
ret += gobbled[0];
|
|
228
|
+
i += gobbled[1];
|
|
229
|
+
// eslint-disable-next-line no-continue
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
// Retain a pair of \\ if double escaped `\\\\`
|
|
233
|
+
// https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
|
|
234
|
+
if (str[i + 1] === '\\') {
|
|
235
|
+
ret += '\\';
|
|
236
|
+
i += 1;
|
|
237
|
+
// eslint-disable-next-line no-continue
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
// if \\ is at the end of the string retain it
|
|
241
|
+
// https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
|
|
242
|
+
if (str.length === i + 1) {
|
|
243
|
+
ret += str[i];
|
|
244
|
+
}
|
|
245
|
+
// eslint-disable-next-line no-continue
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
ret += str[i];
|
|
249
|
+
}
|
|
250
|
+
return ret;
|
|
251
|
+
}
|
|
252
|
+
function normalizePath(file) {
|
|
253
|
+
return path_1.default.sep === '\\' ? file.replace(/\\/g, '/') : file;
|
|
254
|
+
}
|
|
255
|
+
// eslint-disable-next-line no-control-regex
|
|
256
|
+
const filenameReservedRegex = /[<>:"/\\|?*]/g;
|
|
257
|
+
// eslint-disable-next-line no-control-regex
|
|
258
|
+
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
|
|
259
|
+
function escapeLocalIdent(localident) {
|
|
260
|
+
// TODO simplify in the next major release
|
|
261
|
+
return escape(localident
|
|
262
|
+
// For `[hash]` placeholder
|
|
263
|
+
.replace(/^((-?[0-9])|--)/, '_$1')
|
|
264
|
+
.replace(filenameReservedRegex, '-')
|
|
265
|
+
.replace(reControlChars, '-')
|
|
266
|
+
.replace(/\./g, '-'));
|
|
267
|
+
}
|
|
268
|
+
function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
|
|
269
|
+
const { context, hashSalt } = options;
|
|
270
|
+
const { resourcePath } = loaderContext;
|
|
271
|
+
const relativeResourcePath = normalizePath(path_1.default.relative(context, resourcePath));
|
|
272
|
+
// eslint-disable-next-line no-param-reassign
|
|
273
|
+
options.content = `${relativeResourcePath}\x00${localName}`;
|
|
274
|
+
let { hashFunction, hashDigest, hashDigestLength } = options;
|
|
275
|
+
const matches = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
|
|
276
|
+
if (matches) {
|
|
277
|
+
const hashName = matches[2] || hashFunction;
|
|
278
|
+
hashFunction = matches[1] || hashFunction;
|
|
279
|
+
hashDigest = matches[3] || hashDigest;
|
|
280
|
+
hashDigestLength = matches[4] || hashDigestLength;
|
|
281
|
+
// `hash` and `contenthash` are same in `loader-utils` context
|
|
282
|
+
// let's keep `hash` for backward compatibility
|
|
283
|
+
// eslint-disable-next-line no-param-reassign
|
|
284
|
+
localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => (hashName === 'fullhash' ? '[fullhash]' : '[contenthash]'));
|
|
285
|
+
}
|
|
286
|
+
let localIdentHash = '';
|
|
287
|
+
for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
|
|
288
|
+
// TODO remove this in the next major release
|
|
289
|
+
const hash = loaderContext.utils &&
|
|
290
|
+
typeof loaderContext.utils.createHash === 'function'
|
|
291
|
+
? loaderContext.utils.createHash(hashFunction)
|
|
292
|
+
: // eslint-disable-next-line no-underscore-dangle
|
|
293
|
+
loaderContext._compiler.webpack.util.createHash(hashFunction);
|
|
294
|
+
if (hashSalt) {
|
|
295
|
+
hash.update(hashSalt);
|
|
296
|
+
}
|
|
297
|
+
const tierSalt = Buffer.allocUnsafe(4);
|
|
298
|
+
tierSalt.writeUInt32LE(tier);
|
|
299
|
+
hash.update(tierSalt);
|
|
300
|
+
// TODO: bug in webpack with unicode characters with strings
|
|
301
|
+
hash.update(Buffer.from(options.content, 'utf8'));
|
|
302
|
+
localIdentHash = (localIdentHash + hash.digest(hashDigest))
|
|
303
|
+
// Remove all leading digits
|
|
304
|
+
.replace(/^\d+/, '')
|
|
305
|
+
// Replace all slashes with underscores (same as in base64url)
|
|
306
|
+
.replace(/\//g, '_')
|
|
307
|
+
// Remove everything that is not an alphanumeric or underscore
|
|
308
|
+
.replace(/[^A-Za-z0-9_]+/g, '')
|
|
309
|
+
.slice(0, hashDigestLength);
|
|
310
|
+
}
|
|
311
|
+
// TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
|
|
312
|
+
const ext = path_1.default.extname(resourcePath);
|
|
313
|
+
const base = path_1.default.basename(resourcePath);
|
|
314
|
+
const name = base.slice(0, base.length - ext.length);
|
|
315
|
+
const data = {
|
|
316
|
+
filename: path_1.default.relative(context, resourcePath),
|
|
317
|
+
contentHash: localIdentHash,
|
|
318
|
+
chunk: {
|
|
319
|
+
name,
|
|
320
|
+
hash: localIdentHash,
|
|
321
|
+
contentHash: localIdentHash
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
325
|
+
let result = loaderContext._compilation.getPath(localIdentName, data);
|
|
326
|
+
if (/\[folder\]/gi.test(result)) {
|
|
327
|
+
const dirname = path_1.default.dirname(resourcePath);
|
|
328
|
+
let directory = normalizePath(path_1.default.relative(context, `${dirname + path_1.default.sep}_`));
|
|
329
|
+
directory = directory.substr(0, directory.length - 1);
|
|
330
|
+
let folder = '';
|
|
331
|
+
if (directory.length > 1) {
|
|
332
|
+
folder = path_1.default.basename(directory);
|
|
333
|
+
}
|
|
334
|
+
result = result.replace(/\[folder\]/gi, () => folder);
|
|
335
|
+
}
|
|
336
|
+
if (options.regExp) {
|
|
337
|
+
const match = resourcePath.match(options.regExp);
|
|
338
|
+
if (match) {
|
|
339
|
+
match.forEach((matched, i) => {
|
|
340
|
+
result = result.replace(new RegExp(`\\[${i}\\]`, 'ig'), matched);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return result;
|
|
345
|
+
}
|
|
346
|
+
function fixedEncodeURIComponent(str) {
|
|
347
|
+
return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
|
|
348
|
+
}
|
|
349
|
+
function isDataUrl(url) {
|
|
350
|
+
if (/^data:/i.test(url)) {
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
exports.isDataUrl = isDataUrl;
|
|
356
|
+
const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
|
|
357
|
+
function normalizeUrl(url, isStringValue) {
|
|
358
|
+
let normalizedUrl = url
|
|
359
|
+
.replace(/^( |\t\n|\r\n|\r|\f)*/g, '')
|
|
360
|
+
.replace(/( |\t\n|\r\n|\r|\f)*$/g, '');
|
|
361
|
+
if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
|
|
362
|
+
normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, '');
|
|
363
|
+
}
|
|
364
|
+
if (NATIVE_WIN32_PATH.test(url)) {
|
|
365
|
+
try {
|
|
366
|
+
normalizedUrl = decodeURI(normalizedUrl);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
// Ignore
|
|
370
|
+
}
|
|
371
|
+
return normalizedUrl;
|
|
372
|
+
}
|
|
373
|
+
normalizedUrl = unescape(normalizedUrl);
|
|
374
|
+
if (isDataUrl(url)) {
|
|
375
|
+
// Todo fixedEncodeURIComponent is workaround. Webpack resolver shouldn't handle "!" in dataURL
|
|
376
|
+
return fixedEncodeURIComponent(normalizedUrl);
|
|
377
|
+
}
|
|
378
|
+
try {
|
|
379
|
+
normalizedUrl = decodeURI(normalizedUrl);
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
// Ignore
|
|
383
|
+
}
|
|
384
|
+
return normalizedUrl;
|
|
385
|
+
}
|
|
386
|
+
exports.normalizeUrl = normalizeUrl;
|
|
387
|
+
function requestify(url, rootContext, needToResolveURL = true) {
|
|
388
|
+
if (needToResolveURL) {
|
|
389
|
+
if (/^file:/i.test(url)) {
|
|
390
|
+
return (0, url_1.fileURLToPath)(url);
|
|
391
|
+
}
|
|
392
|
+
return url.charAt(0) === '/'
|
|
393
|
+
? urlToRequest(url, rootContext)
|
|
394
|
+
: urlToRequest(url);
|
|
395
|
+
}
|
|
396
|
+
if (url.charAt(0) === '/' || /^file:/i.test(url)) {
|
|
397
|
+
return url;
|
|
398
|
+
}
|
|
399
|
+
// A `~` makes the url an module
|
|
400
|
+
if (IS_MODULE_REQUEST.test(url)) {
|
|
401
|
+
return url.replace(IS_MODULE_REQUEST, '');
|
|
402
|
+
}
|
|
403
|
+
return url;
|
|
404
|
+
}
|
|
405
|
+
exports.requestify = requestify;
|
|
406
|
+
function getValidLocalName(localName, exportLocalsConvention) {
|
|
407
|
+
const result = exportLocalsConvention(localName);
|
|
408
|
+
return Array.isArray(result) ? result[0] : result;
|
|
409
|
+
}
|
|
410
|
+
const IS_MODULES = /\.module(s)?\.\w+$/i;
|
|
411
|
+
const IS_ICSS = /\.icss\.\w+$/i;
|
|
412
|
+
function getModulesOptions(rawOptions, exportType, loaderContext) {
|
|
413
|
+
if (typeof rawOptions.modules === 'boolean' && rawOptions.modules === false) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
const resourcePath =
|
|
417
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
418
|
+
(loaderContext._module && loaderContext._module.matchResource) ||
|
|
419
|
+
loaderContext.resourcePath;
|
|
420
|
+
let auto;
|
|
421
|
+
let rawModulesOptions;
|
|
422
|
+
if (typeof rawOptions.modules === 'undefined') {
|
|
423
|
+
rawModulesOptions = {};
|
|
424
|
+
auto = true;
|
|
425
|
+
}
|
|
426
|
+
else if (typeof rawOptions.modules === 'boolean') {
|
|
427
|
+
rawModulesOptions = {};
|
|
428
|
+
}
|
|
429
|
+
else if (typeof rawOptions.modules === 'string') {
|
|
430
|
+
rawModulesOptions = { mode: rawOptions.modules };
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
rawModulesOptions = rawOptions.modules;
|
|
434
|
+
({ auto } = rawModulesOptions);
|
|
435
|
+
}
|
|
436
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
437
|
+
const { outputOptions } = loaderContext._compilation;
|
|
438
|
+
const needNamedExport = exportType === 'css-style-sheet' || exportType === 'string';
|
|
439
|
+
const modulesOptions = Object.assign({ auto, mode: 'local', exportGlobals: false, localIdentName: '[hash:base64]', localIdentContext: loaderContext.rootContext, localIdentHashSalt: outputOptions.hashSalt, localIdentHashFunction: outputOptions.hashFunction, localIdentHashDigest: outputOptions.hashDigest, localIdentHashDigestLength: outputOptions.hashDigestLength,
|
|
440
|
+
// eslint-disable-next-line no-undefined
|
|
441
|
+
localIdentRegExp: undefined,
|
|
442
|
+
// eslint-disable-next-line no-undefined
|
|
443
|
+
getLocalIdent: undefined, namedExport: needNamedExport || false, exportLocalsConvention: (rawModulesOptions.namedExport === true || needNamedExport) &&
|
|
444
|
+
typeof rawModulesOptions.exportLocalsConvention === 'undefined'
|
|
445
|
+
? 'camelCaseOnly'
|
|
446
|
+
: 'asIs', exportOnlyLocals: false }, rawModulesOptions);
|
|
447
|
+
let exportLocalsConventionType;
|
|
448
|
+
if (typeof modulesOptions.exportLocalsConvention === 'string') {
|
|
449
|
+
exportLocalsConventionType = modulesOptions.exportLocalsConvention;
|
|
450
|
+
modulesOptions.exportLocalsConvention = name => {
|
|
451
|
+
switch (exportLocalsConventionType) {
|
|
452
|
+
case 'camelCase': {
|
|
453
|
+
return [name, camelCase(name)];
|
|
454
|
+
}
|
|
455
|
+
case 'camelCaseOnly': {
|
|
456
|
+
return camelCase(name);
|
|
457
|
+
}
|
|
458
|
+
case 'dashes': {
|
|
459
|
+
return [name, dashesCamelCase(name)];
|
|
460
|
+
}
|
|
461
|
+
case 'dashesOnly': {
|
|
462
|
+
return dashesCamelCase(name);
|
|
463
|
+
}
|
|
464
|
+
case 'asIs':
|
|
465
|
+
default:
|
|
466
|
+
return name;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (typeof modulesOptions.auto === 'boolean') {
|
|
471
|
+
const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
|
|
472
|
+
let isIcss;
|
|
473
|
+
if (!isModules) {
|
|
474
|
+
isIcss = IS_ICSS.test(resourcePath);
|
|
475
|
+
if (isIcss) {
|
|
476
|
+
modulesOptions.mode = 'icss';
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (!isModules && !isIcss) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else if (modulesOptions.auto instanceof RegExp) {
|
|
484
|
+
const isModules = modulesOptions.auto.test(resourcePath);
|
|
485
|
+
if (!isModules) {
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
else if (typeof modulesOptions.auto === 'function') {
|
|
490
|
+
const isModule = modulesOptions.auto(resourcePath);
|
|
491
|
+
if (!isModule) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (typeof modulesOptions.mode === 'function') {
|
|
496
|
+
modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath);
|
|
497
|
+
}
|
|
498
|
+
if (needNamedExport) {
|
|
499
|
+
if (rawOptions.esModule === false) {
|
|
500
|
+
throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'esModules' option to be enabled");
|
|
501
|
+
}
|
|
502
|
+
if (modulesOptions.namedExport === false) {
|
|
503
|
+
throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'modules.namedExport' option to be enabled");
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (modulesOptions.namedExport === true) {
|
|
507
|
+
if (rawOptions.esModule === false) {
|
|
508
|
+
throw new Error("The 'modules.namedExport' option requires the 'esModules' option to be enabled");
|
|
509
|
+
}
|
|
510
|
+
if (typeof exportLocalsConventionType === 'string' &&
|
|
511
|
+
exportLocalsConventionType !== 'camelCaseOnly' &&
|
|
512
|
+
exportLocalsConventionType !== 'dashesOnly') {
|
|
513
|
+
throw new Error('The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"');
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
return modulesOptions;
|
|
517
|
+
}
|
|
518
|
+
function normalizeOptions(rawOptions, loaderContext) {
|
|
519
|
+
const exportType = typeof rawOptions.exportType === 'undefined'
|
|
520
|
+
? 'array'
|
|
521
|
+
: rawOptions.exportType;
|
|
522
|
+
const modulesOptions = getModulesOptions(rawOptions, exportType, loaderContext);
|
|
523
|
+
return {
|
|
524
|
+
url: typeof rawOptions.url === 'undefined' ? true : rawOptions.url,
|
|
525
|
+
import: typeof rawOptions.import === 'undefined' ? true : rawOptions.import,
|
|
526
|
+
modules: modulesOptions,
|
|
527
|
+
sourceMap: typeof rawOptions.sourceMap === 'boolean'
|
|
528
|
+
? rawOptions.sourceMap
|
|
529
|
+
: loaderContext.sourceMap,
|
|
530
|
+
importLoaders: typeof rawOptions.importLoaders === 'string'
|
|
531
|
+
? parseInt(rawOptions.importLoaders, 10)
|
|
532
|
+
: rawOptions.importLoaders,
|
|
533
|
+
esModule: typeof rawOptions.esModule === 'undefined' ? true : rawOptions.esModule,
|
|
534
|
+
exportType
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
exports.normalizeOptions = normalizeOptions;
|
|
538
|
+
function shouldUseIcssPlugin(options) {
|
|
539
|
+
return Boolean(options.modules);
|
|
540
|
+
}
|
|
541
|
+
exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
|
|
542
|
+
const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
|
|
543
|
+
function getURLType(source) {
|
|
544
|
+
if (source[0] === '/') {
|
|
545
|
+
if (source[1] === '/') {
|
|
546
|
+
return 'scheme-relative';
|
|
547
|
+
}
|
|
548
|
+
return 'path-absolute';
|
|
549
|
+
}
|
|
550
|
+
if (IS_NATIVE_WIN32_PATH.test(source)) {
|
|
551
|
+
return 'path-absolute';
|
|
552
|
+
}
|
|
553
|
+
return ABSOLUTE_SCHEME.test(source) ? 'absolute' : 'path-relative';
|
|
554
|
+
}
|
|
555
|
+
function normalizeSourceMap(map, resourcePath) {
|
|
556
|
+
let newMap = map;
|
|
557
|
+
// Some loader emit source map as string
|
|
558
|
+
// Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
|
|
559
|
+
if (typeof newMap === 'string') {
|
|
560
|
+
newMap = JSON.parse(newMap);
|
|
561
|
+
}
|
|
562
|
+
delete newMap.file;
|
|
563
|
+
const { sourceRoot } = newMap;
|
|
564
|
+
delete newMap.sourceRoot;
|
|
565
|
+
if (newMap.sources) {
|
|
566
|
+
// Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
|
|
567
|
+
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
|
|
568
|
+
newMap.sources = newMap.sources.map(source => {
|
|
569
|
+
// Non-standard syntax from `postcss`
|
|
570
|
+
if (source.indexOf('<') === 0) {
|
|
571
|
+
return source;
|
|
572
|
+
}
|
|
573
|
+
const sourceType = getURLType(source);
|
|
574
|
+
// Do no touch `scheme-relative` and `absolute` URLs
|
|
575
|
+
if (sourceType === 'path-relative' || sourceType === 'path-absolute') {
|
|
576
|
+
const absoluteSource = sourceType === 'path-relative' && sourceRoot
|
|
577
|
+
? path_1.default.resolve(sourceRoot, normalizePath(source))
|
|
578
|
+
: normalizePath(source);
|
|
579
|
+
return path_1.default.relative(path_1.default.dirname(resourcePath), absoluteSource);
|
|
580
|
+
}
|
|
581
|
+
return source;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
return newMap;
|
|
585
|
+
}
|
|
586
|
+
exports.normalizeSourceMap = normalizeSourceMap;
|
|
587
|
+
function getPreRequester({ loaders, loaderIndex }) {
|
|
588
|
+
const cache = Object.create(null);
|
|
589
|
+
return number => {
|
|
590
|
+
if (cache[number]) {
|
|
591
|
+
return cache[number];
|
|
592
|
+
}
|
|
593
|
+
if (number === false) {
|
|
594
|
+
cache[number] = '';
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
const loadersRequest = loaders
|
|
598
|
+
.slice(loaderIndex, loaderIndex + 1 + (typeof number !== 'number' ? 0 : number))
|
|
599
|
+
.map(x => x.request)
|
|
600
|
+
.join('!');
|
|
601
|
+
cache[number] = `-!${loadersRequest}!`;
|
|
602
|
+
}
|
|
603
|
+
return cache[number];
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
exports.getPreRequester = getPreRequester;
|
|
607
|
+
function getImportCode(imports, options) {
|
|
608
|
+
let code = '';
|
|
609
|
+
for (const item of imports) {
|
|
610
|
+
const { importName, url, icss, type } = item;
|
|
611
|
+
if (options.esModule) {
|
|
612
|
+
if (icss && options.modules.namedExport) {
|
|
613
|
+
code += `import ${options.modules.exportOnlyLocals ? '' : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
code +=
|
|
617
|
+
type === 'url'
|
|
618
|
+
? `var ${importName} = new URL(${url}, import.meta.url);\n`
|
|
619
|
+
: `import ${importName} from ${url};\n`;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
code += `var ${importName} = require(${url});\n`;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return code ? `// Imports\n${code}` : '';
|
|
627
|
+
}
|
|
628
|
+
exports.getImportCode = getImportCode;
|
|
629
|
+
function normalizeParcelCssSourceMapForRuntime(map, loaderContext) {
|
|
630
|
+
let resultMap = null;
|
|
631
|
+
if (map instanceof Buffer) {
|
|
632
|
+
resultMap = JSON.parse(map.toString());
|
|
633
|
+
}
|
|
634
|
+
else if (typeof map === 'object') {
|
|
635
|
+
resultMap = map;
|
|
636
|
+
}
|
|
637
|
+
if (resultMap) {
|
|
638
|
+
delete resultMap.file;
|
|
639
|
+
/* eslint-disable no-underscore-dangle */
|
|
640
|
+
if (loaderContext._compilation &&
|
|
641
|
+
loaderContext._compilation.options &&
|
|
642
|
+
loaderContext._compilation.options.devtool &&
|
|
643
|
+
loaderContext._compilation.options.devtool.includes('nosources')) {
|
|
644
|
+
/* eslint-enable no-underscore-dangle */
|
|
645
|
+
delete resultMap.sourcesContent;
|
|
646
|
+
}
|
|
647
|
+
resultMap.sourceRoot = '';
|
|
648
|
+
// parseCss sourcesMap sources path is wrong, generate source by webpack
|
|
649
|
+
const contextifyPath = normalizePath(path_1.default.relative(loaderContext.rootContext, loaderContext.resourcePath));
|
|
650
|
+
resultMap.sources = [`webpack://./${contextifyPath}`];
|
|
651
|
+
}
|
|
652
|
+
return JSON.stringify(resultMap);
|
|
653
|
+
}
|
|
654
|
+
function printParams(media, dedupe, supports, layer) {
|
|
655
|
+
let result = '';
|
|
656
|
+
if (typeof layer !== 'undefined' && layer) {
|
|
657
|
+
result = `, ${JSON.stringify(layer)}`;
|
|
658
|
+
}
|
|
659
|
+
if (typeof supports !== 'undefined' && supports) {
|
|
660
|
+
result = `, ${JSON.stringify(supports)}${result}`;
|
|
661
|
+
}
|
|
662
|
+
else if (result.length > 0) {
|
|
663
|
+
result = `, undefined${result}`;
|
|
664
|
+
}
|
|
665
|
+
if (dedupe) {
|
|
666
|
+
result = `, true${result}`;
|
|
667
|
+
}
|
|
668
|
+
else if (result.length > 0) {
|
|
669
|
+
result = `, false${result}`;
|
|
670
|
+
}
|
|
671
|
+
if (media) {
|
|
672
|
+
result = `${JSON.stringify(media)}${result}`;
|
|
673
|
+
}
|
|
674
|
+
else if (result.length > 0) {
|
|
675
|
+
result = `""${result}`;
|
|
676
|
+
}
|
|
677
|
+
return result;
|
|
678
|
+
}
|
|
679
|
+
function getParcelCssModuleCode(result, api, replacements, options, loaderContext) {
|
|
680
|
+
if (options.modules.exportOnlyLocals === true) {
|
|
681
|
+
return '';
|
|
682
|
+
}
|
|
683
|
+
let sourceMapValue = '';
|
|
684
|
+
if (options.sourceMap) {
|
|
685
|
+
const sourceMap = result.map;
|
|
686
|
+
sourceMapValue = `,${normalizeParcelCssSourceMapForRuntime(sourceMap, loaderContext)}`;
|
|
687
|
+
}
|
|
688
|
+
let code = JSON.stringify(result.code.toString());
|
|
689
|
+
let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap
|
|
690
|
+
? '___CSS_LOADER_API_SOURCEMAP_IMPORT___'
|
|
691
|
+
: '___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___'});\n`;
|
|
692
|
+
for (const item of api) {
|
|
693
|
+
const { url, layer, supports, media, dedupe } = item;
|
|
694
|
+
if (url) {
|
|
695
|
+
// eslint-disable-next-line no-undefined
|
|
696
|
+
const printedParam = printParams(media, undefined, supports, layer);
|
|
697
|
+
beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${printedParam.length > 0 ? `, ${printedParam}` : ''}]);\n`;
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
const printedParam = printParams(media, dedupe, supports, layer);
|
|
701
|
+
beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${printedParam.length > 0 ? `, ${printedParam}` : ''});\n`;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
for (const item of replacements) {
|
|
705
|
+
const { replacementName, importName, localName, placeholder } = item;
|
|
706
|
+
if (localName) {
|
|
707
|
+
code = code.replace(new RegExp(replacementName, 'g'), () => options.modules.namedExport
|
|
708
|
+
? `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`
|
|
709
|
+
: `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
|
|
710
|
+
}
|
|
711
|
+
else {
|
|
712
|
+
const { hash, needQuotes, isString } = item;
|
|
713
|
+
if (isString) {
|
|
714
|
+
code = code.replace(new RegExp(placeholder, 'g'), () => `${replacementName}`);
|
|
715
|
+
}
|
|
716
|
+
else {
|
|
717
|
+
const getUrlOptions = []
|
|
718
|
+
.concat(hash ? [`hash: ${JSON.stringify(hash)}`] : [])
|
|
719
|
+
.concat(needQuotes ? 'needQuotes: true' : []);
|
|
720
|
+
const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
|
|
721
|
+
beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
|
|
722
|
+
}
|
|
723
|
+
code = code.replace(new RegExp(placeholder, 'g'), () => `" + ${replacementName} + "`);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
// Indexes description:
|
|
727
|
+
// 0 - module id
|
|
728
|
+
// 1 - CSS code
|
|
729
|
+
// 2 - media
|
|
730
|
+
// 3 - source map
|
|
731
|
+
// 4 - supports
|
|
732
|
+
// 5 - layer
|
|
733
|
+
return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
|
|
734
|
+
}
|
|
735
|
+
exports.getParcelCssModuleCode = getParcelCssModuleCode;
|
|
736
|
+
function dashesCamelCase(str) {
|
|
737
|
+
return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
|
|
738
|
+
}
|
|
739
|
+
function getExportCode(exports, replacements, icssPluginUsed, options) {
|
|
740
|
+
let code = '// Exports\n';
|
|
741
|
+
if (icssPluginUsed) {
|
|
742
|
+
let localsCode = '';
|
|
743
|
+
const addExportToLocalsCode = (names, value) => {
|
|
744
|
+
const normalizedNames = Array.isArray(names)
|
|
745
|
+
? new Set(names)
|
|
746
|
+
: new Set([names]);
|
|
747
|
+
for (const name of normalizedNames) {
|
|
748
|
+
if (options.modules.namedExport) {
|
|
749
|
+
localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
if (localsCode) {
|
|
753
|
+
localsCode += `,\n`;
|
|
754
|
+
}
|
|
755
|
+
localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
for (const { name, value } of exports) {
|
|
760
|
+
addExportToLocalsCode(options.modules.exportLocalsConvention(name), value);
|
|
761
|
+
}
|
|
762
|
+
for (const item of replacements) {
|
|
763
|
+
const { replacementName, localName, isString } = item;
|
|
764
|
+
if (isString) {
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
if (localName) {
|
|
768
|
+
const { importName } = item;
|
|
769
|
+
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => {
|
|
770
|
+
if (options.modules.namedExport) {
|
|
771
|
+
return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
|
|
772
|
+
}
|
|
773
|
+
else if (options.modules.exportOnlyLocals) {
|
|
774
|
+
return `" + ${importName}[${JSON.stringify(localName)}] + "`;
|
|
775
|
+
}
|
|
776
|
+
return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
localsCode = localsCode.replace(new RegExp(replacementName, 'g'), () => `" + ${replacementName} + "`);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (options.modules.exportOnlyLocals) {
|
|
784
|
+
code += options.modules.namedExport
|
|
785
|
+
? localsCode
|
|
786
|
+
: `${options.esModule ? 'export default' : 'module.exports ='} {\n${localsCode}\n};\n`;
|
|
787
|
+
return code;
|
|
788
|
+
}
|
|
789
|
+
code += options.modules.namedExport
|
|
790
|
+
? localsCode
|
|
791
|
+
: `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ''}};\n`;
|
|
792
|
+
}
|
|
793
|
+
const isCSSStyleSheetExport = options.exportType === 'css-style-sheet';
|
|
794
|
+
if (isCSSStyleSheetExport) {
|
|
795
|
+
code += 'var ___CSS_LOADER_STYLE_SHEET___ = new CSSStyleSheet();\n';
|
|
796
|
+
code +=
|
|
797
|
+
'___CSS_LOADER_STYLE_SHEET___.replaceSync(___CSS_LOADER_EXPORT___.toString());\n';
|
|
798
|
+
}
|
|
799
|
+
let finalExport;
|
|
800
|
+
switch (options.exportType) {
|
|
801
|
+
case 'string':
|
|
802
|
+
finalExport = '___CSS_LOADER_EXPORT___.toString()';
|
|
803
|
+
break;
|
|
804
|
+
case 'css-style-sheet':
|
|
805
|
+
finalExport = '___CSS_LOADER_STYLE_SHEET___';
|
|
806
|
+
break;
|
|
807
|
+
default:
|
|
808
|
+
case 'array':
|
|
809
|
+
finalExport = '___CSS_LOADER_EXPORT___';
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
code += `${options.esModule ? 'export default' : 'module.exports ='} ${finalExport};\n`;
|
|
813
|
+
return code;
|
|
814
|
+
}
|
|
815
|
+
exports.getExportCode = getExportCode;
|
|
816
|
+
function resolveRequests(resolve, context, possibleRequests) {
|
|
817
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
818
|
+
return resolve(context, possibleRequests[0])
|
|
819
|
+
.then(result => result)
|
|
820
|
+
.catch(error => {
|
|
821
|
+
const [, ...tailPossibleRequests] = possibleRequests;
|
|
822
|
+
if (tailPossibleRequests.length === 0) {
|
|
823
|
+
throw error;
|
|
824
|
+
}
|
|
825
|
+
return resolveRequests(resolve, context, tailPossibleRequests);
|
|
826
|
+
});
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
exports.resolveRequests = resolveRequests;
|
|
830
|
+
function isURLRequestable(url, options = {}) {
|
|
831
|
+
// Protocol-relative URLs
|
|
832
|
+
if (/^\/\//.test(url)) {
|
|
833
|
+
return { requestable: false, needResolve: false };
|
|
834
|
+
}
|
|
835
|
+
// `#` URLs
|
|
836
|
+
if (/^#/.test(url)) {
|
|
837
|
+
return { requestable: false, needResolve: false };
|
|
838
|
+
}
|
|
839
|
+
// Data URI
|
|
840
|
+
if (isDataUrl(url) && options.isSupportDataURL) {
|
|
841
|
+
try {
|
|
842
|
+
decodeURIComponent(url);
|
|
843
|
+
}
|
|
844
|
+
catch (ignoreError) {
|
|
845
|
+
return { requestable: false, needResolve: false };
|
|
846
|
+
}
|
|
847
|
+
return { requestable: true, needResolve: false };
|
|
848
|
+
}
|
|
849
|
+
// `file:` protocol
|
|
850
|
+
if (/^file:/i.test(url)) {
|
|
851
|
+
return { requestable: true, needResolve: true };
|
|
852
|
+
}
|
|
853
|
+
// Absolute URLs
|
|
854
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !NATIVE_WIN32_PATH.test(url)) {
|
|
855
|
+
if (options.isSupportAbsoluteURL && /^https?:/i.test(url)) {
|
|
856
|
+
return { requestable: true, needResolve: false };
|
|
857
|
+
}
|
|
858
|
+
return { requestable: false, needResolve: false };
|
|
859
|
+
}
|
|
860
|
+
return { requestable: true, needResolve: true };
|
|
861
|
+
}
|
|
862
|
+
exports.isURLRequestable = isURLRequestable;
|
|
863
|
+
function combineRequests(preRequest, url) {
|
|
864
|
+
const idx = url.indexOf('!=!');
|
|
865
|
+
return idx !== -1
|
|
866
|
+
? url.slice(0, idx + 3) + preRequest + url.slice(idx + 3)
|
|
867
|
+
: preRequest + url;
|
|
868
|
+
}
|
|
869
|
+
exports.combineRequests = combineRequests;
|