1 | "use strict";
|
2 |
|
3 | var loaderUtils = require('loader-utils');
|
4 |
|
5 | var types = ['scoped', 'global', 'resolve'];
|
6 |
|
7 | module.exports = function (content) {
|
8 | if (this.cacheable) this.cacheable();
|
9 | this.addDependency(this.resourcePath);
|
10 | var options = Object.assign({}, loaderUtils.getOptions(this));
|
11 |
|
12 | if (!options.type) {
|
13 | options.type = 'scoped';
|
14 | }
|
15 |
|
16 |
|
17 | if (typeof options.type === 'function') {
|
18 | options.type = options.type(this.resourcePath);
|
19 | }
|
20 |
|
21 | if (!types.includes(options.type)) {
|
22 | return this.callback('The given `type` option is invalid. \n\n' + "Expected:\n One of scoped|global|resolve \n\n" + 'Actual:\n ' + options.type);
|
23 | }
|
24 |
|
25 |
|
26 | var commentType = content.match(/\/*\s*@styled-jsx=(scoped|global|resolve)/);
|
27 |
|
28 | if (commentType) {
|
29 | options.type = commentType[1];
|
30 | }
|
31 |
|
32 | var output = "import css from 'styled-jsx/css';\n\nexport default css";
|
33 |
|
34 | if (options.type === 'global') {
|
35 |
|
36 | output += '.global';
|
37 | } else if (options.type === 'resolve') {
|
38 |
|
39 | output += '.resolve';
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | output += "`".concat(content.replace(/[`\\]/g, function (match) {
|
46 | return '\\' + match;
|
47 | }), "`");
|
48 | this.callback(null, output);
|
49 | }; |
\ | No newline at end of file |