Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jonespossibly
Advocate I
Advocate I

Current method for importing external libraries?

So, I want to import bootstrap (https://getbootstrap.com/) and bootstrap-table (https://bootstrap-table.com/) into a visual i'm writing and the advice about how to add external libraries to the visual.ts seems to be a bit varying across different sources.

do i need to install via npm?  do i need to include the libraries in pbiviz.json externalJS?  do i use the CDN versions?

Do i need to separately install jquery?

 

i'm using:

powerbi-visuals-tools@4.0.4

"powerbi-visuals-api": "^3.8.4"

 

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @jonespossibly,

There were a lot of changes in v3 of the SDK  introduce Webpack and to mitigate the amount of additional work, so some older guides will likely include all the additional steps for tsconfig.json and pbiviz.json that you needed to make dependencies work previously.

You're best loading as much as you can via npm so that everything's bundled at build time. Loading libraries over the web can be tricky if the endpoint is not permissive enough to deal with the CORS restrictions in the sandboxed iframe.

npm install [package] --save-dev  is sufficient to make sure that your project has the dependency.

Webpack will bundle what you import in your source (providing there's a loader for it). With libraries that support TypeScript, this usually just works.

You can probably take a look at any of my production visuals on GitHub to get an idea of what the key files might look like - these all seem to be okay with just loading via npm and Webpack handling the imports via the usual build process.

Bootstrap can be installed via npm, but it uses sass (the SDK uses less) - therefore you're need to load the distribution .css file in your main visual entry point, kind of like this (I have used it previously, but don't think I ever put one into production, so I don't have any source I can link; the principle is the same though).

Last time I used Bootstrap, jQuery was it was optional, depending on whether you wanted to use the dynamic stuff or not (I think we also had to install popper.js on older versions for tooltips etc., although it looks like it might be streamlined now to just the bootstrap package). Although, if you specifically want jQuery, then it's best to install it via npm separately so that you get the version you want.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

2 REPLIES 2
jonespossibly
Advocate I
Advocate I

As usual, an excellent and detailed informative answer.

You sir, are a legend.

dm-p
Super User
Super User

Hi @jonespossibly,

There were a lot of changes in v3 of the SDK  introduce Webpack and to mitigate the amount of additional work, so some older guides will likely include all the additional steps for tsconfig.json and pbiviz.json that you needed to make dependencies work previously.

You're best loading as much as you can via npm so that everything's bundled at build time. Loading libraries over the web can be tricky if the endpoint is not permissive enough to deal with the CORS restrictions in the sandboxed iframe.

npm install [package] --save-dev  is sufficient to make sure that your project has the dependency.

Webpack will bundle what you import in your source (providing there's a loader for it). With libraries that support TypeScript, this usually just works.

You can probably take a look at any of my production visuals on GitHub to get an idea of what the key files might look like - these all seem to be okay with just loading via npm and Webpack handling the imports via the usual build process.

Bootstrap can be installed via npm, but it uses sass (the SDK uses less) - therefore you're need to load the distribution .css file in your main visual entry point, kind of like this (I have used it previously, but don't think I ever put one into production, so I don't have any source I can link; the principle is the same though).

Last time I used Bootstrap, jQuery was it was optional, depending on whether you wanted to use the dynamic stuff or not (I think we also had to install popper.js on older versions for tooltips etc., although it looks like it might be streamlined now to just the bootstrap package). Although, if you specifically want jQuery, then it's best to install it via npm separately so that you get the version you want.

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.