Search code examples
rxjsrxjs6rxjs-compat

How to use only a part of rxjs-compat, or write a custom rxjs-compat?


We've updated our project to use Angular & Rxjs 6 and all works fine.

We've also updated the code to use the pipe operators, so we would like to drop rxjs-compat.
The only issue is that one of our dependencies still uses the old import syntax for Observable and Subject.

import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

Is there any way to provide our own minimal rxjs-compat just for these two classes?

The library does not do anything fancy with Observable and Subject, and doesn't use any operators, so it seems overkill to import the full rxjs-compat package.


Solution

  • I don't think you need to copy any files when using the paths option.

    I'd try something like this:

    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "rxjs/Observable": ["./node_modules/rxjs/internal/Observable"],
            "rxjs/Subject": ["./node_modules/rxjs/internal/Subject"]
        }
    }
    

    Note that baseUrl must be specified.

    The question is whether or not the paths option affects other dependencies in node_modules. I'm not sure and I didn't try it.