Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91671389
AutomaticPrefetchPlugin.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 13, 07:45
Size
1 KB
Mime Type
text/x-c++
Expires
Fri, Nov 15, 07:45 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22288966
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
AutomaticPrefetchPlugin.js
View Options
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const asyncLib = require("neo-async");
const NormalModule = require("./NormalModule");
const PrefetchDependency = require("./dependencies/PrefetchDependency");
/** @typedef {import("./Compiler")} Compiler */
class AutomaticPrefetchPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(
"AutomaticPrefetchPlugin",
(compilation, { normalModuleFactory }) => {
compilation.dependencyFactories.set(
PrefetchDependency,
normalModuleFactory
);
}
);
let lastModules = null;
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
lastModules = Array.from(compilation.modules)
.filter(m => m instanceof NormalModule)
.map((/** @type {NormalModule} */ m) => ({
context: m.context,
request: m.request
}));
});
compiler.hooks.make.tapAsync(
"AutomaticPrefetchPlugin",
(compilation, callback) => {
if (!lastModules) return callback();
asyncLib.forEach(
lastModules,
(m, callback) => {
compilation.addModuleChain(
m.context || compiler.context,
new PrefetchDependency(m.request),
callback
);
},
callback
);
}
);
}
}
module.exports = AutomaticPrefetchPlugin;
Event Timeline
Log In to Comment