Skip to content

Commit

Permalink
Add loaders when bundling workers (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa authored and devongovett committed Oct 6, 2018
1 parent a663db2 commit cc04a49
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/parcel-bundler/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.
@@ -0,0 +1,2 @@
exports.wasmFunctions = require('./add.wasm');
exports.startWorker = require('./worker-client').startWorker;
@@ -0,0 +1,6 @@
const {add} = require('./add.wasm');

exports.startWorker = function() {
const worker = new Worker('worker.js');
worker.postMessage(add(2, 3));
};
@@ -0,0 +1,5 @@
const {add} = require('./add.wasm');

self.addEventListener('message', () => {
self.postMessage(add(2, 3));
});
41 changes: 41 additions & 0 deletions packages/core/parcel-bundler/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

0 comments on commit cc04a49

Please sign in to comment.