If you want the client code for your Something class to be clean, you can move conditional imports to a single file. You may have the following directory structure for your Something module:
/Something RealSomething.ts FakeSomething.ts index.ts
And in your index.ts you can have the following:
import { config } from '../config'; const Something = config.useFakeSomething ? require('./FakeSomething').FakeSomething : require('./RealSomething').RealSomething; export default Something;
And in your client code, you can simply import Something :
import Something from './Something/index';
source share