简体   繁体   中英

Sharepoint Online SPFX Web parts React - How to dynamically choose script based on enviro?

I want to dynamically choose which script to use in my web part.

My imports are as follows:

import * as jQuery from 'jquery';
import 'jqueryui';

And I want to do this in my component:

//Select script to us 
//if (Environment.type === EnvironmentType.Local) {
  //import * as jQuery from 'jquery';
  //import 'jqueryui';
//} else if (){
   SPComponentLoader.loadCs('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
  SPComponentLoader.loadScript('//code.jquery.com/jquery-min.1.12.1.js');
} ;

Is this possible?

I think you can make use of require method somewhat as below:

//Select script to use 
if (Environment.type === EnvironmentType.Local) {
    require('jQuery');
    require('jqueryui');  
} else if (){
   SPComponentLoader.loadCss('//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css');
   SPComponentLoader.loadScript('//code.jquery.com/jquery-min.1.12.1.js');
};

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM