How do I load bootstrap using npm?

后端 未结 7 412
无人共我
无人共我 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:16

      I'm using Laravel Mix (Webpack), so I had to add this alias to webpack.mix.js:

      mix.webpackConfig({
          ...
          resolve: {    
              ...
              alias: {        
                  "bootstrap": path.resolve(__dirname, "node_modules/bootstrap/dist/js/bootstrap.min.js"),
              }
          },
      });
      

      My package.json has "bootstrap": "^4.0.0", within devDependencies.

      Then in my javascript file for my view, I use:

      var $ = require('jquery');
      window.$ = $;
      require('bootstrap');
      

      https://getbootstrap.com/docs/4.0/getting-started/download/#npm also helped.

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