dynamic-cdn-webpack-plugin icon indicating copy to clipboard operation
dynamic-cdn-webpack-plugin copied to clipboard

How can I disable/ignore the plugin for Web Workers?

Open kloener opened this issue 7 years ago • 2 comments

Hi

I've an issue where a Web Worker tries to use a global "ng" from Angular (to extend a class), which is not present inside a worker.

How can I tell your plugin to ignore these worker-files and use the normal webpack behaviour?

kind regards, Christian

kloener avatar Nov 30 '17 09:11 kloener

Hi

There is no way to currently ignore a specific chunk (I'm guessing it's a chunk you are talking about?)

I wonder if we even have that information, maybe from nmf or factory

mastilver avatar Nov 30 '17 16:11 mastilver

Yes, I use worker-loader which creates another chunk, I guess.

I solved it for me now by creating another webpack-config file. The new configuration has the imported file from the worker as the entry point. The output will be used with importScripts('another-bundle.js');, instead of using import {MyClass} from './my-actual-file';

// another webpack configuration
    entry: {
        myWorkerBundle: 'src/app/my-actual-file.ts')
},
    output: {
        path: 'src',
        filename: 'another-bundle.js'
},
// ...
// my-actual-file.ts
// ... some class should be defined here
if(typeof self !== "undefined") {
    (<any>self).MyClass = MyClass;
}
// inside my worker script
importScripts('another-bundle.js');
const MyRealClass = (<any>self).MyClass;
// using the worker somewhere
import * as MyWorker from 'worker-loader!./my-worker';
const worker = new MyWorker();

kloener avatar Nov 30 '17 20:11 kloener