How do I load bootstrap using npm?

后端 未结 7 437
无人共我
无人共我 2021-02-01 15:35

I have a npm project that uses jquery.

var $ = require(\'jquery\');

I also have an index html file that references bootstrap.

  • 7条回答
    •  无人及你
      2021-02-01 16:13

      Assuming you want to install the latest version of Bootstrap 4, and that you are using node 10+ which uses npm at least 5.6+ (I used it for node v12.14.1 and npm 6.13.6, and it works properly):

      npm install bootstrap
      npm install jquery
      npm install popper.js
      

      Notice that you don't need to pass --save since after npm 5.0.0 installed modules are added as a dependency by default.

      Now, assuming you have a file called index.html at the same directory of node_modules, you need to add the following to your head tag:

      
      
      
      
      
      
      

      You also need to add the following before :

      
      
      
      
      

      Notice the comment: jQuery first, then Popper.js, then Bootstrap JS. This is important since Bootstrap depends upon JQuery and Popper.js.

    提交回复
    热议问题