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

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

Open
kloener opened this issue Nov 30, 2017 · 2 comments
Open

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

kloener opened this issue Nov 30, 2017 · 2 comments

Comments

@kloener
Copy link

kloener commented Nov 30, 2017

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

@mastilver
Copy link
Owner

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

@kloener
Copy link
Author

kloener commented Nov 30, 2017

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants