css-loader 5.0.0 → 5.1.1

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.
@@ -14,16 +14,16 @@ class CssSyntaxError extends Error {
14
14
  column,
15
15
  file
16
16
  } = error;
17
- this.name = 'CssSyntaxError'; // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
17
+ this.name = "CssSyntaxError"; // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
18
18
  // We don't need `plugin` and `file` properties.
19
19
 
20
20
  this.message = `${this.name}\n\n`;
21
21
 
22
- if (typeof line !== 'undefined') {
22
+ if (typeof line !== "undefined") {
23
23
  this.message += `(${line}:${column}) `;
24
24
  }
25
25
 
26
- this.message += file ? `${file} ` : '<css input> ';
26
+ this.message += file ? `${file} ` : "<css input> ";
27
27
  this.message += `${reason}`;
28
28
  const code = error.showSourceCode();
29
29
 
package/dist/Warning.js CHANGED
@@ -13,12 +13,12 @@ class Warning extends Error {
13
13
  line,
14
14
  column
15
15
  } = warning;
16
- this.name = 'Warning'; // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
16
+ this.name = "Warning"; // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
17
17
  // We don't need `plugin` properties.
18
18
 
19
19
  this.message = `${this.name}\n\n`;
20
20
 
21
- if (typeof line !== 'undefined') {
21
+ if (typeof line !== "undefined") {
22
22
  this.message += `(${line}:${column}) `;
23
23
  }
24
24
 
package/dist/cjs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
 
3
- const loader = require('./index');
3
+ const loader = require("./index");
4
4
 
5
5
  module.exports = loader.default;
package/dist/index.js CHANGED
@@ -34,8 +34,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
34
34
  async function loader(content, map, meta) {
35
35
  const rawOptions = (0, _loaderUtils.getOptions)(this);
36
36
  (0, _schemaUtils.validate)(_options.default, rawOptions, {
37
- name: 'CSS Loader',
38
- baseDataPath: 'options'
37
+ name: "CSS Loader",
38
+ baseDataPath: "options"
39
39
  });
40
40
  const plugins = [];
41
41
  const callback = this.async();
@@ -60,10 +60,10 @@ async function loader(content, map, meta) {
60
60
 
61
61
  if ((0, _utils.shouldUseImportPlugin)(options)) {
62
62
  const resolver = this.getResolve({
63
- conditionNames: ['style'],
64
- extensions: ['.css'],
65
- mainFields: ['css', 'style', 'main', '...'],
66
- mainFiles: ['index', '...'],
63
+ conditionNames: ["style"],
64
+ extensions: [".css"],
65
+ mainFields: ["css", "style", "main", "..."],
66
+ mainFiles: ["index", "..."],
67
67
  restrictions: [/\.css$/i]
68
68
  });
69
69
  plugins.push((0, _plugins.importParser)({
@@ -81,8 +81,8 @@ async function loader(content, map, meta) {
81
81
 
82
82
  if ((0, _utils.shouldUseURLPlugin)(options)) {
83
83
  const urlResolver = this.getResolve({
84
- conditionNames: ['asset'],
85
- mainFields: ['asset'],
84
+ conditionNames: ["asset"],
85
+ mainFields: ["asset"],
86
86
  mainFiles: [],
87
87
  extensions: []
88
88
  });
@@ -102,10 +102,10 @@ async function loader(content, map, meta) {
102
102
 
103
103
  if ((0, _utils.shouldUseIcssPlugin)(options)) {
104
104
  const icssResolver = this.getResolve({
105
- conditionNames: ['style'],
105
+ conditionNames: ["style"],
106
106
  extensions: [],
107
- mainFields: ['css', 'style', 'main', '...'],
108
- mainFiles: ['index', '...']
107
+ mainFields: ["css", "style", "main", "..."],
108
+ mainFiles: ["index", "..."]
109
109
  });
110
110
  plugins.push((0, _plugins.icssParser)({
111
111
  imports: icssPluginImports,
@@ -125,7 +125,7 @@ async function loader(content, map, meta) {
125
125
  ast
126
126
  } = meta;
127
127
 
128
- if (ast && ast.type === 'postcss' && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
128
+ if (ast && ast.type === "postcss" && (0, _semver.satisfies)(ast.version, `^${_package.default.version}`)) {
129
129
  // eslint-disable-next-line no-param-reassign
130
130
  content = ast.root;
131
131
  }
@@ -152,7 +152,7 @@ async function loader(content, map, meta) {
152
152
  this.addDependency(error.file);
153
153
  }
154
154
 
155
- callback(error.name === 'CssSyntaxError' ? new _CssSyntaxError.default(error) : error);
155
+ callback(error.name === "CssSyntaxError" ? new _CssSyntaxError.default(error) : error);
156
156
  return;
157
157
  }
158
158
 
@@ -165,14 +165,14 @@ async function loader(content, map, meta) {
165
165
 
166
166
  if (options.modules.exportOnlyLocals !== true) {
167
167
  imports.unshift({
168
- importName: '___CSS_LOADER_API_IMPORT___',
169
- url: (0, _loaderUtils.stringifyRequest)(this, require.resolve('./runtime/api'))
168
+ importName: "___CSS_LOADER_API_IMPORT___",
169
+ url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/api"))
170
170
  });
171
171
 
172
172
  if (options.sourceMap) {
173
173
  imports.unshift({
174
- importName: '___CSS_LOADER_API_SOURCEMAP_IMPORT___',
175
- url: (0, _loaderUtils.stringifyRequest)(this, require.resolve('./runtime/cssWithMappingToString'))
174
+ importName: "___CSS_LOADER_API_SOURCEMAP_IMPORT___",
175
+ url: (0, _loaderUtils.stringifyRequest)(this, require.resolve("./runtime/cssWithMappingToString"))
176
176
  });
177
177
  }
178
178
  }
@@ -11,7 +11,7 @@ var _utils = require("../utils");
11
11
 
12
12
  const plugin = (options = {}) => {
13
13
  return {
14
- postcssPlugin: 'postcss-icss-parser',
14
+ postcssPlugin: "postcss-icss-parser",
15
15
 
16
16
  async OnceExit(root) {
17
17
  const importReplacements = Object.create(null);
@@ -31,12 +31,12 @@ const plugin = (options = {}) => {
31
31
  }
32
32
 
33
33
  let normalizedUrl = url;
34
- let prefix = '';
35
- const queryParts = normalizedUrl.split('!');
34
+ let prefix = "";
35
+ const queryParts = normalizedUrl.split("!");
36
36
 
37
37
  if (queryParts.length > 1) {
38
38
  normalizedUrl = queryParts.pop();
39
- prefix = queryParts.join('!');
39
+ prefix = queryParts.join("!");
40
40
  }
41
41
 
42
42
  const request = (0, _utils.requestify)((0, _utils.normalizeUrl)(normalizedUrl, true), options.rootContext);
@@ -13,8 +13,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  function visitor(result, parsedResults, node, key) {
15
15
  // Convert only top-level @import
16
- if (node.parent.type !== 'root') {
16
+ if (node.parent.type !== "root") {
17
17
  return;
18
+ }
19
+
20
+ if (node.raws && node.raws.afterName && node.raws.afterName.trim().length > 0) {
21
+ const lastCommentIndex = node.raws.afterName.lastIndexOf("/*");
22
+ const matched = node.raws.afterName.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
23
+
24
+ if (matched && matched[2] === "true") {
25
+ return;
26
+ }
27
+ }
28
+
29
+ const prevNode = node.prev();
30
+
31
+ if (prevNode && prevNode.type === "comment") {
32
+ const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
33
+
34
+ if (matched && matched[2] === "true") {
35
+ return;
36
+ }
18
37
  } // Nodes do not exists - `@import url('http://') :root {}`
19
38
 
20
39
 
@@ -30,7 +49,7 @@ function visitor(result, parsedResults, node, key) {
30
49
  } = (0, _postcssValueParser.default)(node[key]); // No nodes - `@import ;`
31
50
  // Invalid type - `@import foo-bar;`
32
51
 
33
- if (paramsNodes.length === 0 || paramsNodes[0].type !== 'string' && paramsNodes[0].type !== 'function') {
52
+ if (paramsNodes.length === 0 || paramsNodes[0].type !== "string" && paramsNodes[0].type !== "function") {
34
53
  result.warn(`Unable to find uri in "${node.toString()}"`, {
35
54
  node
36
55
  });
@@ -40,19 +59,19 @@ function visitor(result, parsedResults, node, key) {
40
59
  let isStringValue;
41
60
  let url;
42
61
 
43
- if (paramsNodes[0].type === 'string') {
62
+ if (paramsNodes[0].type === "string") {
44
63
  isStringValue = true;
45
64
  url = paramsNodes[0].value;
46
65
  } else {
47
66
  // Invalid function - `@import nourl(test.css);`
48
- if (paramsNodes[0].value.toLowerCase() !== 'url') {
67
+ if (paramsNodes[0].value.toLowerCase() !== "url") {
49
68
  result.warn(`Unable to find uri in "${node.toString()}"`, {
50
69
  node
51
70
  });
52
71
  return;
53
72
  }
54
73
 
55
- isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === 'string';
74
+ isStringValue = paramsNodes[0].nodes.length !== 0 && paramsNodes[0].nodes[0].type === "string";
56
75
  url = isStringValue ? paramsNodes[0].nodes[0].value : _postcssValueParser.default.stringify(paramsNodes[0].nodes);
57
76
  } // Empty url - `@import "";` or `@import url();`
58
77
 
@@ -74,14 +93,14 @@ function visitor(result, parsedResults, node, key) {
74
93
 
75
94
  const plugin = (options = {}) => {
76
95
  return {
77
- postcssPlugin: 'postcss-import-parser',
96
+ postcssPlugin: "postcss-import-parser",
78
97
 
79
98
  prepare(result) {
80
99
  const parsedResults = [];
81
100
  return {
82
101
  AtRule: {
83
102
  import(atRule) {
84
- visitor(result, parsedResults, atRule, 'params');
103
+ visitor(result, parsedResults, atRule, "params");
85
104
  }
86
105
 
87
106
  },
@@ -102,15 +121,15 @@ const plugin = (options = {}) => {
102
121
  mediaNodes
103
122
  } = parsedResult;
104
123
  let normalizedUrl = url;
105
- let prefix = '';
124
+ let prefix = "";
106
125
  const isRequestable = (0, _utils.isUrlRequestable)(normalizedUrl);
107
126
 
108
127
  if (isRequestable) {
109
- const queryParts = normalizedUrl.split('!');
128
+ const queryParts = normalizedUrl.split("!");
110
129
 
111
130
  if (queryParts.length > 1) {
112
131
  normalizedUrl = queryParts.pop();
113
- prefix = queryParts.join('!');
132
+ prefix = queryParts.join("!");
114
133
  }
115
134
 
116
135
  normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue); // Empty url after normalize - `@import '\
@@ -21,7 +21,7 @@ function getNodeFromUrlFunc(node) {
21
21
 
22
22
  function shouldHandleRule(rule, node, result) {
23
23
  // https://www.w3.org/TR/css-syntax-3/#typedef-url-token
24
- if (rule.url.replace(/^[\s]+|[\s]+$/g, '').length === 0) {
24
+ if (rule.url.replace(/^[\s]+|[\s]+$/g, "").length === 0) {
25
25
  result.warn(`Unable to find uri in '${node.toString()}'`, {
26
26
  node
27
27
  });
@@ -35,22 +35,86 @@ function shouldHandleRule(rule, node, result) {
35
35
  return true;
36
36
  }
37
37
 
38
+ function getWebpackIgnoreCommentValue(index, nodes, inBetween) {
39
+ if (index === 0 && typeof inBetween !== "undefined") {
40
+ return inBetween;
41
+ }
42
+
43
+ let prevValueNode = nodes[index - 1];
44
+
45
+ if (!prevValueNode) {
46
+ // eslint-disable-next-line consistent-return
47
+ return;
48
+ }
49
+
50
+ if (prevValueNode.type === "space") {
51
+ if (!nodes[index - 2]) {
52
+ // eslint-disable-next-line consistent-return
53
+ return;
54
+ }
55
+
56
+ prevValueNode = nodes[index - 2];
57
+ }
58
+
59
+ if (prevValueNode.type !== "comment") {
60
+ // eslint-disable-next-line consistent-return
61
+ return;
62
+ }
63
+
64
+ const matched = prevValueNode.value.match(_utils.webpackIgnoreCommentRegexp);
65
+ return matched && matched[2] === "true";
66
+ }
67
+
38
68
  function visitor(result, parsedResults, node, key) {
39
69
  if (!needParseDeclaration.test(node[key])) {
40
70
  return;
41
71
  }
42
72
 
43
- const parsed = (0, _postcssValueParser.default)(node[key]);
44
- parsed.walk(valueNode => {
45
- if (valueNode.type !== 'function') {
73
+ const parsed = (0, _postcssValueParser.default)(node.raws && node.raws.value && node.raws.value.raw ? node.raws.value.raw : node[key]);
74
+ let inBetween;
75
+
76
+ if (node.raws && node.raws.between) {
77
+ const lastCommentIndex = node.raws.between.lastIndexOf("/*");
78
+ const matched = node.raws.between.slice(lastCommentIndex).match(_utils.webpackIgnoreCommentRegexp);
79
+
80
+ if (matched) {
81
+ inBetween = matched[2] === "true";
82
+ }
83
+ }
84
+
85
+ let isIgnoreOnDeclaration = false;
86
+ const prevNode = node.prev();
87
+
88
+ if (prevNode && prevNode.type === "comment") {
89
+ const matched = prevNode.text.match(_utils.webpackIgnoreCommentRegexp);
90
+
91
+ if (matched) {
92
+ isIgnoreOnDeclaration = matched[2] === "true";
93
+ }
94
+ }
95
+
96
+ let needIgnore;
97
+ parsed.walk((valueNode, index, valueNodes) => {
98
+ if (valueNode.type !== "function") {
46
99
  return;
47
100
  }
48
101
 
49
102
  if (isUrlFunc.test(valueNode.value)) {
103
+ needIgnore = getWebpackIgnoreCommentValue(index, valueNodes, inBetween);
104
+
105
+ if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
106
+ if (needIgnore) {
107
+ // eslint-disable-next-line no-undefined
108
+ needIgnore = undefined;
109
+ }
110
+
111
+ return;
112
+ }
113
+
50
114
  const {
51
115
  nodes
52
116
  } = valueNode;
53
- const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
117
+ const isStringValue = nodes.length !== 0 && nodes[0].type === "string";
54
118
  const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
55
119
  const rule = {
56
120
  node: getNodeFromUrlFunc(valueNode),
@@ -71,17 +135,29 @@ function visitor(result, parsedResults, node, key) {
71
135
 
72
136
  return false;
73
137
  } else if (isImageSetFunc.test(valueNode.value)) {
74
- for (const nNode of valueNode.nodes) {
138
+ for (const [innerIndex, nNode] of valueNode.nodes.entries()) {
75
139
  const {
76
140
  type,
77
141
  value
78
142
  } = nNode;
79
143
 
80
- if (type === 'function' && isUrlFunc.test(value)) {
144
+ if (type === "function" && isUrlFunc.test(value)) {
145
+ needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
146
+
147
+ if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
148
+ if (needIgnore) {
149
+ // eslint-disable-next-line no-undefined
150
+ needIgnore = undefined;
151
+ } // eslint-disable-next-line no-continue
152
+
153
+
154
+ continue;
155
+ }
156
+
81
157
  const {
82
158
  nodes
83
159
  } = nNode;
84
- const isStringValue = nodes.length !== 0 && nodes[0].type === 'string';
160
+ const isStringValue = nodes.length !== 0 && nodes[0].type === "string";
85
161
  const url = isStringValue ? nodes[0].value : _postcssValueParser.default.stringify(nodes);
86
162
  const rule = {
87
163
  node: getNodeFromUrlFunc(nNode),
@@ -97,7 +173,19 @@ function visitor(result, parsedResults, node, key) {
97
173
  parsed
98
174
  });
99
175
  }
100
- } else if (type === 'string') {
176
+ } else if (type === "string") {
177
+ needIgnore = getWebpackIgnoreCommentValue(innerIndex, valueNode.nodes);
178
+
179
+ if (isIgnoreOnDeclaration && typeof needIgnore === "undefined" || needIgnore) {
180
+ if (needIgnore) {
181
+ // eslint-disable-next-line no-undefined
182
+ needIgnore = undefined;
183
+ } // eslint-disable-next-line no-continue
184
+
185
+
186
+ continue;
187
+ }
188
+
101
189
  const rule = {
102
190
  node: nNode,
103
191
  url: value,
@@ -124,13 +212,13 @@ function visitor(result, parsedResults, node, key) {
124
212
 
125
213
  const plugin = (options = {}) => {
126
214
  return {
127
- postcssPlugin: 'postcss-url-parser',
215
+ postcssPlugin: "postcss-url-parser",
128
216
 
129
217
  prepare(result) {
130
218
  const parsedResults = [];
131
219
  return {
132
220
  Declaration(declaration) {
133
- visitor(result, parsedResults, declaration, 'value');
221
+ visitor(result, parsedResults, declaration, "value");
134
222
  },
135
223
 
136
224
  async OnceExit() {
@@ -149,12 +237,12 @@ const plugin = (options = {}) => {
149
237
  isStringValue
150
238
  } = parsedResult.rule;
151
239
  let normalizedUrl = url;
152
- let prefix = '';
153
- const queryParts = normalizedUrl.split('!');
240
+ let prefix = "";
241
+ const queryParts = normalizedUrl.split("!");
154
242
 
155
243
  if (queryParts.length > 1) {
156
244
  normalizedUrl = queryParts.pop();
157
- prefix = queryParts.join('!');
245
+ prefix = queryParts.join("!");
158
246
  }
159
247
 
160
248
  normalizedUrl = (0, _utils.normalizeUrl)(normalizedUrl, isStringValue);
@@ -166,8 +254,8 @@ const plugin = (options = {}) => {
166
254
 
167
255
  if (!hasUrlImportHelper) {
168
256
  options.imports.push({
169
- importName: '___CSS_LOADER_GET_URL_IMPORT___',
170
- url: options.urlHandler(require.resolve('../runtime/getUrl.js')),
257
+ importName: "___CSS_LOADER_GET_URL_IMPORT___",
258
+ url: options.urlHandler(require.resolve("../runtime/getUrl.js")),
171
259
  index: -1
172
260
  });
173
261
  hasUrlImportHelper = true;
@@ -175,8 +263,8 @@ const plugin = (options = {}) => {
175
263
 
176
264
  const splittedUrl = normalizedUrl.split(/(\?)?#/);
177
265
  const [pathname, query, hashOrQuery] = splittedUrl;
178
- let hash = query ? '?' : '';
179
- hash += hashOrQuery ? `#${hashOrQuery}` : '';
266
+ let hash = query ? "?" : "";
267
+ hash += hashOrQuery ? `#${hashOrQuery}` : "";
180
268
  const request = (0, _utils.requestify)(pathname, options.rootContext);
181
269
  tasks.push((async () => {
182
270
  const {
@@ -242,7 +330,7 @@ const plugin = (options = {}) => {
242
330
  } // eslint-disable-next-line no-param-reassign
243
331
 
244
332
 
245
- rule.node.type = 'word'; // eslint-disable-next-line no-param-reassign
333
+ rule.node.type = "word"; // eslint-disable-next-line no-param-reassign
246
334
 
247
335
  rule.node.value = replacementName; // eslint-disable-next-line no-param-reassign
248
336
 
@@ -18,15 +18,15 @@ module.exports = function (cssWithMappingToString) {
18
18
  }
19
19
 
20
20
  return content;
21
- }).join('');
21
+ }).join("");
22
22
  }; // import a list of modules into the list
23
23
  // eslint-disable-next-line func-names
24
24
 
25
25
 
26
26
  list.i = function (modules, mediaQuery, dedupe) {
27
- if (typeof modules === 'string') {
27
+ if (typeof modules === "string") {
28
28
  // eslint-disable-next-line no-param-reassign
29
- modules = [[null, modules, '']];
29
+ modules = [[null, modules, ""]];
30
30
  }
31
31
 
32
32
  var alreadyImportedModules = {};
@@ -17,16 +17,16 @@ module.exports = function cssWithMappingToString(item) {
17
17
  content = _item[1],
18
18
  cssMapping = _item[3];
19
19
 
20
- if (typeof btoa === 'function') {
20
+ if (typeof btoa === "function") {
21
21
  // eslint-disable-next-line no-undef
22
22
  var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping))));
23
23
  var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64);
24
24
  var sourceMapping = "/*# ".concat(data, " */");
25
25
  var sourceURLs = cssMapping.sources.map(function (source) {
26
- return "/*# sourceURL=".concat(cssMapping.sourceRoot || '').concat(source, " */");
26
+ return "/*# sourceURL=".concat(cssMapping.sourceRoot || "").concat(source, " */");
27
27
  });
28
- return [content].concat(sourceURLs).concat([sourceMapping]).join('\n');
28
+ return [content].concat(sourceURLs).concat([sourceMapping]).join("\n");
29
29
  }
30
30
 
31
- return [content].join('\n');
31
+ return [content].join("\n");
32
32
  };
@@ -9,7 +9,7 @@ module.exports = function (url, options) {
9
9
 
10
10
  url = url && url.__esModule ? url.default : url;
11
11
 
12
- if (typeof url !== 'string') {
12
+ if (typeof url !== "string") {
13
13
  return url;
14
14
  } // If url is already wrapped in quotes, remove them
15
15
 
@@ -27,7 +27,7 @@ module.exports = function (url, options) {
27
27
 
28
28
 
29
29
  if (/["'() \t\n]/.test(url) || options.needQuotes) {
30
- return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, '\\n'), "\"");
30
+ return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, "\\n"), "\"");
31
31
  }
32
32
 
33
33
  return url;