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 | query: loaderUtils.parseQuery(this.resourceQuery || '?') || {}
|
20 | });
|
21 | }
|
22 |
|
23 | if (!types.includes(options.type)) {
|
24 | return this.callback('The given `type` option is invalid. \n\n' + "Expected:\n One of scoped|global|resolve \n\n" + 'Actual:\n ' + options.type);
|
25 | }
|
26 |
|
27 |
|
28 | var commentType = content.match(/\/*\s*@styled-jsx=(scoped|global|resolve)/);
|
29 |
|
30 | if (commentType) {
|
31 | options.type = commentType[1];
|
32 | }
|
33 |
|
34 | var output = "import css from 'styled-jsx/css';\n\nexport default css";
|
35 |
|
36 | if (options.type === 'global') {
|
37 |
|
38 | output += '.global';
|
39 | } else if (options.type === 'resolve') {
|
40 |
|
41 | output += '.resolve';
|
42 | }
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | output += "`" + content.replace(/[`\\]/g, function (match) {
|
48 | return '\\' + match;
|
49 | }) + "`";
|
50 | this.callback(null, output);
|
51 | }; |
\ | No newline at end of file |