preload-webpack-plugin
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
"use strict"; | ||
require("core-js/modules/es7.symbol.async-iterator"); | ||
require("core-js/modules/es6.symbol"); | ||
require("core-js/modules/web.dom.iterable"); | ||
require("core-js/modules/es6.array.sort"); | ||
require("core-js/modules/es6.set"); | ||
/** | ||
* @license | ||
* Copyright 2018 Google Inc. | ||
* Copyright 2019 Google Inc. | ||
* | ||
@@ -29,2 +19,4 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
*/ | ||
const assert = require('assert'); | ||
const createHTMLElementString = require('./lib/create-html-element-string'); | ||
@@ -70,48 +62,29 @@ | ||
const publicPath = compilation.outputOptions.publicPath || ''; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = sortedFilteredFiles[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const file = _step.value; | ||
const href = `${publicPath}${file}`; | ||
const attributes = { | ||
for (const file of sortedFilteredFiles) { | ||
const href = `${publicPath}${file}`; | ||
const attributes = { | ||
href, | ||
rel: options.rel | ||
}; // If we're preloading this resource (as opposed to prefetching), | ||
// then we need to set the 'as' attribute correctly. | ||
if (options.rel === 'preload') { | ||
attributes.as = determineAsValue({ | ||
href, | ||
rel: options.rel | ||
}; // If we're preloading this resource (as opposed to prefetching), | ||
// then we need to set the 'as' attribute correctly. | ||
optionsAs: options.as | ||
}); // On the off chance that we have an 'href' attribute with a | ||
// cross-origin URL, set crossOrigin on the <link> to trigger CORS mode. | ||
// when preloading fonts. (Non-CORS fonts can't be used.) | ||
if (options.rel === 'preload') { | ||
attributes.as = determineAsValue({ | ||
href, | ||
optionsAs: options.as | ||
}); // On the off chance that we have an 'href' attribute with a | ||
// cross-origin URL, set crossOrigin on the <link> to trigger CORS mode. | ||
// when preloading fonts. (Non-CORS fonts can't be used.) | ||
if (attributes.as === 'font') { | ||
attributes.crossorigin = 'anonymous'; | ||
} | ||
if (attributes.as === 'font') { | ||
attributes.crossorigin = 'anonymous'; | ||
} | ||
} | ||
const linkElementString = createHTMLElementString({ | ||
attributes, | ||
elementName: 'link' | ||
}); | ||
links.push(linkElementString); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
const linkElementString = createHTMLElementString({ | ||
attributes, | ||
elementName: 'link' | ||
}); | ||
links.push(linkElementString); | ||
} | ||
@@ -127,35 +100,20 @@ | ||
apply(compiler) { | ||
if ('hooks' in compiler) { | ||
// We're using webpack v4+. | ||
compiler.hooks.compilation.tap(this.constructor.name, compilation => { | ||
// This is set in html-webpack-plugin pre-v4. | ||
let hook = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing; | ||
compiler.hooks.compilation.tap(this.constructor.name, compilation => { | ||
// This is set in html-webpack-plugin pre-v4. | ||
let hook = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing; | ||
if (!hook) { | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
if (!hook) { | ||
const [HtmlWebpackPlugin] = compiler.options.plugins.filter(plugin => plugin.constructor.name === 'HtmlWebpackPlugin'); | ||
assert(HtmlWebpackPlugin, 'Unable to find an instance of ' + 'HtmlWebpackPlugin in the current compilation.'); | ||
hook = HtmlWebpackPlugin.constructor.getHooks(compilation).beforeEmit; | ||
} | ||
hook = HtmlWebpackPlugin.getHooks(compilation).beforeEmit; | ||
hook.tapAsync(this.constructor.name, (htmlPluginData, callback) => { | ||
try { | ||
callback(null, this.addLinks(compilation, htmlPluginData)); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
hook.tapAsync(this.constructor.name, (htmlPluginData, callback) => { | ||
try { | ||
callback(null, this.addLinks(compilation, htmlPluginData)); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
}); | ||
}); | ||
} else { | ||
// We're using webpack pre-v4, which implies that we're also using | ||
// html-webpack-plugin pre-v4. | ||
compiler.plugin('compilation', compilation => { | ||
compilation.plugin('html-webpack-plugin-before-html-processing', (htmlPluginData, callback) => { | ||
try { | ||
callback(null, this.addLinks(compilation, htmlPluginData)); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
@@ -162,0 +120,0 @@ |
"use strict"; | ||
require("core-js/modules/es7.symbol.async-iterator"); | ||
require("core-js/modules/es6.symbol"); | ||
require("core-js/modules/es7.object.entries"); | ||
require("core-js/modules/es6.array.sort"); | ||
require("core-js/modules/web.dom.iterable"); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
/** | ||
@@ -47,31 +29,9 @@ * @license | ||
const attributeStrings = []; | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Object.entries(attributes).sort()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
const _step$value = _slicedToArray(_step.value, 2), | ||
attributeName = _step$value[0], | ||
attributeValue = _step$value[1]; | ||
if (attributeValue === '') { | ||
attributeStrings.push(attributeName); | ||
} else { | ||
attributeStrings.push(`${attributeName}=${JSON.stringify(attributeValue)}`); | ||
} | ||
for (const [attributeName, attributeValue] of Object.entries(attributes).sort()) { | ||
if (attributeValue === '') { | ||
attributeStrings.push(attributeName); | ||
} else { | ||
attributeStrings.push(`${attributeName}=${JSON.stringify(attributeValue)}`); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
@@ -78,0 +38,0 @@ |
@@ -5,3 +5,3 @@ "use strict"; | ||
* @license | ||
* Copyright 2018 Google Inc. | ||
* Copyright 2019 Google Inc. | ||
* | ||
@@ -22,7 +22,8 @@ * Licensed under the Apache License, Version 2.0 (the "License"); | ||
const path = require('path'); // The first-party 'url' module isn't available in node 6. | ||
const path = require('path'); | ||
const { | ||
URL | ||
} = require('url'); | ||
const URL = require('url-parse'); | ||
function determineAsValue({ | ||
@@ -29,0 +30,0 @@ optionsAs, |
{ | ||
"name": "preload-webpack-plugin", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "A webpack plugin for injecting <link rel='preload|prefecth'> into HtmlWebpackPlugin pages, with async chunk support", | ||
@@ -20,7 +20,6 @@ "author": "Addy Osmani <addy.osmani@gmail.com> (https://github.com/addyosmani)", | ||
"script", | ||
"preload", | ||
"resource hints" | ||
"preload" | ||
], | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
@@ -41,23 +40,17 @@ "scripts": { | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.2", | ||
"@babel/core": "^7.1.2", | ||
"@babel/preset-env": "^7.1.0", | ||
"eslint": "^5.6.1", | ||
"eslint-config-google": "^0.10.0", | ||
"html-webpack-plugin": "^4.0.0-beta.2", | ||
"jasmine": "^3.2.0", | ||
"jsdom": "^12.1.0", | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/preset-env": "^7.5.5", | ||
"eslint": "^6.2.1", | ||
"eslint-config-google": "^0.13.0", | ||
"jasmine": "^3.4.0", | ||
"jsdom": "^15.1.1", | ||
"memory-fs": "^0.4.1", | ||
"nyc": "^13.0.1", | ||
"rimraf": "^2.6.2", | ||
"webpack": "^4.20.2" | ||
"nyc": "^14.1.1", | ||
"rimraf": "^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"html-webpack-plugin": ">=2.26.0", | ||
"webpack": ">=3.2.0" | ||
}, | ||
"dependencies": { | ||
"core-js": "^2.5.7", | ||
"url-parse": "^1.4.3" | ||
"html-webpack-plugin": ">=3.0.0", | ||
"webpack": ">=4.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
10
35037
316
- Removedcore-js@^2.5.7
- Removedurl-parse@^1.4.3
- Removedcore-js@2.6.12(transitive)
- Removedquerystringify@2.2.0(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedurl-parse@1.5.10(transitive)