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();
}
I would say (per this )
import $ from 'jquery';
import 'bootstrap';
if(!$.core.login){
import('./lib/log-in').then(loginPlz => loginPlz());
}else{
import('./lib/logged-in').then(alreadyIn => alreadyIn());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.