SPFX how to link the external libraries:

After create an sample spfx webpart with "nojavascript"

1. In visual studio code, open config.json file in your machine (press ctrl+p and type config.json file).

2. external object key shows empty initially.

3. Open Node JS cmd prompt and install requried external library files using npm

To Install Jquery: npm install jquery@2
Install Jquery types for typescript handy: npm install @types/jquery@2

Jquery UI
npm install jqueryui

npm install @types/jqueryui

Bootstrap
npm install bootstrap

Angular:

npm install @types/angular --save-dev

Under externals key object provide below reference

"externals": {
    "jquery":"node_modules/jquery/dist/jquery.min.js",
    "angular": {
      "path""https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.6/angular.min.js",
      "globalName""angular"
    },
    "bootstrap": {
      "path""https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js",
      "globalName""bootstrap",
      "globalDependencies": ["jquery"]
    }
  },



In your webpart ts file, refer the files as below


import { SPComponentLoader } from '@microsoft/sp-loader';


let cssURL = "https://mercedessaga.sharepoint.com/sites/myfirstappcatalog/SiteAssets/bootstrap.min.css";
SPComponentLoader.loadCss(cssURL);
let cssURLIcon = "https://mercedessaga.sharepoint.com/sites/teja_dev/SiteAssets/CSS/font-awesome.css";
SPComponentLoader.loadCss(cssURLIcon);
SPComponentLoader.loadScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js', { globalExportsName: 'jQuery' }).then((jQueryany): void => {
SPComponentLoader.loadScript('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js',  { globalExportsName: 'jQuery' }).then((): void => {        
});











Comments

Popular posts from this blog

Powerapps overcome 2000 item limit from any datasource

PowerApps multiselect cascading dropdown and save an item to SharePoint List

Multi select cascading dropdown in Power Apps