How to import popper.js?

后端 未结 11 2214
广开言路
广开言路 2020-12-25 10:12

It seems to be a lame question, but I cannot to figure it out. How to import popper.js which comes toghether with Bootstrap 4 beta?

I use bower and I\'ve installed B

相关标签:
11条回答
  • 2020-12-25 10:50

    Ways to get popper.js: Package, CDN, and Local file

    The best way depends on whether you have a project with a package manager like npm.

    Package manager
    If you're using a package manager, use it to get popper.js like this:

    npm install popper.js --save
    

    CDN
    For a prototype or playground environment (like http://codepen.io) or may just want a url to a CDN file:

    https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.js https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.min.js

    note: Bootstrap 4 requires the versions under the umd path (more info on popper/bs4).

    Local file

    Just save one of the CDN files to use locally. For example, paste one of these URLs in a browser, then Save As... to get a local copy.

    https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.js https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.min.js

    0 讨论(0)
  • 2020-12-25 10:51

    IN bootstrap 4 you need to add popper js for tooltip, I also don`t understand why bootstrap 4 includes external popper.js, It means bootstrap makes more complicated instead of easy when upgrading to the latest versions.

    You can import popper js before bootstrap on angular or a simple html, Angular import would be like this

    npm install popper.js --save
    

    then go to .angular-cli.json and change the order like below.

     "scripts": [
            "../node_modules/jquery/dist/jquery.slim.min.js",
            "../node_modules/tether/dist/js/tether.min.js", 
            "../node_modules/popper.js/dist/umd/popper.js",              
            "../node_modules/bootstrap/dist/js/bootstrap.min.js"
          ],
    

    you can also use CDN direct call popper js into your any project.

    https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.js https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.5/umd/popper.min.js

    0 讨论(0)
  • 2020-12-25 10:53

    I really don't understand why Javascript world trying to do thing more complicated. Why not just download and include in html? Trying to have something like Maven in Java? But we have to manually include it in html anyway? So, what is the point? Maybe someday I will understand but not now.

    This is how I can get it

    • download & install NodeJs
    • run "npm install popper.js --save"
    • then I get this message

      popper.js@1.12.7 added 1 package in 1.215s

    • then where is "add package" ? very informative , right? I found it in my C:\Users\surasin\node_modules\popper.js\dist

    Hope this help

    0 讨论(0)
  • 2020-12-25 10:55

    add popper**.js** as dependency instead of popper (only): see the difference in bold.

    yarn add popper.js , instead of yarn add popper

    it makes the difference.

    and include the script according your needs:

    as html or the library access as a dependency in SPA applications like react or angular

    0 讨论(0)
  • 2020-12-25 10:55

    You can download and import all of Bootstrap, and Popper, with a single command using Fetch Injection:

    fetchInject([
      'https://npmcdn.com/bootstrap@4.0.0-alpha.5/dist/js/bootstrap.min.js',
      'https://cdn.jsdelivr.net/popper.js/1.0.0-beta.3/popper.min.js'
    ], fetchInject([
      'https://cdn.jsdelivr.net/jquery/3.1.1/jquery.slim.min.js',
      'https://npmcdn.com/tether@1.2.4/dist/js/tether.min.js'
    ]));
    

    Add CSS files if you need those too. Adjust versions and external sources to meet your needs and consider using sub-resource integrity checking if you're not hosting the files on your own domain or don't trust the source.

    0 讨论(0)
  • 2020-12-25 10:59

    Install popper.js with spesific version number like this:

    bower install popper.js@^1.16.0
    

    Now u can find dist folder and popper.min.js file.

    0 讨论(0)
提交回复
热议问题