@@ -16,10 +16,6 @@ class CssChunkLoadingRuntimeModule extends RuntimeModule {
16
16
const fn = RuntimeGlobals . ensureChunkHandlers ;
17
17
const { compilation, chunk } = this ;
18
18
const { runtimeTemplate } = compilation ;
19
- const withCompat = this . runtimeRequirements . has (
20
- RuntimeGlobals . compatGetDefaultExport
21
- ) ;
22
-
23
19
const chunkMaps = chunk . getChunkMaps ( ) ;
24
20
const { crossOriginLoading } = compilation . outputOptions ;
25
21
const linkHrefPath = compilation . getAssetPath (
@@ -81,76 +77,73 @@ class CssChunkLoadingRuntimeModule extends RuntimeModule {
81
77
) ,
82
78
'}' ,
83
79
'' ,
84
- withCompat
85
- ? Template . asString ( [
86
- `${ fn } .n = ${ runtimeTemplate . basicFunction (
87
- 'chunkId, promises' ,
80
+ Template . asString ( [
81
+ `${ fn } .n = ${ runtimeTemplate . basicFunction (
82
+ 'chunkId, promises' ,
83
+ Template . indent ( [
84
+ `// ${ this . pluginName } CSS loading` ,
85
+ `var cssChunks = ${ JSON . stringify ( this . chunkMap ) } ;` ,
86
+ 'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);' ,
87
+ 'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {' ,
88
+ Template . indent ( [
89
+ 'promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {' ,
88
90
Template . indent ( [
89
- // source,
90
- `// ${ this . pluginName } CSS loading` ,
91
- `var cssChunks = ${ JSON . stringify ( this . chunkMap ) } ;` ,
92
- 'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);' ,
93
- 'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {' ,
91
+ `var href = ${ linkHrefPath } ;` ,
92
+ `var fullhref = __webpack_require__.p + href;` ,
93
+ 'var existingLinkTags = document.getElementsByTagName("link");' ,
94
+ 'for(var i = 0; i < existingLinkTags.length; i++) {' ,
94
95
Template . indent ( [
95
- 'promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {' ,
96
- Template . indent ( [
97
- `var href = ${ linkHrefPath } ;` ,
98
- `var fullhref = __webpack_require__.p + href;` ,
99
- 'var existingLinkTags = document.getElementsByTagName("link");' ,
100
- 'for(var i = 0; i < existingLinkTags.length; i++) {' ,
101
- Template . indent ( [
102
- 'var tag = existingLinkTags[i];' ,
103
- 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");' ,
104
- 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve();' ,
105
- ] ) ,
106
- '}' ,
107
- 'var existingStyleTags = document.getElementsByTagName("style");' ,
108
- 'for(var i = 0; i < existingStyleTags.length; i++) {' ,
109
- Template . indent ( [
110
- 'var tag = existingStyleTags[i];' ,
111
- 'var dataHref = tag.getAttribute("data-href");' ,
112
- 'if(dataHref === href || dataHref === fullhref) return resolve();' ,
113
- ] ) ,
114
- '}' ,
115
- 'var linkTag = document.createElement("link");' ,
116
- 'linkTag.rel = "stylesheet";' ,
117
- 'linkTag.type = "text/css";' ,
118
- 'linkTag.onload = resolve;' ,
119
- 'linkTag.onerror = function(event) {' ,
120
- Template . indent ( [
121
- 'var request = event && event.target && event.target.src || fullhref;' ,
122
- 'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");' ,
123
- 'err.code = "CSS_CHUNK_LOAD_FAILED";' ,
124
- 'err.request = request;' ,
125
- 'delete installedCssChunks[chunkId]' ,
126
- 'linkTag.parentNode.removeChild(linkTag)' ,
127
- 'reject(err);' ,
128
- ] ) ,
129
- '};' ,
130
- 'linkTag.href = fullhref;' ,
131
- crossOriginLoading
132
- ? Template . asString ( [
133
- `if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {` ,
134
- Template . indent (
135
- `linkTag.crossOrigin = ${ JSON . stringify (
136
- crossOriginLoading
137
- ) } ;`
138
- ) ,
139
- '}' ,
140
- ] )
141
- : '' ,
142
- 'var head = document.getElementsByTagName("head")[0];' ,
143
- 'head.appendChild(linkTag);' ,
144
- ] ) ,
145
- '}).then(function() {' ,
146
- Template . indent ( [ 'installedCssChunks[chunkId] = 0;' ] ) ,
147
- '}));' ,
96
+ 'var tag = existingLinkTags[i];' ,
97
+ 'var dataHref = tag.getAttribute("data-href") || tag.getAttribute("href");' ,
98
+ 'if(tag.rel === "stylesheet" && (dataHref === href || dataHref === fullhref)) return resolve();' ,
148
99
] ) ,
149
100
'}' ,
150
- ] )
151
- ) } ;`,
101
+ 'var existingStyleTags = document.getElementsByTagName("style");' ,
102
+ 'for(var i = 0; i < existingStyleTags.length; i++) {' ,
103
+ Template . indent ( [
104
+ 'var tag = existingStyleTags[i];' ,
105
+ 'var dataHref = tag.getAttribute("data-href");' ,
106
+ 'if(dataHref === href || dataHref === fullhref) return resolve();' ,
107
+ ] ) ,
108
+ '}' ,
109
+ 'var linkTag = document.createElement("link");' ,
110
+ 'linkTag.rel = "stylesheet";' ,
111
+ 'linkTag.type = "text/css";' ,
112
+ 'linkTag.onload = resolve;' ,
113
+ 'linkTag.onerror = function(event) {' ,
114
+ Template . indent ( [
115
+ 'var request = event && event.target && event.target.src || fullhref;' ,
116
+ 'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");' ,
117
+ 'err.code = "CSS_CHUNK_LOAD_FAILED";' ,
118
+ 'err.request = request;' ,
119
+ 'delete installedCssChunks[chunkId]' ,
120
+ 'linkTag.parentNode.removeChild(linkTag)' ,
121
+ 'reject(err);' ,
122
+ ] ) ,
123
+ '};' ,
124
+ 'linkTag.href = fullhref;' ,
125
+ crossOriginLoading
126
+ ? Template . asString ( [
127
+ `if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {` ,
128
+ Template . indent (
129
+ `linkTag.crossOrigin = ${ JSON . stringify (
130
+ crossOriginLoading
131
+ ) } ;`
132
+ ) ,
133
+ '}' ,
134
+ ] )
135
+ : '' ,
136
+ 'var head = document.getElementsByTagName("head")[0];' ,
137
+ 'head.appendChild(linkTag);' ,
138
+ ] ) ,
139
+ '}).then(function() {' ,
140
+ Template . indent ( [ 'installedCssChunks[chunkId] = 0;' ] ) ,
141
+ '}));' ,
142
+ ] ) ,
143
+ '}' ,
152
144
] )
153
- : '' ,
145
+ ) } ;`,
146
+ ] ) ,
154
147
] ) ;
155
148
}
156
149
}
0 commit comments