1

I want to import two objects from different files based on some conditions, and export the imported object with different name:

if(condition1)
    import {obj3, obj4} from './file1';
else
    import {obj5, obj6} from './file2';

export {obj1, obj2}
Zeyad Etman
  • 1,848
  • 4
  • 20
  • 36

1 Answers1

4

You could have an intermediate importer/exporter that re-export a given import based on a condition, like this:

//exportSelector.js;
import {obj1, obj2}
let exportedObj = condition1 ? obj1 : obj2;
export exportedObj;

//import.js
import exportedObj;
TLP
  • 1,192
  • 1
  • 6
  • 18