Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loaders when bundling workers #2092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packagers/JSPackager.js
Expand Up @@ -66,6 +66,7 @@ class JSPackager extends Packager {
this.externalModules.add(mod);
if (
!this.bundle.parentBundle ||
this.bundle.isolated ||
this.bundle.parentBundle.type !== 'js'
) {
this.bundleLoaders.add(mod.type);
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions test/integration/workers-with-other-loaders/index.js
@@ -0,0 +1,2 @@
exports.wasmFunctions = require('./add.wasm');
exports.startWorker = require('./worker-client').startWorker;
6 changes: 6 additions & 0 deletions test/integration/workers-with-other-loaders/worker-client.js
@@ -0,0 +1,6 @@
const {add} = require('./add.wasm');

exports.startWorker = function() {
const worker = new Worker('worker.js');
worker.postMessage(add(2, 3));
};
5 changes: 5 additions & 0 deletions test/integration/workers-with-other-loaders/worker.js
@@ -0,0 +1,5 @@
const {add} = require('./add.wasm');

self.addEventListener('message', () => {
self.postMessage(add(2, 3));
});
41 changes: 41 additions & 0 deletions test/javascript.js
Expand Up @@ -448,6 +448,47 @@ describe('javascript', function() {
});
});

it('should support bundling in workers with other loaders', async function() {
let b = await bundle(
path.join(__dirname, '/integration/workers-with-other-loaders/index.js')
);

await assertBundleTree(b, {
name: 'index.js',
assets: [
'index.js',
'worker-client.js',
'bundle-loader.js',
'bundle-url.js',
'js-loader.js',
'wasm-loader.js'
],
childBundles: [
{
type: 'wasm',
assets: ['add.wasm'],
childBundles: []
},
{
type: 'map'
},
{
assets: [
'worker.js',
'bundle-loader.js',
'bundle-url.js',
'wasm-loader.js'
],
childBundles: [
{
type: 'map'
}
]
}
]
});
});

it('should dynamic import files which import raw files', async function() {
let b = await bundle(
path.join(__dirname, '/integration/dynamic-references-raw/index.js')
Expand Down