Reputation: 2909
I am using JSPM and I am new to ES6 as well
I am wondering what is correct way to make imports when they are conditional in ES6
Method-1:
// should load only module required
import $ from 'jquery';
import 'bootstrap';
if(!$.core.login){
System.import('lib/log-in');
}else{
System.import('lib/logged-in');
}
Method-2:
//load both at once and consume which ever is valid
import $ from 'jquery';
import 'bootstrap';
import {loginPlz} from 'lib/log-in';
import {alreadyIn} from 'lib/logged-in';
if(!$.core.login){
loginPlz();
}else{
alreadyIn();
}
Upvotes: 0
Views: 86