css-loader 3.0.0 → 3.3.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.
@@ -9,8 +9,6 @@ var _postcss = _interopRequireDefault(require("postcss"));
9
9
 
10
10
  var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
11
 
12
- var _utils = require("../utils");
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
13
 
16
14
  const pluginName = 'postcss-url-parser';
@@ -56,7 +54,7 @@ function walkUrls(parsed, callback) {
56
54
  });
57
55
  }
58
56
 
59
- function getUrlsFromValue(value, result, filter, decl = null) {
57
+ function getUrlsFromValue(value, result, filter, decl) {
60
58
  if (!needParseDecl.test(value)) {
61
59
  return;
62
60
  }
@@ -65,9 +63,9 @@ function getUrlsFromValue(value, result, filter, decl = null) {
65
63
  const urls = [];
66
64
  walkUrls(parsed, (node, url, needQuotes) => {
67
65
  if (url.trim().replace(/\\[\r\n]/g, '').length === 0) {
68
- result.warn(`Unable to find uri in '${decl ? decl.toString() : value}'`, decl ? {
66
+ result.warn(`Unable to find uri in '${decl ? decl.toString() : value}'`, {
69
67
  node: decl
70
- } : {});
68
+ });
71
69
  return;
72
70
  }
73
71
 
@@ -75,8 +73,12 @@ function getUrlsFromValue(value, result, filter, decl = null) {
75
73
  return;
76
74
  }
77
75
 
76
+ const [normalizedUrl, singleQuery, hashValue] = url.split(/(\?)?#/);
77
+ const hash = singleQuery || hashValue ? `${singleQuery ? '?' : ''}${hashValue ? `#${hashValue}` : ''}` : '';
78
78
  urls.push({
79
- url,
79
+ node,
80
+ url: normalizedUrl,
81
+ hash,
80
82
  needQuotes
81
83
  });
82
84
  }); // eslint-disable-next-line consistent-return
@@ -87,16 +89,12 @@ function getUrlsFromValue(value, result, filter, decl = null) {
87
89
  };
88
90
  }
89
91
 
90
- function walkDeclsWithUrl(css, result, filter) {
92
+ function walkDecls(css, result, filter) {
91
93
  const items = [];
92
94
  css.walkDecls(decl => {
93
95
  const item = getUrlsFromValue(decl.value, result, filter, decl);
94
96
 
95
- if (!item) {
96
- return;
97
- }
98
-
99
- if (item.urls.length === 0) {
97
+ if (!item || item.urls.length === 0) {
100
98
  return;
101
99
  }
102
100
 
@@ -109,67 +107,82 @@ function walkDeclsWithUrl(css, result, filter) {
109
107
  return items;
110
108
  }
111
109
 
112
- var _default = _postcss.default.plugin(pluginName, (options = {}) => function process(css, result) {
113
- const traversed = walkDeclsWithUrl(css, result, options.filter);
114
- const paths = (0, _utils.uniqWith)((0, _utils.flatten)(traversed.map(item => item.urls)), (value, other) => value.url === other.url && value.needQuotes === other.needQuotes);
110
+ function flatten(array) {
111
+ return array.reduce((a, b) => a.concat(b), []);
112
+ }
115
113
 
116
- if (paths.length === 0) {
117
- return;
118
- }
114
+ function collectUniqueUrlsWithNodes(array) {
115
+ return array.reduce((accumulator, currentValue) => {
116
+ const {
117
+ url,
118
+ needQuotes,
119
+ hash,
120
+ node
121
+ } = currentValue;
122
+ const found = accumulator.find(item => url === item.url && needQuotes === item.needQuotes && hash === item.hash);
123
+
124
+ if (!found) {
125
+ accumulator.push({
126
+ url,
127
+ hash,
128
+ needQuotes,
129
+ nodes: [node]
130
+ });
131
+ } else {
132
+ found.nodes.push(node);
133
+ }
134
+
135
+ return accumulator;
136
+ }, []);
137
+ }
119
138
 
120
- const placeholders = [];
121
- let hasUrlHelper = false;
139
+ var _default = _postcss.default.plugin(pluginName, options => function process(css, result) {
140
+ const traversed = walkDecls(css, result, options.filter);
141
+ const paths = collectUniqueUrlsWithNodes(flatten(traversed.map(item => item.urls)));
142
+ const replacers = new Map();
122
143
  paths.forEach((path, index) => {
123
- const {
124
- loaderContext
125
- } = options;
126
- const placeholder = `___CSS_LOADER_URL___${index}___`;
127
144
  const {
128
145
  url,
129
- needQuotes
146
+ hash,
147
+ needQuotes,
148
+ nodes
130
149
  } = path;
131
- placeholders.push({
132
- placeholder,
133
- path
134
- });
135
-
136
- if (!hasUrlHelper) {
137
- result.messages.push({
138
- pluginName,
139
- type: 'import',
140
- import: (0, _utils.getUrlHelperCode)(loaderContext)
141
- }); // eslint-disable-next-line no-param-reassign
142
-
143
- hasUrlHelper = true;
144
- }
145
-
150
+ const name = `___CSS_LOADER_URL_IMPORT_${index}___`;
146
151
  result.messages.push({
147
152
  pluginName,
148
153
  type: 'import',
149
- import: (0, _utils.getUrlItemCode)({
154
+ value: {
155
+ type: 'url',
156
+ name,
150
157
  url,
151
- placeholder,
152
- needQuotes
153
- }, loaderContext),
154
- importType: 'url',
155
- placeholder
158
+ needQuotes,
159
+ hash,
160
+ index
161
+ }
162
+ }, {
163
+ pluginName,
164
+ type: 'replacer',
165
+ value: {
166
+ type: 'url',
167
+ name
168
+ }
169
+ });
170
+ nodes.forEach(node => {
171
+ replacers.set(node, name);
156
172
  });
157
173
  });
158
174
  traversed.forEach(item => {
159
- walkUrls(item.parsed, (node, url, needQuotes) => {
160
- const value = placeholders.find(placeholder => placeholder.path.url === url && placeholder.path.needQuotes === needQuotes);
175
+ walkUrls(item.parsed, node => {
176
+ const name = replacers.get(node);
161
177
 
162
- if (!value) {
178
+ if (!name) {
163
179
  return;
164
- }
180
+ } // eslint-disable-next-line no-param-reassign
165
181
 
166
- const {
167
- placeholder
168
- } = value; // eslint-disable-next-line no-param-reassign
169
182
 
170
183
  node.type = 'word'; // eslint-disable-next-line no-param-reassign
171
184
 
172
- node.value = placeholder;
185
+ node.value = name;
173
186
  }); // eslint-disable-next-line no-param-reassign
174
187
 
175
188
  item.decl.value = item.parsed.toString();
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
 
3
- module.exports = function (url, needQuotes) {
3
+ module.exports = function (url, options) {
4
+ if (!options) {
5
+ // eslint-disable-next-line no-param-reassign
6
+ options = {};
7
+ } // eslint-disable-next-line no-underscore-dangle, no-param-reassign
8
+
9
+
10
+ url = url && url.__esModule ? url.default : url;
11
+
4
12
  if (typeof url !== 'string') {
5
13
  return url;
6
14
  } // If url is already wrapped in quotes, remove them
@@ -9,11 +17,16 @@ module.exports = function (url, needQuotes) {
9
17
  if (/^['"].*['"]$/.test(url)) {
10
18
  // eslint-disable-next-line no-param-reassign
11
19
  url = url.slice(1, -1);
20
+ }
21
+
22
+ if (options.hash) {
23
+ // eslint-disable-next-line no-param-reassign
24
+ url += options.hash;
12
25
  } // Should url be wrapped?
13
26
  // See https://drafts.csswg.org/css-values-3/#urls
14
27
 
15
28
 
16
- if (/["'() \t\n]/.test(url) || needQuotes) {
29
+ if (/["'() \t\n]/.test(url) || options.needQuotes) {
17
30
  return "\"".concat(url.replace(/"/g, '\\"').replace(/\n/g, '\\n'), "\"");
18
31
  }
19
32
 
package/dist/utils.js CHANGED
@@ -3,23 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.uniqWith = uniqWith;
7
- exports.flatten = flatten;
8
- exports.dashesCamelCase = dashesCamelCase;
9
- exports.getImportPrefix = getImportPrefix;
10
- exports.getLocalIdent = getLocalIdent;
11
6
  exports.getFilter = getFilter;
12
7
  exports.getModulesPlugins = getModulesPlugins;
13
8
  exports.normalizeSourceMap = normalizeSourceMap;
14
- exports.getImportItemCode = getImportItemCode;
15
- exports.getUrlHelperCode = getUrlHelperCode;
16
- exports.getUrlItemCode = getUrlItemCode;
17
9
  exports.getApiCode = getApiCode;
18
10
  exports.getImportCode = getImportCode;
19
11
  exports.getModuleCode = getModuleCode;
20
- exports.getExportItemCode = getExportItemCode;
21
12
  exports.getExportCode = getExportCode;
22
- exports.prepareCode = prepareCode;
23
13
 
24
14
  var _path = _interopRequireDefault(require("path"));
25
15
 
@@ -39,7 +29,9 @@ var _postcssModulesScope = _interopRequireDefault(require("postcss-modules-scope
39
29
 
40
30
  var _camelcase = _interopRequireDefault(require("camelcase"));
41
31
 
42
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
32
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
33
+
34
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
43
35
 
44
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
37
 
@@ -47,18 +39,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
47
39
  MIT License http://www.opensource.org/licenses/mit-license.php
48
40
  Author Tobias Koppers @sokra
49
41
  */
50
- function uniqWith(array, comparator) {
51
- return array.reduce((acc, d) => !acc.some(item => comparator(d, item)) ? [...acc, d] : acc, []);
52
- }
53
-
54
- function flatten(array) {
55
- return array.reduce((a, b) => a.concat(b), []);
56
- }
57
-
58
- function dashesCamelCase(str) {
59
- return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
60
- }
61
-
62
42
  function getImportPrefix(loaderContext, importLoaders) {
63
43
  if (importLoaders === false) {
64
44
  return '';
@@ -86,7 +66,13 @@ function unescape(str) {
86
66
  String.fromCharCode(high >> 10 | 0xd800, high & 0x3ff | 0xdc00);
87
67
  /* eslint-enable line-comment-position */
88
68
  });
89
- }
69
+ } // eslint-disable-next-line no-control-regex
70
+
71
+
72
+ const filenameReservedRegex = /[<>:"/\\|?*\x00-\x1F]/g; // eslint-disable-next-line no-control-regex
73
+
74
+ const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
75
+ const reRelativePath = /^\.+/;
90
76
 
91
77
  function getLocalIdent(loaderContext, localIdentName, localName, options) {
92
78
  if (!options.context) {
@@ -100,7 +86,7 @@ function getLocalIdent(loaderContext, localIdentName, localName, options) {
100
86
  // Also directories can contains invalid characters for css we need escape their too
101
87
 
102
88
  return (0, _cssesc.default)(_loaderUtils.default.interpolateName(loaderContext, localIdentName, options) // For `[hash]` placeholder
103
- .replace(/^((-?[0-9])|--)/, '_$1'), {
89
+ .replace(/^((-?[0-9])|--)/, '_$1').replace(filenameReservedRegex, '-').replace(reControlChars, '-').replace(reRelativePath, '-').replace(/\./g, '-'), {
104
90
  isIdentifier: true
105
91
  }).replace(/\\\[local\\\]/gi, localName);
106
92
  }
@@ -124,7 +110,6 @@ function getModulesPlugins(options, loaderContext) {
124
110
  mode: 'local',
125
111
  localIdentName: '[hash:base64]',
126
112
  getLocalIdent,
127
- context: null,
128
113
  hashPrefix: '',
129
114
  localIdentRegExp: null
130
115
  };
@@ -139,11 +124,21 @@ function getModulesPlugins(options, loaderContext) {
139
124
  mode: modulesOptions.mode
140
125
  }), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
141
126
  generateScopedName: function generateScopedName(exportName) {
142
- return modulesOptions.getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
127
+ let localIdent = modulesOptions.getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
143
128
  context: modulesOptions.context,
144
129
  hashPrefix: modulesOptions.hashPrefix,
145
130
  regExp: modulesOptions.localIdentRegExp
146
131
  });
132
+
133
+ if (!localIdent) {
134
+ localIdent = getLocalIdent(loaderContext, modulesOptions.localIdentName, exportName, {
135
+ context: modulesOptions.context,
136
+ hashPrefix: modulesOptions.hashPrefix,
137
+ regExp: modulesOptions.localIdentRegExp
138
+ });
139
+ }
140
+
141
+ return localIdent;
147
142
  }
148
143
  })];
149
144
  }
@@ -173,158 +168,170 @@ function normalizeSourceMap(map) {
173
168
  return newMap;
174
169
  }
175
170
 
176
- function getImportItemCode(item, loaderContext, importPrefix) {
177
- const {
178
- url
179
- } = item;
180
- const media = item.media || '';
181
-
182
- if (!(0, _loaderUtils.isUrlRequest)(url)) {
183
- return `exports.push([module.id, ${JSON.stringify(`@import url(${url});`)}, ${JSON.stringify(media)}]);`;
184
- }
185
-
186
- const importUrl = importPrefix + (0, _loaderUtils.urlToRequest)(url);
187
- return `exports.i(require(${(0, _loaderUtils.stringifyRequest)(loaderContext, importUrl)}), ${JSON.stringify(media)});`;
188
- }
189
-
190
- function getUrlHelperCode(loaderContext) {
191
- return `var getUrl = require(${(0, _loaderUtils.stringifyRequest)(loaderContext, require.resolve('./runtime/getUrl.js'))});`;
192
- }
193
-
194
- function getUrlItemCode(item, loaderContext) {
195
- const {
196
- url,
197
- placeholder,
198
- needQuotes
199
- } = item; // Remove `#hash` and `?#hash` from `require`
200
-
201
- const [normalizedUrl, singleQuery, hashValue] = url.split(/(\?)?#/);
202
- const hash = singleQuery || hashValue ? `"${singleQuery ? '?' : ''}${hashValue ? `#${hashValue}` : ''}"` : '';
203
- return `var ${placeholder} = getUrl(require(${(0, _loaderUtils.stringifyRequest)(loaderContext, (0, _loaderUtils.urlToRequest)(normalizedUrl))})${hash ? ` + ${hash}` : ''}${needQuotes ? ', true' : ''});`;
171
+ function getApiCode(loaderContext, sourceMap) {
172
+ const url = (0, _loaderUtils.stringifyRequest)(loaderContext, require.resolve('./runtime/api'));
173
+ return `exports = module.exports = require(${url})(${sourceMap});\n`;
204
174
  }
205
175
 
206
- function getApiCode(loaderContext, sourceMap, onlyLocals) {
207
- if (onlyLocals) {
208
- return '';
209
- }
210
-
211
- return `exports = module.exports = require(${(0, _loaderUtils.stringifyRequest)(loaderContext, require.resolve('./runtime/api'))})(${sourceMap});\n`;
212
- }
213
-
214
- function getImportCode(importItems, onlyLocals) {
215
- if (importItems.length === 0 || onlyLocals) {
216
- return '';
217
- }
218
-
219
- return `// Imports\n${importItems.join('\n')}\n`;
220
- }
221
-
222
- function getModuleCode(result, sourceMap, onlyLocals) {
223
- if (onlyLocals) {
224
- return '';
225
- }
226
-
227
- return `// Module\nexports.push([module.id, ${JSON.stringify(result.css)}, ""${sourceMap && result.map ? `,${result.map}` : ''}]);\n`;
228
- }
229
-
230
- function getExportItemCode(key, value, localsConvention) {
231
- let targetKey;
232
- const items = [];
233
-
234
- function addEntry(k) {
235
- items.push(`\t${JSON.stringify(k)}: ${JSON.stringify(value)}`);
236
- }
237
-
238
- switch (localsConvention) {
239
- case 'camelCase':
240
- addEntry(key);
241
- targetKey = (0, _camelcase.default)(key);
242
-
243
- if (targetKey !== key) {
244
- addEntry(targetKey);
176
+ function getImportCode(loaderContext, imports, options) {
177
+ const importItems = [];
178
+ const codeItems = [];
179
+ const urlImportNames = new Map();
180
+ let hasUrlHelperCode = false;
181
+ let importPrefix;
182
+ imports.forEach(item => {
183
+ if (item.type === '@import' || item.type === 'icss-import') {
184
+ const media = item.media ? `, ${JSON.stringify(item.media)}` : '';
185
+
186
+ if (!(0, _loaderUtils.isUrlRequest)(item.url)) {
187
+ const url = JSON.stringify(`@import url(${item.url});`);
188
+ codeItems.push(`exports.push([module.id, ${url}${media}]);`);
189
+ return;
245
190
  }
246
191
 
247
- break;
248
-
249
- case 'camelCaseOnly':
250
- addEntry((0, _camelcase.default)(key));
251
- break;
192
+ if (!importPrefix) {
193
+ importPrefix = getImportPrefix(loaderContext, options.importLoaders);
194
+ }
252
195
 
253
- case 'dashes':
254
- addEntry(key);
255
- targetKey = dashesCamelCase(key);
196
+ const url = (0, _loaderUtils.stringifyRequest)(loaderContext, importPrefix + (0, _loaderUtils.urlToRequest)(item.url));
197
+ importItems.push(`var ${item.name} = require(${url});`);
256
198
 
257
- if (targetKey !== key) {
258
- addEntry(targetKey);
199
+ if (options.exportType === 'full') {
200
+ codeItems.push(`exports.i(${item.name}${media});`);
259
201
  }
202
+ }
260
203
 
261
- break;
204
+ if (item.type === 'url') {
205
+ if (!hasUrlHelperCode) {
206
+ const pathToGetUrl = require.resolve('./runtime/getUrl.js');
262
207
 
263
- case 'dashesOnly':
264
- addEntry(dashesCamelCase(key));
265
- break;
208
+ const url = (0, _loaderUtils.stringifyRequest)(loaderContext, pathToGetUrl);
209
+ importItems.push(`var ___CSS_LOADER_GET_URL_IMPORT___ = require(${url});`);
210
+ hasUrlHelperCode = true;
211
+ }
266
212
 
267
- case 'asIs':
268
- default:
269
- addEntry(key);
270
- break;
271
- }
213
+ const {
214
+ name,
215
+ url,
216
+ hash,
217
+ needQuotes,
218
+ index
219
+ } = item;
220
+ let importName = urlImportNames.get(url);
221
+
222
+ if (!importName) {
223
+ const preparedUrl = (0, _loaderUtils.stringifyRequest)(loaderContext, (0, _loaderUtils.urlToRequest)(url));
224
+ importName = `___CSS_LOADER_URL_PURE_IMPORT_${index}___`;
225
+ importItems.push(`var ${importName} = require(${preparedUrl});`);
226
+ urlImportNames.set(url, importName);
227
+ }
272
228
 
273
- return items.join(',\n');
229
+ const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? 'needQuotes: true' : []);
230
+ const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(', ')} }` : '';
231
+ codeItems.push(`var ${name} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});`);
232
+ }
233
+ });
234
+ return `// Imports\n${importItems.join('\n')}\n${codeItems.join('\n')}\n`;
274
235
  }
275
236
 
276
- function getExportCode(exportItems, onlyLocals) {
277
- if (exportItems.length === 0) {
278
- return '';
279
- }
237
+ function getModuleCode(loaderContext, result, replacers, sourceMap) {
238
+ const {
239
+ css,
240
+ map
241
+ } = result;
242
+ const sourceMapValue = sourceMap && map ? `,${map}` : '';
243
+ let cssCode = JSON.stringify(css);
244
+ replacers.forEach(replacer => {
245
+ const {
246
+ type,
247
+ name
248
+ } = replacer;
249
+
250
+ if (type === 'url') {
251
+ cssCode = cssCode.replace(new RegExp(name, 'g'), () => `" + ${name} + "`);
252
+ }
280
253
 
281
- return `// Exports\n${onlyLocals ? 'module.exports' : 'exports.locals'} = {\n${exportItems.join(',\n')}\n};`;
254
+ if (type === 'icss-import') {
255
+ const {
256
+ importName,
257
+ localName
258
+ } = replacer;
259
+ cssCode = cssCode.replace(new RegExp(name, 'g'), () => `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
260
+ }
261
+ });
262
+ return `// Module\nexports.push([module.id, ${cssCode}, ""${sourceMapValue}]);\n`;
282
263
  }
283
264
 
284
- function getIcssReplacer(item, loaderContext, importPrefix, onlyLocals) {
285
- const importUrl = importPrefix + (0, _loaderUtils.urlToRequest)(item.url);
286
- return () => onlyLocals ? `" + require(${(0, _loaderUtils.stringifyRequest)(loaderContext, importUrl)})[${JSON.stringify(item.export)}] + "` : `" + require(${(0, _loaderUtils.stringifyRequest)(loaderContext, importUrl)}).locals[${JSON.stringify(item.export)}] + "`;
265
+ function dashesCamelCase(str) {
266
+ return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
287
267
  }
288
268
 
289
- function prepareCode(file, messages, loaderContext, importPrefix, onlyLocals) {
290
- const {
291
- apiCode,
292
- importCode
293
- } = file;
294
- let {
295
- moduleCode,
296
- exportCode
297
- } = file;
298
- messages.filter(message => message.type === 'icss-import' || message.type === 'import' && message.importType === 'url').forEach(message => {
299
- // Replace all urls on `require`
300
- if (message.type === 'import') {
301
- const {
302
- placeholder
303
- } = message;
304
-
305
- if (moduleCode) {
306
- // eslint-disable-next-line no-param-reassign
307
- moduleCode = moduleCode.replace(new RegExp(placeholder, 'g'), () => `" + ${placeholder} + "`);
308
- }
309
- } // Replace external ICSS import on `require`
269
+ function getExportCode(loaderContext, exports, replacers, options) {
270
+ const items = [];
310
271
 
272
+ function addExportedItem(name, value) {
273
+ items.push(`\t${JSON.stringify(name)}: ${JSON.stringify(value)}`);
274
+ }
311
275
 
312
- if (message.type === 'icss-import') {
276
+ exports.forEach(item => {
277
+ const {
278
+ name,
279
+ value
280
+ } = item;
281
+
282
+ switch (options.localsConvention) {
283
+ case 'camelCase':
284
+ {
285
+ addExportedItem(name, value);
286
+ const modifiedName = (0, _camelcase.default)(name);
287
+
288
+ if (modifiedName !== name) {
289
+ addExportedItem(modifiedName, value);
290
+ }
291
+
292
+ break;
293
+ }
294
+
295
+ case 'camelCaseOnly':
296
+ {
297
+ addExportedItem((0, _camelcase.default)(name), value);
298
+ break;
299
+ }
300
+
301
+ case 'dashes':
302
+ {
303
+ addExportedItem(name, value);
304
+ const modifiedName = dashesCamelCase(name);
305
+
306
+ if (modifiedName !== name) {
307
+ addExportedItem(modifiedName, value);
308
+ }
309
+
310
+ break;
311
+ }
312
+
313
+ case 'dashesOnly':
314
+ {
315
+ addExportedItem(dashesCamelCase(name), value);
316
+ break;
317
+ }
318
+
319
+ case 'asIs':
320
+ default:
321
+ addExportedItem(name, value);
322
+ break;
323
+ }
324
+ });
325
+ let exportCode = `// Exports\n${options.exportType === 'locals' ? 'module.exports' : 'exports.locals'} = {\n${items.join(',\n')}\n};`;
326
+ replacers.forEach(replacer => {
327
+ if (replacer.type === 'icss-import') {
313
328
  const {
314
- item
315
- } = message;
316
- const replacer = getIcssReplacer(item, loaderContext, importPrefix, onlyLocals);
317
-
318
- if (moduleCode) {
319
- // eslint-disable-next-line no-param-reassign
320
- moduleCode = moduleCode.replace(new RegExp(`___CSS_LOADER_IMPORT___(${item.index})___`, 'g'), replacer);
321
- }
322
-
323
- if (exportCode) {
324
- // eslint-disable-next-line no-param-reassign
325
- exportCode = exportCode.replace(new RegExp(`___CSS_LOADER_IMPORT___(${item.index})___`, 'g'), replacer);
326
- }
329
+ name,
330
+ importName
331
+ } = replacer;
332
+ const localName = JSON.stringify(replacer.localName);
333
+ exportCode = exportCode.replace(new RegExp(name, 'g'), () => options.exportType === 'locals' ? `" + ${importName}[${localName}] + "` : `" + ${importName}.locals[${localName}] + "`);
327
334
  }
328
335
  });
329
- return [apiCode, importCode, moduleCode, exportCode].filter(Boolean).join('');
336
+ return exportCode;
330
337
  }