preload-webpack-plugin
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
"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"); | ||
/** | ||
@@ -19,4 +29,2 @@ * @license | ||
*/ | ||
const assert = require('assert'); | ||
const createHTMLElementString = require('./lib/create-html-element-string'); | ||
@@ -28,4 +36,2 @@ | ||
const doesChunkBelongToHTML = require('./lib/does-chunk-belong-to-html'); | ||
const extractChunks = require('./lib/extract-chunks'); | ||
@@ -40,4 +46,3 @@ | ||
addLinks(webpackVersion, compilation, htmlPluginData) { | ||
assert(webpackVersion in doesChunkBelongToHTML, `An invalid webpackVersion was supplied. Supported values: ${Object.keys(doesChunkBelongToHTML)}.`); | ||
addLinks(compilation, htmlPluginData) { | ||
const options = this.options; // Bail out early if we're configured to exclude this HTML file. | ||
@@ -52,12 +57,5 @@ | ||
optionsInclude: options.include | ||
}); | ||
const htmlChunks = options.include === 'allAssets' ? // Handle all chunks. | ||
extractedChunks : // Only handle chunks imported by this HtmlWebpackPlugin. | ||
extractedChunks.filter(chunk => doesChunkBelongToHTML[webpackVersion]({ | ||
chunk, | ||
compilation, | ||
htmlAssetsChunks: Object.values(htmlPluginData.assets.chunks) | ||
})); // Flatten the list of files. | ||
}); // Flatten the list of files. | ||
const allFiles = htmlChunks.reduce((accumulated, chunk) => { | ||
const allFiles = extractedChunks.reduce((accumulated, chunk) => { | ||
return accumulated.concat(chunk.files); | ||
@@ -93,8 +91,8 @@ }, []); | ||
optionsAs: options.as | ||
}); // On the off chance that we have a cross-origin 'href' attribute, | ||
// set crossOrigin on the <link> to trigger CORS mode. Non-CORS | ||
// fonts can't be used. | ||
}); // 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 = ''; | ||
attributes.crossorigin = 'anonymous'; | ||
} | ||
@@ -133,21 +131,28 @@ } | ||
if ('hooks' in compiler) { | ||
// We're using webpack v4+. | ||
compiler.hooks.compilation.tap(this.constructor.name, compilation => { | ||
if ('htmlWebpackPluginBeforeHtmlProcessing' in compilation.hooks) { | ||
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync(this.constructor.name, (htmlPluginData, callback) => { | ||
try { | ||
callback(null, this.addLinks('v4', compilation, htmlPluginData)); | ||
} catch (error) { | ||
callback(error); | ||
} | ||
}); | ||
} else { | ||
const error = new Error(`Unable to tap into the ` + `HtmlWebpackPlugin's callbacks. Make sure to list ` + `${this.constructor.name} at some point after ` + `HtmlWebpackPlugin in webpack's plugins array.`); | ||
compilation.errors.push(error); | ||
// This is set in html-webpack-plugin pre-v4. | ||
let hook = compilation.hooks.htmlWebpackPluginAfterHtmlProcessing; | ||
if (!hook) { | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
hook = HtmlWebpackPlugin.getHooks(compilation).beforeEmit; | ||
} | ||
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('v3', compilation, htmlPluginData)); | ||
callback(null, this.addLinks(compilation, htmlPluginData)); | ||
} catch (error) { | ||
@@ -154,0 +159,0 @@ callback(error); |
"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(); } | ||
@@ -4,0 +14,0 @@ |
{ | ||
"name": "preload-webpack-plugin", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"description": "A webpack plugin for injecting <link rel='preload|prefecth'> into HtmlWebpackPlugin pages, with async chunk support", | ||
@@ -28,3 +28,3 @@ "author": "Addy Osmani <addy.osmani@gmail.com> (https://github.com/addyosmani)", | ||
"lint": "eslint --format=codeframe .", | ||
"test": "jasmine test/unit/* test/webpack3/index.js test/webpack4/index.js", | ||
"test": "jasmine test/unit/* test/webpack*/index.js", | ||
"coverage": "nyc npm run test", | ||
@@ -41,12 +41,14 @@ "clean": "rimraf build", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-rc.1", | ||
"@babel/core": "^7.0.0-rc.1", | ||
"@babel/preset-env": "^7.0.0-rc.1", | ||
"eslint": "^5.3.0", | ||
"eslint-config-google": "^0.9.1", | ||
"@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": "^11.12.0", | ||
"jsdom": "^12.1.0", | ||
"memory-fs": "^0.4.1", | ||
"nyc": "^12.0.2", | ||
"rimraf": "^2.6.2" | ||
"nyc": "^13.0.1", | ||
"rimraf": "^2.6.2", | ||
"webpack": "^4.20.2" | ||
}, | ||
@@ -58,4 +60,5 @@ "peerDependencies": { | ||
"dependencies": { | ||
"core-js": "^2.5.7", | ||
"url-parse": "^1.4.3" | ||
} | ||
} |
@@ -129,4 +129,9 @@ # preload-webpack-plugin | ||
You can also configure the plugin to preload all chunks (vendor, async, normal chunks) using `include: 'all'`, or only preload initial chunks with `include: 'initial'`: | ||
You can also configure the plugin to preload all chunks (vendor, async, and normal chunks) using | ||
`include: 'allChunks'`, or only preload initial chunks with `include: 'initial'`. | ||
It is very common in webpack to use loaders such as `file-loader` to generate assets for specific | ||
types, such as fonts or images. If you wish to preload these files as well, even if they don't | ||
belong to a chunk, you can use `include: 'allAssets'`. | ||
```js | ||
@@ -137,3 +142,3 @@ plugins: [ | ||
rel: 'preload', | ||
include: 'all' // or 'initial' | ||
include: 'allChunks' // or 'initial', or 'allAssets' | ||
}) | ||
@@ -140,0 +145,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
300
38098
4
12
9
382
+ Addedcore-js@^2.5.7
+ Addedcore-js@2.6.12(transitive)