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
  • 2,250
  • 5
  • 25
  • 42

1 Answers1

5

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,262
  • 1
  • 8
  • 20