Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 5d038ef

Browse files
committed
Light refactoring.
1 parent 04e7bd6 commit 5d038ef

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ class PreloadPlugin {
7878
// If we're preloading this resource (as opposed to prefetching),
7979
// then we need to set the 'as' attribute correctly.
8080
if (options.rel === 'preload') {
81-
attributes.as = determineAsValue(options.as, href);
81+
attributes.as = determineAsValue({
82+
href,
83+
optionsAs: options.as,
84+
});
8285

8386
// On the off chance that we have a cross-origin 'href' attribute,
8487
// set crossOrigin on the <link> to trigger CORS mode. Non-CORS
@@ -88,11 +91,17 @@ class PreloadPlugin {
8891
}
8992
}
9093

91-
const linkElementString = createHTMLElementString('link', attributes);
94+
const linkElementString = createHTMLElementString({
95+
attributes,
96+
elementName: 'link',
97+
});
9298
links.push(linkElementString);
9399
}
94100

95-
htmlPluginData.html = insertLinksIntoHead(htmlPluginData.html, links);
101+
htmlPluginData.html = insertLinksIntoHead({
102+
links,
103+
html: htmlPluginData.html,
104+
});
96105

97106
return htmlPluginData;
98107
}

src/lib/create-html-element-string.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const assert = require('assert');
1919

20-
function createHTMLElementString(elementName, attributes={}, closingTagRequired=false) {
20+
function createHTMLElementString({elementName, attributes={}, closingTagRequired=false}) {
2121
assert(elementName, 'Please provide an element name.');
2222
assert(!(/\W/.test(elementName)), 'The element name contains invalid characters.');
2323

src/lib/determine-as-value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const assert = require('assert');
1919
const path = require('path');
2020
const {URL} = require('url');
2121

22-
function determineAsAttribute(optionsAs, href) {
22+
function determineAsValue({optionsAs, href}) {
2323
assert(href, `The 'href' parameter was not provided.`);
2424

2525
switch (typeof optionsAs) {
@@ -55,4 +55,4 @@ function determineAsAttribute(optionsAs, href) {
5555
}
5656
}
5757

58-
module.exports = determineAsAttribute;
58+
module.exports = determineAsValue;

src/lib/does-chunk-belong-to-html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
function v3({chunk, htmlAssetsChunks, visitedChunks = {}}) {
18+
function v3({chunk, htmlAssetsChunks, visitedChunks={}}) {
1919
// Prevent circular recursion.
2020
// See https://github.com/GoogleChromeLabs/preload-webpack-plugin/issues/49
2121
if (visitedChunks[chunk.renderedHash]) {

src/lib/insert-links-into-head.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
function insertLinksIntoHead(html, links) {
18+
function insertLinksIntoHead({html, links=[]}) {
1919
if (links.length === 0) {
2020
return html;
2121
}

0 commit comments

Comments
 (0)