in fusion-cli/build/plugins/instrumented-import-dependency-template-plugin.js [162:237]
apply(compiler /*: any */) {
const name = this.constructor.name;
if (this.opts.compilation === 'server') {
const {clientChunkMetadata} = this.opts;
compiler.hooks.make.tapAsync(name, (compilation, done) => {
clientChunkMetadata.result.then(metadata => {
compilation.dependencyTemplates.set(
ImportDependency,
new InstrumentedImportDependency.Template(metadata.fileManifest)
);
done();
});
});
}
if (this.opts.compilation === 'client') {
// Add a new template and factory for IntrumentedImportDependency
compiler.hooks.compilation.tap(name, (compilation, params) => {
compilation.dependencyFactories.set(
InstrumentedImportDependency,
params.normalModuleFactory
);
compilation.dependencyTemplates.set(
InstrumentedImportDependency,
new InstrumentedImportDependency.Template()
);
compilation.hooks.afterOptimizeDependencies.tap(name, modules => {
// Replace ImportDependency with our Instrumented dependency
for (const module of modules) {
if (module.blocks) {
module.blocks.forEach(block => {
block.dependencies.forEach((dep, index) => {
if (dep instanceof ImportDependency) {
let moduleId = dep.module.id;
if (dep.module.id === null && dep.module.libIdent) {
moduleId = dep.module.libIdent({
context: compiler.options.context,
});
}
block.dependencies[
index
] = new InstrumentedImportDependency(
dep,
this.opts,
moduleId
);
}
});
});
}
}
});
});
}
/**
* server and client
* Ensure custom module ids are used instead of hashed module ids
* Based on https://github.com/gogoair/custom-module-ids-webpack-plugin
*/
compiler.hooks.compilation.tap(name, (compilation, params) => {
compilation.hooks.beforeModuleIds.tap(name, modules => {
for (const module of modules) {
if (module.id === null && module.libIdent) {
// Some modules lose their id by this point
// Reassign the cached module id so it matches the id used in the instrumentation
const id = module.libIdent({
context: compiler.options.context,
});
const moduleId = getCachedModuleId(id);
if (moduleId) {
module.id = moduleId;
}
}
}
});
});
}