From 3b4e37e5582dcd944bf8dade026b81542df17fb3 Mon Sep 17 00:00:00 2001 From: "Masahiro Miyashiro (3846masa)" <3846masahiro@gmail.com> Date: Sat, 6 Oct 2018 23:53:53 +0900 Subject: [PATCH] Add loaders when bundling workers (#2092) --- src/packagers/JSPackager.js | 1 + .../workers-with-other-loaders/add.wasm | Bin 0 -> 41 bytes .../workers-with-other-loaders/index.js | 2 + .../worker-client.js | 6 +++ .../workers-with-other-loaders/worker.js | 5 +++ test/javascript.js | 41 ++++++++++++++++++ 6 files changed, 55 insertions(+) create mode 100644 test/integration/workers-with-other-loaders/add.wasm create mode 100644 test/integration/workers-with-other-loaders/index.js create mode 100644 test/integration/workers-with-other-loaders/worker-client.js create mode 100644 test/integration/workers-with-other-loaders/worker.js diff --git a/src/packagers/JSPackager.js b/src/packagers/JSPackager.js index 339e0c5155a..6464c7a25b8 100644 --- a/src/packagers/JSPackager.js +++ b/src/packagers/JSPackager.js @@ -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); diff --git a/test/integration/workers-with-other-loaders/add.wasm b/test/integration/workers-with-other-loaders/add.wasm new file mode 100644 index 0000000000000000000000000000000000000000..357f72da7a0db8add83699082fd51d46bf3352fb GIT binary patch literal 41 wcmZQbEY4+QU|?WmXG~zKuV<`hW@2PuXJ=$iOi5v2;NoOtXHZ~JV9eqM0DJxgJ^%m! literal 0 HcmV?d00001 diff --git a/test/integration/workers-with-other-loaders/index.js b/test/integration/workers-with-other-loaders/index.js new file mode 100644 index 00000000000..f806f1bb4da --- /dev/null +++ b/test/integration/workers-with-other-loaders/index.js @@ -0,0 +1,2 @@ +exports.wasmFunctions = require('./add.wasm'); +exports.startWorker = require('./worker-client').startWorker; diff --git a/test/integration/workers-with-other-loaders/worker-client.js b/test/integration/workers-with-other-loaders/worker-client.js new file mode 100644 index 00000000000..32ed154d387 --- /dev/null +++ b/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)); +}; diff --git a/test/integration/workers-with-other-loaders/worker.js b/test/integration/workers-with-other-loaders/worker.js new file mode 100644 index 00000000000..0aa80122a3c --- /dev/null +++ b/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)); +}); diff --git a/test/javascript.js b/test/javascript.js index d59cc1de64c..4f34102ca68 100644 --- a/test/javascript.js +++ b/test/javascript.js @@ -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')