cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jonespossibly
Helper I
Helper 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
Helper I
Helper 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
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors