Bootstrap 4 Beta importing Popper.js with Webpack 3.x throws Popper is not a constructor

前端 未结 5 526
滥情空心
滥情空心 2020-12-28 17:32

So Bootstrap 4 Beta is out... yey! However Tether has been replaced by Popper.js for tooltip (and other features). I saw an error thrown in the con

5条回答
  •  情深已故
    2020-12-28 18:03

    While browsing Bootstrap 4 documentation. I actually found a section about Webpack which explains how to install it correctly. Following the Bootstrap - installing with Webpack documentation, the answer is to simply modify the webpack.config.js with the following:

    plugins: [
      // ...
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        Popper: ['popper.js', 'default']
      })
      // ...
    ]
    

    and let's not forget to import it in the main.ts

    import 'bootstrap';
    

    and voilà! We are back in business :)

提交回复
热议问题