forked from ili-ili/next.js-style-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (30 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint no-invalid-this:0 */
'use strict';
var _loaderUtils = require('loader-utils');
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function loader(content, sourceMap) {
var _this = this;
this.cacheable && this.cacheable();
// Grab the content from the css-loader
if (content.indexOf('module.exports =') !== -1) {
content = this.exec(content, this.resource);
// Otherwise it's a css string
} else {
content = [[this.resourcePath, content, '', sourceMap]];
}
// Preserve CSS modules locals
var out = content.locals ? content.locals : {};
// Generate _nextStyles that will be used by applyStyles()
out._nextStyles = content.map(function (entry) {
var relativePath = _path2.default.relative(_this._compiler.context, entry[0]);
return {
id: (0, _loaderUtils.getHashDigest)(relativePath, 'md5', 'hex'),
content: entry[1],
sourceMap: entry[3]
};
});
return 'module.exports = ' + JSON.stringify(out) + ';';
}
module.exports = loader;