@@ -13,6 +13,7 @@ import {
13
13
getStyleTagTransformFn ,
14
14
getExportStyleCode ,
15
15
getExportLazyStyleCode ,
16
+ getSetAttributesCode ,
16
17
} from "./utils" ;
17
18
18
19
import schema from "./options.json" ;
@@ -37,39 +38,6 @@ loaderAPI.pitch = function loader(request) {
37
38
base : options . base ,
38
39
} ;
39
40
40
- let setAttributesFn ;
41
-
42
- if ( typeof options . attributes !== "undefined" ) {
43
- setAttributesFn =
44
- typeof options . attributes . nonce === "undefined"
45
- ? `function(style, attributes) {
46
- var nonce =
47
- typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null;
48
-
49
- if (nonce) {
50
- attributes.nonce = nonce;
51
- }
52
-
53
- Object.keys(attributes).forEach((key) => {
54
- style.setAttribute(key, attributes[key]);
55
- });
56
- }`
57
- : `function(style, attributes) {
58
- Object.keys(attributes).forEach((key) => {
59
- style.setAttribute(key, attributes[key]);
60
- });
61
- }` ;
62
- } else {
63
- setAttributesFn = `function(style) {
64
- var nonce =
65
- typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null;
66
-
67
- if (nonce) {
68
- style.setAttribute("nonce", nonce);
69
- }
70
- }` ;
71
- }
72
-
73
41
const insertFn = insertIsFunction
74
42
? options . insert . toString ( )
75
43
: `function(style){
@@ -139,6 +107,7 @@ ${esModule ? "export default {}" : ""}`;
139
107
${ getImportStyleAPICode ( esModule , this ) }
140
108
${ getImportStyleDomAPICode ( esModule , this , isSingleton , isAuto ) }
141
109
${ getImportGetTargetCode ( esModule , this , insertIsFunction ) }
110
+ ${ getSetAttributesCode ( esModule , this , options ) }
142
111
${ getImportInsertStyleElementCode ( esModule , this ) }
143
112
${ getImportStyleContentCode ( esModule , this , request ) }
144
113
${ isAuto ? getImportIsOldIECode ( esModule , this ) : "" }
@@ -158,7 +127,7 @@ var update;
158
127
var options = ${ JSON . stringify ( runtimeOptions ) } ;
159
128
160
129
${ getStyleTagTransformFn ( styleTagTransformFn , isSingleton ) } ;
161
- options.setAttributes = ${ setAttributesFn } ;
130
+ options.setAttributes = setAttributes ;
162
131
options.insert = ${ insertFn } ;
163
132
options.domAPI = ${ getdomAPI ( isAuto ) } ;
164
133
options.insertStyleElement = insertStyleElement;
@@ -197,6 +166,7 @@ ${getExportLazyStyleCode(esModule, this, request)}
197
166
${ getImportStyleAPICode ( esModule , this ) }
198
167
${ getImportStyleDomAPICode ( esModule , this , isSingleton , isAuto ) }
199
168
${ getImportGetTargetCode ( esModule , this , insertIsFunction ) }
169
+ ${ getSetAttributesCode ( esModule , this , options ) }
200
170
${ getImportInsertStyleElementCode ( esModule , this ) }
201
171
${ getImportStyleContentCode ( esModule , this , request ) }
202
172
${ isAuto ? getImportIsOldIECode ( esModule , this ) : "" }
@@ -209,7 +179,7 @@ ${getExportLazyStyleCode(esModule, this, request)}
209
179
var options = ${ JSON . stringify ( runtimeOptions ) } ;
210
180
211
181
${ getStyleTagTransformFn ( styleTagTransformFn , isSingleton ) } ;
212
- options.setAttributes = ${ setAttributesFn } ;
182
+ options.setAttributes = setAttributes ;
213
183
options.insert = ${ insertFn } ;
214
184
options.domAPI = ${ getdomAPI ( isAuto ) } ;
215
185
options.insertStyleElement = insertStyleElement;
0 commit comments