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

前端 未结 5 497
滥情空心
滥情空心 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:11

    In bootstrap": "^4.1.1" no need to import jquery and popper.js because those plugins will be already included when 'bootstrap' or bootstrap's plugins imported individually.

    Notice that if you chose to import plugins individually, you must also install exports-loader

    No need to require files require('exports-loader?file ... '); as mentioned here because this will be taken care automatically by just installing $ npm install exports-loader --save-dev

    import 'bootstrap'; // Import all plugins at once
    
    //
    // Or, import plugins individually
    //
    // import 'bootstrap/js/src/alert';
    // import 'bootstrap/js/src/button';
    // import 'bootstrap/js/src/carousel';
    // import 'bootstrap/js/src/collapse';
    // import 'bootstrap/js/src/dropdown';
    // import 'bootstrap/js/src/modal';
    // import 'bootstrap/js/src/popover';
    // import 'bootstrap/js/src/scrollspy';
    // import 'bootstrap/js/src/tab';
    // import 'bootstrap/js/src/tooltip';
    // import 'bootstrap/js/src/util';
    

    There is no need to do anything like below:

    const webpack = require('webpack');
    
    module.exports = {
      configureWebpack: {
        plugins: [
          new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery',
            'window.jQuery': 'jquery',
            Popper: ['popper.js', 'default']
          })
        ]
      }
    }
    

    I am a vue.js developer and in new vue-cli-3, we create vue.config.js in root and place code like above to register new plugin, but as said there is no need to do all this in bootstrap": "^4.1.1".

    Bootstrap's tooltip plugin is depend on popper.js and need to be enabled manually, so you can do like below in the component where you use tooltip element:

    
    

提交回复
热议问题