forked from GoogleChromeLabs/worker-plugin
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
bugSomething isn't workingSomething isn't working
Description
I'm currently writing a small plugin to allow prefetching workers written with the plugin (the principle works). During this work, I noticed that webpack compilation.chunks is missing the worker files.
Here's my current plugin code:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const insertLinksIntoHead = require('./insert-links-into-head');
class PrefetchPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
const { include } = this.options;
// TODO: Match using include
compiler.hooks.compilation.tap('PrefetchPlugin', (compilation) => {
console.log('include', include);
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync('PrefetchPlugin', (data, cb) => {
const links = []; // TODO: Populate with HTML for prefetching
const allFiles = compilation.chunks.reduce((accumulated, chunk) => {
return accumulated.concat(chunk.files);
}, []);
console.log('chunks', allFiles);
data.html = insertLinksIntoHead({
links,
html: data.html,
});
cb(null, data);
});
});
}
}
module.exports = PrefetchPlugin;That helper module is directly from https://github.com/GoogleChromeLabs/preload-webpack-plugin .
I peeked at the code and I noticed threads-plugin is using a child compiler within a loader to write the worker files. My feeling is that there's something missing that would communicate the emitted files to the parent compilation.
What's the technical reason for using a child compiler? Have you encountered something like this before?
Nantris
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working