File tree 4 files changed +48
-20
lines changed
4 files changed +48
-20
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,17 @@ module.exports = function addStyle(cssCode) {
15
15
} else {
16
16
styleElement . appendChild ( document . createTextNode ( cssCode ) ) ;
17
17
}
18
- return function ( ) {
19
- head . removeChild ( styleElement ) ;
20
- } ;
18
+ if ( module . hot ) {
19
+ return function ( cssCode ) {
20
+ if ( typeof cssCode === "string" ) {
21
+ if ( styleElement . styleSheet ) {
22
+ styleElement . styleSheet . cssText = cssCode ;
23
+ } else {
24
+ styleElement . childNodes [ 0 ] . nodeValue = cssCode ;
25
+ }
26
+ } else {
27
+ head . removeChild ( styleElement ) ;
28
+ }
29
+ } ;
30
+ }
21
31
}
Original file line number Diff line number Diff line change @@ -12,7 +12,13 @@ module.exports = function addStyleUrl(cssUrl) {
12
12
styleElement . href = cssUrl ;
13
13
var head = document . getElementsByTagName ( "head" ) [ 0 ] ;
14
14
head . appendChild ( styleElement ) ;
15
- return function ( ) {
16
- head . removeChild ( styleElement ) ;
17
- } ;
15
+ if ( module . hot ) {
16
+ return function ( cssUrl ) {
17
+ if ( typeof cssUrl === "string" ) {
18
+ styleElement . href = cssUrl ;
19
+ } else {
20
+ head . removeChild ( styleElement ) ;
21
+ }
22
+ } ;
23
+ }
18
24
}
Original file line number Diff line number Diff line change @@ -6,11 +6,17 @@ var path = require("path");
6
6
module . exports = function ( ) { } ;
7
7
module . exports . pitch = function ( remainingRequest ) {
8
8
this . cacheable && this . cacheable ( ) ;
9
- var comment1 = "// style-loader: Adds some css to the DOM by adding a <style> tag\n" ;
10
- var addStyleCode = "var dispose = require(" + JSON . stringify ( "!" + path . join ( __dirname , "addStyle.js" ) ) + ")\n" ;
11
- var comment2 = "\t// The css code:\n" ;
12
- var cssCodeRequest = "require(" + JSON . stringify ( "!!" + remainingRequest ) + ")" ;
13
- var comment3 = "// Hot Module Replacement\n" ;
14
- var hmrCode = "if(module.hot) {\n\tmodule.hot.accept();\n\tmodule.hot.dispose(dispose);\n}" ;
15
- return comment1 + addStyleCode + comment2 + "\t(" + cssCodeRequest + ");\n" + comment3 + hmrCode ;
9
+ return [
10
+ "// style-loader: Adds some css to the DOM by adding a <style> tag" ,
11
+ "var update = require(" + JSON . stringify ( "!" + path . join ( __dirname , "addStyle.js" ) ) + ")(" ,
12
+ "\trequire(" + JSON . stringify ( "!!" + remainingRequest ) + ")" ,
13
+ ");" ,
14
+ "// Hot Module Replacement" ,
15
+ "if(module.hot) {" ,
16
+ "\tmodule.hot.accept(" + JSON . stringify ( "!!" + remainingRequest ) + ", function() {" ,
17
+ "\t\tupdate(require(" + JSON . stringify ( "!!" + remainingRequest ) + "));" ,
18
+ "\t});" ,
19
+ "\tmodule.hot.dispose(function() { update(); });" ,
20
+ "}"
21
+ ] . join ( "\n" ) ;
16
22
} ;
Original file line number Diff line number Diff line change @@ -6,11 +6,17 @@ var path = require("path");
6
6
module . exports = function ( ) { } ;
7
7
module . exports . pitch = function ( remainingRequest ) {
8
8
this . cacheable && this . cacheable ( ) ;
9
- var comment1 = "// style-loader: Adds some css to the DOM by adding a <style> tag\n" ;
10
- var addStyleCode = "var dispose = require(" + JSON . stringify ( "!" + path . join ( __dirname , "addStyleUrl.js" ) ) + ")\n" ;
11
- var comment2 = "\t// The url to the css code:\n" ;
12
- var cssUrlRequest = "require(" + JSON . stringify ( "!!" + remainingRequest ) + ")" ;
13
- var comment3 = "// Hot Module Replacement\n" ;
14
- var hmrCode = "if(module.hot) {\n\tmodule.hot.accept();\n\tmodule.hot.dispose(dispose);\n}" ;
15
- return comment1 + addStyleCode + comment2 + "\t(" + cssUrlRequest + ");\n" + comment3 + hmrCode ;
9
+ return [
10
+ "// style-loader: Adds some reference to a css file to the DOM by adding a <link> tag" ,
11
+ "var update = require(" + JSON . stringify ( "!" + path . join ( __dirname , "addStyleUrl.js" ) ) + ")(" ,
12
+ "\trequire(" + JSON . stringify ( "!!" + remainingRequest ) + ")" ,
13
+ ");" ,
14
+ "// Hot Module Replacement" ,
15
+ "if(module.hot) {" ,
16
+ "\tmodule.hot.accept(" + JSON . stringify ( "!!" + remainingRequest ) + ", function() {" ,
17
+ "\t\tupdate(require(" + JSON . stringify ( "!!" + remainingRequest ) + "));" ,
18
+ "\t});" ,
19
+ "\tmodule.hot.dispose(function() { update(); });" ,
20
+ "}"
21
+ ] . join ( "\n" ) ;
16
22
} ;
You can’t perform that action at this time.
0 commit comments