Skip to content

Commit c6b02a4

Browse files
committed
fix: run 'execLinkTag' through 'processLinkHref' func too
1 parent 53a6b92 commit c6b02a4

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ class ExtractCssChunksPlugin {
113113
// the parameter or globally available stuff like `window.x`
114114
// note: here we are using a plain ES5 function as a default, cause we don't
115115
// know what env this code will be run
116-
/* eslint-disable func-names, object-shorthand, prefer-template */
116+
/* eslint-disable func-names, object-shorthand */
117117
processLinkHref: function(x) {
118118
return x;
119119
},
120-
/* eslint-enable func-names, object-shorthand, prefer-template */
120+
/* eslint-enable func-names, object-shorthand */
121121
},
122122
options,
123123
{ insert }
@@ -332,7 +332,7 @@ class ExtractCssChunksPlugin {
332332
contentHashType: MODULE_TYPE,
333333
}
334334
);
335-
const { insert } = this.options;
335+
const { insert, processLinkHref } = this.options;
336336
const supportsPreload =
337337
'(function() { try { return document.createElement("link").relList.supports("preload"); } catch(e) { return false; }}());';
338338
return Template.asString([
@@ -341,12 +341,12 @@ class ExtractCssChunksPlugin {
341341
`// ${pluginName} CSS loading`,
342342
`var supportsPreload = ${supportsPreload}`,
343343
`var cssChunks = ${JSON.stringify(chunkMap)};`,
344+
`var processLinkHref = ${processLinkHref};`,
344345
'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);',
345346
'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {',
346347
Template.indent([
347348
'promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {',
348349
Template.indent([
349-
`var processLinkHref = ${this.options.processLinkHref};`,
350350
`var href = ${linkHrefPath};`,
351351
`var fullhref = processLinkHref(${mainTemplate.requireFn}.p + href);`,
352352
'var existingLinkTags = document.getElementsByTagName("link");',
@@ -402,7 +402,7 @@ class ExtractCssChunksPlugin {
402402
'if(supportsPreload) {',
403403
Template.indent([
404404
'var execLinkTag = document.createElement("link");',
405-
`execLinkTag.href = ${mainTemplate.requireFn}.p + ${linkHrefPath};`,
405+
`execLinkTag.href = processLinkHref(${mainTemplate.requireFn}.p + ${linkHrefPath});`,
406406
'execLinkTag.rel = "stylesheet";',
407407
'execLinkTag.type = "text/css";',
408408
'document.body.appendChild(execLinkTag);',

test/cases/simple-async-process-link-href/expected/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
/******/ // extract-css-chunks-webpack-plugin CSS loading
8585
/******/ var supportsPreload = (function() { try { return document.createElement("link").relList.supports("preload"); } catch(e) { return false; }}());
8686
/******/ var cssChunks = {"1":1,"2":1};
87+
/******/ var processLinkHref = function (x) {
88+
/******/ return x + '.dummy';
89+
/******/ };
8790
/******/ if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);
8891
/******/ else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {
8992
/******/ promises.push(installedCssChunks[chunkId] = new Promise(function(resolve, reject) {
90-
/******/ var processLinkHref = function (x) {
91-
/******/ return x + '.dummy';
92-
/******/ };
9393
/******/ var href = "" + ({}[chunkId]||chunkId) + ".css";
9494
/******/ var fullhref = processLinkHref(__webpack_require__.p + href);
9595
/******/ var existingLinkTags = document.getElementsByTagName("link");
@@ -124,7 +124,7 @@
124124
/******/ installedCssChunks[chunkId] = 0;
125125
/******/ if(supportsPreload) {
126126
/******/ var execLinkTag = document.createElement("link");
127-
/******/ execLinkTag.href = __webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".css";
127+
/******/ execLinkTag.href = processLinkHref(__webpack_require__.p + "" + ({}[chunkId]||chunkId) + ".css");
128128
/******/ execLinkTag.rel = "stylesheet";
129129
/******/ execLinkTag.type = "text/css";
130130
/******/ document.body.appendChild(execLinkTag);

0 commit comments

Comments
 (0)