dynamic-cdn-webpack-plugin
dynamic-cdn-webpack-plugin copied to clipboard
How can I disable/ignore the plugin for Web Workers?
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
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
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();