Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ loader.pitch = function(request) {
// only process entry exports
if (current.resource!==entry) return;

let exports = compilation.__workerizeExports || (compilation.__workerizeExports = {});
let exports = CACHE[entry] || (CACHE[entry] = {});
Copy link
Contributor Author

@danieldunderfelt danieldunderfelt Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core issue is here. The __workerizeExports property does not seem to be persisted across re-compiles, resulting in an empty methods list. I propose using the CACHE object instead, since it seems to be used for this purpose anyway.

I assume the compilation object is somehow instanced by entry file, so I wanted to replicate that in the CACHE object if there are many workers in the project.

I think this will still require the end-user to restart the build when method names change, but that's a lot better than having to restart after any change. AFAIK the generated filename isn't available at this point yet, and this function only runs once so it wouldn't know what the next filename is after a recompile. Feel free to suggest modifications to this to enable recompiling method name changes without a restart.


if (decl.id) {
exports[decl.id.name] = true;
Expand All @@ -106,8 +106,9 @@ loader.pitch = function(request) {
if (entries[0]) {
worker.file = entries[0].files[0];

let entry = entries[0].entryModule.resource;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CACHE is keyed by the resource name, so we need to retrieve that here.

let contents = compilation.assets[worker.file].source();
let exports = Object.keys(CACHE[worker.file] = compilation.__workerizeExports || CACHE[worker.file] || {});
let exports = Object.keys(CACHE[entry] || {});

// console.log('Workerized exports: ', exports.join(', '));

Expand Down