css-loader 5.2.6 → 6.2.0

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/dist/index.js CHANGED
@@ -5,14 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = loader;
7
7
 
8
- var _loaderUtils = require("loader-utils");
9
-
10
8
  var _postcss = _interopRequireDefault(require("postcss"));
11
9
 
12
10
  var _package = _interopRequireDefault(require("postcss/package.json"));
13
11
 
14
- var _schemaUtils = require("schema-utils");
15
-
16
12
  var _semver = require("semver");
17
13
 
18
14
  var _CssSyntaxError = _interopRequireDefault(require("./CssSyntaxError"));
@@ -32,11 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
32
28
  Author Tobias Koppers @sokra
33
29
  */
34
30
  async function loader(content, map, meta) {
35
- const rawOptions = (0, _loaderUtils.getOptions)(this);
36
- (0, _schemaUtils.validate)(_options.default, rawOptions, {
37
- name: "CSS Loader",
38
- baseDataPath: "options"
39
- });
31
+ const rawOptions = this.getOptions(_options.default);
40
32
  const plugins = [];
41
33
  const callback = this.async();
42
34
  let options;
@@ -60,39 +52,45 @@ async function loader(content, map, meta) {
60
52
 
61
53
  if ((0, _utils.shouldUseImportPlugin)(options)) {
62
54
  const resolver = this.getResolve({
55
+ dependencyType: "css",
63
56
  conditionNames: ["style"],
64
- extensions: [".css"],
65
57
  mainFields: ["css", "style", "main", "..."],
66
- mainFiles: ["index", "..."]
58
+ mainFiles: ["index", "..."],
59
+ extensions: [".css", "..."],
60
+ preferRelative: true
67
61
  });
68
62
  plugins.push((0, _plugins.importParser)({
69
63
  imports: importPluginImports,
70
64
  api: importPluginApi,
71
65
  context: this.context,
72
66
  rootContext: this.rootContext,
73
- filter: (0, _utils.getFilter)(options.import, this.resourcePath),
67
+ resourcePath: this.resourcePath,
68
+ filter: (0, _utils.getFilter)(options.import.filter, this.resourcePath),
74
69
  resolver,
75
- urlHandler: url => (0, _loaderUtils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
70
+ urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
76
71
  }));
77
72
  }
78
73
 
79
74
  const urlPluginImports = [];
80
75
 
81
76
  if ((0, _utils.shouldUseURLPlugin)(options)) {
82
- const urlResolver = this.getResolve({
83
- conditionNames: ["asset"],
84
- mainFields: ["asset"],
85
- mainFiles: [],
86
- extensions: []
87
- });
77
+ const needToResolveURL = !options.esModule;
78
+ const isSupportDataURLInNewURL = options.esModule && Boolean("fsStartTime" in this._compiler);
88
79
  plugins.push((0, _plugins.urlParser)({
89
80
  imports: urlPluginImports,
90
81
  replacements,
91
82
  context: this.context,
92
83
  rootContext: this.rootContext,
93
- filter: (0, _utils.getFilter)(options.url, this.resourcePath),
94
- resolver: urlResolver,
95
- urlHandler: url => (0, _loaderUtils.stringifyRequest)(this, url)
84
+ filter: (0, _utils.getFilter)(options.url.filter, this.resourcePath),
85
+ needToResolveURL,
86
+ resolver: needToResolveURL ? this.getResolve({
87
+ mainFiles: [],
88
+ extensions: []
89
+ }) : // eslint-disable-next-line no-undefined
90
+ undefined,
91
+ urlHandler: url => (0, _utils.stringifyRequest)(this, url),
92
+ // Support data urls as input in new URL added in webpack@5.38.0
93
+ isSupportDataURLInNewURL
96
94
  }));
97
95
  }
98
96
 
@@ -102,10 +100,12 @@ async function loader(content, map, meta) {
102
100
 
103
101
  if (needToUseIcssPlugin) {
104
102
  const icssResolver = this.getResolve({
103
+ dependencyType: "icss",
105
104
  conditionNames: ["style"],
106
- extensions: [],
105
+ extensions: ["..."],
107
106
  mainFields: ["css", "style", "main", "..."],
108
- mainFiles: ["index", "..."]
107
+ mainFiles: ["index", "..."],
108
+ preferRelative: true
109
109
  });
110
110
  plugins.push((0, _plugins.icssParser)({
111
111
  imports: icssPluginImports,
@@ -115,7 +115,7 @@ async function loader(content, map, meta) {
115
115
  context: this.context,
116
116
  rootContext: this.rootContext,
117
117
  resolver: icssResolver,
118
- urlHandler: url => (0, _loaderUtils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
118
+ urlHandler: url => (0, _utils.stringifyRequest)(this, (0, _utils.combineRequests)((0, _utils.getPreRequester)(this)(options.importLoaders), url))
119
119
  }));
120
120
  } // Reuse CSS AST (PostCSS AST e.g 'postcss-loader') to avoid reparsing
121
121
 
@@ -165,20 +165,30 @@ async function loader(content, map, meta) {
165
165
 
166
166
  if (options.modules.exportOnlyLocals !== true) {
167
167
  imports.unshift({
168
+ type: "api_import",
168
169
  importName: "___CSS_LOADER_API_IMPORT___",
169
- url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/api"))
170
+ url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/api"))
170
171
  });
171
172
 
172
173
  if (options.sourceMap) {
173
174
  imports.unshift({
175
+ type: "api_sourcemap_import",
174
176
  importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
175
- url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/cssWithMappingToString"))
177
+ url: (0, _utils.stringifyRequest)(this, require.resolve("./runtime/cssWithMappingToString"))
176
178
  });
177
179
  }
178
180
  }
179
181
 
180
182
  const importCode = (0, _utils.getImportCode)(imports, options);
181
- const moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
183
+ let moduleCode;
184
+
185
+ try {
186
+ moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
187
+ } catch (error) {
188
+ callback(error);
189
+ return;
190
+ }
191
+
182
192
  const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options);
183
193
  callback(null, `${importCode}${moduleCode}${exportCode}`);
184
194
  }
package/dist/options.json CHANGED
@@ -1,47 +1,60 @@
1
1
  {
2
+ "title": "CSS Loader options",
2
3
  "additionalProperties": false,
3
4
  "properties": {
4
5
  "url": {
5
- "description": "Enables/Disables 'url'/'image-set' functions handling (https://github.com/webpack-contrib/css-loader#url).",
6
+ "description": "Allows to enables/disables `url()`/`image-set()` functions handling.",
7
+ "link": "https://github.com/webpack-contrib/css-loader#url",
6
8
  "anyOf": [
7
9
  {
8
10
  "type": "boolean"
9
11
  },
10
12
  {
11
- "instanceof": "Function"
13
+ "type": "object",
14
+ "properties": {
15
+ "filter": {
16
+ "instanceof": "Function"
17
+ }
18
+ },
19
+ "additionalProperties": false
12
20
  }
13
21
  ]
14
22
  },
15
23
  "import": {
16
- "description": "Enables/Disables '@import' at-rules handling (https://github.com/webpack-contrib/css-loader#import).",
24
+ "description": "Allows to enables/disables `@import` at-rules handling.",
25
+ "link": "https://github.com/webpack-contrib/css-loader#import",
17
26
  "anyOf": [
18
27
  {
19
28
  "type": "boolean"
20
29
  },
21
30
  {
22
- "instanceof": "Function"
31
+ "type": "object",
32
+ "properties": {
33
+ "filter": {
34
+ "instanceof": "Function"
35
+ }
36
+ },
37
+ "additionalProperties": false
23
38
  }
24
39
  ]
25
40
  },
26
41
  "modules": {
27
- "description": "Enables/Disables CSS Modules and their configuration (https://github.com/webpack-contrib/css-loader#modules).",
42
+ "description": "Allows to enable/disable CSS Modules or ICSS and setup configuration.",
43
+ "link": "https://github.com/webpack-contrib/css-loader#modules",
28
44
  "anyOf": [
29
45
  {
30
46
  "type": "boolean"
31
47
  },
32
48
  {
33
- "enum": ["local", "global", "pure"]
49
+ "enum": ["local", "global", "pure", "icss"]
34
50
  },
35
51
  {
36
52
  "type": "object",
37
53
  "additionalProperties": false,
38
54
  "properties": {
39
- "compileType": {
40
- "description": "Controls the extent to which css-loader will process module code (https://github.com/webpack-contrib/css-loader#type)",
41
- "enum": ["module", "icss"]
42
- },
43
55
  "auto": {
44
- "description": "Allows auto enable CSS modules based on filename (https://github.com/webpack-contrib/css-loader#auto).",
56
+ "description": "Allows auto enable CSS modules based on filename.",
57
+ "link": "https://github.com/webpack-contrib/css-loader#auto",
45
58
  "anyOf": [
46
59
  {
47
60
  "instanceof": "RegExp"
@@ -55,10 +68,11 @@
55
68
  ]
56
69
  },
57
70
  "mode": {
58
- "description": "Setup `mode` option (https://github.com/webpack-contrib/css-loader#mode).",
71
+ "description": "Setup `mode` option.",
72
+ "link": "https://github.com/webpack-contrib/css-loader#mode",
59
73
  "anyOf": [
60
74
  {
61
- "enum": ["local", "global", "pure"]
75
+ "enum": ["local", "global", "pure", "icss"]
62
76
  },
63
77
  {
64
78
  "instanceof": "Function"
@@ -66,22 +80,43 @@
66
80
  ]
67
81
  },
68
82
  "localIdentName": {
69
- "description": "Allows to configure the generated local ident name (https://github.com/webpack-contrib/css-loader#localidentname).",
83
+ "description": "Allows to configure the generated local ident name.",
84
+ "link": "https://github.com/webpack-contrib/css-loader#localidentname",
70
85
  "type": "string",
71
86
  "minLength": 1
72
87
  },
73
88
  "localIdentContext": {
74
- "description": "Allows to redefine basic loader context for local ident name (https://github.com/webpack-contrib/css-loader#localidentcontext).",
89
+ "description": "Allows to redefine basic loader context for local ident name.",
90
+ "link": "https://github.com/webpack-contrib/css-loader#localidentcontext",
91
+ "type": "string",
92
+ "minLength": 1
93
+ },
94
+ "localIdentHashSalt": {
95
+ "description": "Allows to add custom hash to generate more unique classes.",
96
+ "link": "https://github.com/webpack-contrib/css-loader#localidenthashsalt",
97
+ "type": "string",
98
+ "minLength": 1
99
+ },
100
+ "localIdentHashFunction": {
101
+ "description": "Allows to specify hash function to generate classes.",
102
+ "link": "https://github.com/webpack-contrib/css-loader#localidenthashfunction",
75
103
  "type": "string",
76
104
  "minLength": 1
77
105
  },
78
- "localIdentHashPrefix": {
79
- "description": "Allows to add custom hash to generate more unique classes (https://github.com/webpack-contrib/css-loader#localidenthashprefix).",
106
+ "localIdentHashDigest": {
107
+ "description": "Allows to specify hash digest to generate classes.",
108
+ "link": "https://github.com/webpack-contrib/css-loader#localidenthashdigest",
80
109
  "type": "string",
81
110
  "minLength": 1
82
111
  },
112
+ "localIdentHashDigestLength": {
113
+ "description": "Allows to specify hash digest length to generate classes.",
114
+ "link": "https://github.com/webpack-contrib/css-loader#localidenthashdigestlength",
115
+ "type": "number"
116
+ },
83
117
  "localIdentRegExp": {
84
- "description": "Allows to specify custom RegExp for local ident name (https://github.com/webpack-contrib/css-loader#localidentregexp).",
118
+ "description": "Allows to specify custom RegExp for local ident name.",
119
+ "link": "https://github.com/webpack-contrib/css-loader#localidentregexp",
85
120
  "anyOf": [
86
121
  {
87
122
  "type": "string",
@@ -93,29 +128,41 @@
93
128
  ]
94
129
  },
95
130
  "getLocalIdent": {
96
- "description": "Allows to specify a function to generate the classname (https://github.com/webpack-contrib/css-loader#getlocalident).",
131
+ "description": "Allows to specify a function to generate the classname.",
132
+ "link": "https://github.com/webpack-contrib/css-loader#getlocalident",
97
133
  "instanceof": "Function"
98
134
  },
99
135
  "namedExport": {
100
- "description": "Enables/disables ES modules named export for locals (https://github.com/webpack-contrib/css-loader#namedexport).",
136
+ "description": "Enables/disables ES modules named export for locals.",
137
+ "link": "https://github.com/webpack-contrib/css-loader#namedexport",
101
138
  "type": "boolean"
102
139
  },
103
140
  "exportGlobals": {
104
- "description": "Allows to export names from global class or id, so you can use that as local name (https://github.com/webpack-contrib/css-loader#exportglobals).",
141
+ "description": "Allows to export names from global class or id, so you can use that as local name.",
142
+ "link": "https://github.com/webpack-contrib/css-loader#exportglobals",
105
143
  "type": "boolean"
106
144
  },
107
145
  "exportLocalsConvention": {
108
- "description": "Style of exported classnames (https://github.com/webpack-contrib/css-loader#localsconvention).",
109
- "enum": [
110
- "asIs",
111
- "camelCase",
112
- "camelCaseOnly",
113
- "dashes",
114
- "dashesOnly"
146
+ "description": "Style of exported classnames.",
147
+ "link": "https://github.com/webpack-contrib/css-loader#localsconvention",
148
+ "anyOf": [
149
+ {
150
+ "enum": [
151
+ "asIs",
152
+ "camelCase",
153
+ "camelCaseOnly",
154
+ "dashes",
155
+ "dashesOnly"
156
+ ]
157
+ },
158
+ {
159
+ "instanceof": "Function"
160
+ }
115
161
  ]
116
162
  },
117
163
  "exportOnlyLocals": {
118
- "description": "Export only locals (https://github.com/webpack-contrib/css-loader#exportonlylocals).",
164
+ "description": "Export only locals.",
165
+ "link": "https://github.com/webpack-contrib/css-loader#exportonlylocals",
119
166
  "type": "boolean"
120
167
  }
121
168
  }
@@ -123,11 +170,13 @@
123
170
  ]
124
171
  },
125
172
  "sourceMap": {
126
- "description": "Enables/Disables generation of source maps (https://github.com/webpack-contrib/css-loader#sourcemap).",
173
+ "description": "Allows to enable/disable source maps.",
174
+ "link": "https://github.com/webpack-contrib/css-loader#sourcemap",
127
175
  "type": "boolean"
128
176
  },
129
177
  "importLoaders": {
130
- "description": "Enables/Disables or setups number of loaders applied before CSS loader (https://github.com/webpack-contrib/css-loader#importloaders).",
178
+ "description": "Allows enables/disables or setups number of loaders applied before CSS loader for `@import`/CSS Modules and ICSS imports.",
179
+ "link": "https://github.com/webpack-contrib/css-loader#importloaders",
131
180
  "anyOf": [
132
181
  {
133
182
  "type": "boolean"
@@ -141,7 +190,8 @@
141
190
  ]
142
191
  },
143
192
  "esModule": {
144
- "description": "Use the ES modules syntax (https://github.com/webpack-contrib/css-loader#esmodule).",
193
+ "description": "Use the ES modules syntax.",
194
+ "link": "https://github.com/webpack-contrib/css-loader#esmodule",
145
195
  "type": "boolean"
146
196
  }
147
197
  },
@@ -81,6 +81,7 @@ const plugin = (options = {}) => {
81
81
  importName = `___CSS_LOADER_ICSS_IMPORT_${imports.size}___`;
82
82
  imports.set(importKey, importName);
83
83
  options.imports.push({
84
+ type: "icss_import",
84
85
  importName,
85
86
  url: options.urlHandler(newUrl),
86
87
  icss: true,
@@ -171,6 +171,11 @@ const plugin = (options = {}) => {
171
171
  return;
172
172
  }
173
173
 
174
+ if (resolvedUrl === options.resourcePath) {
175
+ atRule.remove();
176
+ return;
177
+ }
178
+
174
179
  atRule.remove(); // eslint-disable-next-line consistent-return
175
180
 
176
181
  return {
@@ -226,6 +231,7 @@ const plugin = (options = {}) => {
226
231
  importName = `___CSS_LOADER_AT_RULE_IMPORT_${urlToNameMap.size}___`;
227
232
  urlToNameMap.set(newUrl, importName);
228
233
  options.imports.push({
234
+ type: "rule_import",
229
235
  importName,
230
236
  url: options.urlHandler(newUrl),
231
237
  index
@@ -49,7 +49,7 @@ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
49
49
  return matched && matched[2] === "true";
50
50
  }
51
51
 
52
- function shouldHandleURL(url, declaration, result) {
52
+ function shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL) {
53
53
  if (url.length === 0) {
54
54
  result.warn(`Unable to find uri in '${declaration.toString()}'`, {
55
55
  node: declaration
@@ -57,6 +57,16 @@ function shouldHandleURL(url, declaration, result) {
57
57
  return false;
58
58
  }
59
59
 
60
+ if ((0, _utils.isDataUrl)(url) && isSupportDataURLInNewURL) {
61
+ try {
62
+ decodeURIComponent(url);
63
+ } catch (ignoreError) {
64
+ return false;
65
+ }
66
+
67
+ return true;
68
+ }
69
+
60
70
  if (!(0, _utils.isUrlRequestable)(url)) {
61
71
  return false;
62
72
  }
@@ -64,7 +74,7 @@ function shouldHandleURL(url, declaration, result) {
64
74
  return true;
65
75
  }
66
76
 
67
- function parseDeclaration(declaration, key, result) {
77
+ function parseDeclaration(declaration, key, result, isSupportDataURLInNewURL) {
68
78
  if (!needParseDeclaration.test(declaration[key])) {
69
79
  return;
70
80
  }
@@ -118,7 +128,7 @@ function parseDeclaration(declaration, key, result) {
118
128
  let url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
119
129
  url = (0, _utils.normalizeUrl)(url, isStringValue); // Do not traverse inside `url`
120
130
 
121
- if (!shouldHandleURL(url, declaration, result)) {
131
+ if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
122
132
  // eslint-disable-next-line consistent-return
123
133
  return false;
124
134
  }
@@ -168,7 +178,7 @@ function parseDeclaration(declaration, key, result) {
168
178
  let url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
169
179
  url = (0, _utils.normalizeUrl)(url, isStringValue); // Do not traverse inside `url`
170
180
 
171
- if (!shouldHandleURL(url, declaration, result)) {
181
+ if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
172
182
  // eslint-disable-next-line consistent-return
173
183
  return false;
174
184
  }
@@ -204,7 +214,7 @@ function parseDeclaration(declaration, key, result) {
204
214
 
205
215
  let url = (0, _utils.normalizeUrl)(value, true); // Do not traverse inside `url`
206
216
 
207
- if (!shouldHandleURL(url, declaration, result)) {
217
+ if (!shouldHandleURL(url, declaration, result, isSupportDataURLInNewURL)) {
208
218
  // eslint-disable-next-line consistent-return
209
219
  return false;
210
220
  }
@@ -245,7 +255,10 @@ const plugin = (options = {}) => {
245
255
  const parsedDeclarations = [];
246
256
  return {
247
257
  Declaration(declaration) {
248
- const parsedURL = parseDeclaration(declaration, "value", result);
258
+ const {
259
+ isSupportDataURLInNewURL
260
+ } = options;
261
+ const parsedURL = parseDeclaration(declaration, "value", result, isSupportDataURLInNewURL);
249
262
 
250
263
  if (!parsedURL) {
251
264
  return;
@@ -268,15 +281,34 @@ const plugin = (options = {}) => {
268
281
  const needKeep = await options.filter(url);
269
282
 
270
283
  if (!needKeep) {
284
+ // eslint-disable-next-line consistent-return
271
285
  return;
272
286
  }
273
287
  }
274
288
 
289
+ if ((0, _utils.isDataUrl)(url)) {
290
+ // eslint-disable-next-line consistent-return
291
+ return parsedDeclaration;
292
+ }
293
+
275
294
  const splittedUrl = url.split(/(\?)?#/);
276
295
  const [pathname, query, hashOrQuery] = splittedUrl;
277
296
  let hash = query ? "?" : "";
278
297
  hash += hashOrQuery ? `#${hashOrQuery}` : "";
279
- const request = (0, _utils.requestify)(pathname, options.rootContext);
298
+ const {
299
+ needToResolveURL,
300
+ rootContext
301
+ } = options;
302
+ const request = (0, _utils.requestify)(pathname, rootContext, needToResolveURL);
303
+
304
+ if (!needToResolveURL) {
305
+ // eslint-disable-next-line consistent-return
306
+ return { ...parsedDeclaration,
307
+ url: request,
308
+ hash
309
+ };
310
+ }
311
+
280
312
  const {
281
313
  resolver,
282
314
  context
@@ -284,6 +316,7 @@ const plugin = (options = {}) => {
284
316
  const resolvedUrl = await (0, _utils.resolveRequests)(resolver, context, [...new Set([request, url])]);
285
317
 
286
318
  if (!resolvedUrl) {
319
+ // eslint-disable-next-line consistent-return
287
320
  return;
288
321
  } // eslint-disable-next-line consistent-return
289
322
 
@@ -307,6 +340,7 @@ const plugin = (options = {}) => {
307
340
 
308
341
  if (!hasUrlImportHelper) {
309
342
  options.imports.push({
343
+ type: "get_url_import",
310
344
  importName: "___CSS_LOADER_GET_URL_IMPORT___",
311
345
  url: options.urlHandler(require.resolve("../runtime/getUrl.js")),
312
346
  index: -1
@@ -325,8 +359,9 @@ const plugin = (options = {}) => {
325
359
  importName = `___CSS_LOADER_URL_IMPORT_${urlToNameMap.size}___`;
326
360
  urlToNameMap.set(newUrl, importName);
327
361
  options.imports.push({
362
+ type: "url",
328
363
  importName,
329
- url: options.urlHandler(newUrl),
364
+ url: options.needToResolveURL ? options.urlHandler(newUrl) : JSON.stringify(newUrl),
330
365
  index
331
366
  });
332
367
  }
@@ -8,7 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
 
9
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
10
 
11
- function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
12
 
13
13
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
@@ -17,6 +17,10 @@ module.exports = function cssWithMappingToString(item) {
17
17
  content = _item[1],
18
18
  cssMapping = _item[3];
19
19
 
20
+ if (!cssMapping) {
21
+ return content;
22
+ }
23
+
20
24
  if (typeof btoa === "function") {
21
25
  // eslint-disable-next-line no-undef
22
26
  var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
@@ -4,15 +4,14 @@ module.exports = function (url, options) {
4
4
  if (!options) {
5
5
  // eslint-disable-next-line no-param-reassign
6
6
  options = {};
7
- } // eslint-disable-next-line no-underscore-dangle, no-param-reassign
8
-
9
-
10
- url = url && url.__esModule ? url.default : url;
7
+ }
11
8
 
12
- if (typeof url !== "string") {
9
+ if (!url) {
13
10
  return url;
14
- } // If url is already wrapped in quotes, remove them
11
+ } // eslint-disable-next-line no-underscore-dangle, no-param-reassign
12
+
15
13
 
14
+ url = String(url.__esModule ? url.default : url); // If url is already wrapped in quotes, remove them
16
15
 
17
16
  if (/^['"].*['"]$/.test(url)) {
18
17
  // eslint-disable-next-line no-param-reassign
@@ -26,7 +25,7 @@ module.exports = function (url, options) {
26
25
  // See https://drafts.csswg.org/css-values-3/#urls
27
26
 
28
27
 
29
- if (/["'() \t\n]/.test(url) || options.needQuotes) {
28
+ if (/["'() \t\n]|(%20)/.test(url) || options.needQuotes) {
30
29
  return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
31
30
  }
32
31