[英]How to configure webpack for Bootstrap4 Popups and Tooltips (Popper.js)
I'm trying to update from bootstrap 4 alpha to beta and I'm using webpack! 我正在尝试从Bootstrap 4 Alpha更新到Beta,并且正在使用Webpack!
Up to now I've successfully migrated my code to be compatible, the only thing is that i cant get Tooltips and Dropdowns to work! 到目前为止,我已经成功迁移了代码以使其兼容,唯一的问题是我无法使工具提示和下拉菜单正常工作! According to the docs they said that those features depends on popper.js and the gave an example on how to configure i to work! 根据文档,他们说这些功能取决于popper.js,并给出了有关如何配置i的示例!
I've follow those instruction but now when i want to use dropdowns and tooltips i get TypeError: popper is undefined
我已经遵循了这些说明,但是现在当我想使用下拉菜单和工具提示时,出现TypeError: popper is undefined
webpack.mix.js webpack.mix.js
const path = require('path');
const webpack = require('webpack');
const { mix } = require('laravel-mix');
mix.webpackConfig({
output: {
path: path.join(__dirname, "/public"),
publicPath: '/',
chunkFilename: 'js/modules/[name].js'
},
plugins:[
new webpack.ProvidePlugin({
Moment: 'moment',
'window.Moment': 'moment',
Popper: ['popper.js', 'default'],
popper: ['popper.js', 'default'],
// 'window.Po': ['popper.js', 'default']
}),
new webpack.optimize.MinChunkSizePlugin({minChunkSize: 100000})
]
});
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.autoload({
vue: [ 'Vue', 'window.Vue' ],
// moment: ['window.moment', 'Moment'],
jquery: ['$','jQuery','window.jQuery'],
tether: ['window.Tether', 'Tether'],
axios: ['axios','window.axios'],
'cookies-js': ['Cookies']
});
mix.js('resources/assets/js/app.js', 'public/js')
.extract(['vue','lodash','cookies-js','jquery','moment','tether','bootstrap','axios'])
.sass('resources/assets/sass/app.scss', 'public/css')
.js('resources/assets/js/admin.js', 'public/js')
.sass('resources/assets/sass/admin.scss', 'public/css')
.version()
.browserSync({
proxy: 'localhost:8000'
});
I cant figure out what I'm missing here 我无法弄清楚我在这里想念的是什么
UPDATE 更新
HTML Code HTML代码
<li class="nav-drop dropdown">
<a href="#currency-menu" data-toggle="dropdown">{{ moneyCurrencyCode() }}</a>
<ul id="currency-menu" class="list nav-drop-menu dropdown-menu">
<li><a data-toggle="currency" data-currency="MZN" href="#">MZN</a></li>
<li><a data-toggle="currency" data-currency="ZAR" href="#">ZAR</a></li>
<li><a data-toggle="currency" data-currency="USD" href="#">USD</a></li>
<li><a data-toggle="currency" data-currency="EUR" href="#">EUR</a></li>
</ul>
</li>
This actually works for me: 这实际上对我有用:
let mix = require('laravel-mix');
let webpack = require('webpack');
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css')
.webpackConfig({
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
})
]
})
.version();
In order to use bootsrap4 (beta) popups, tooltips, dropdown using laravel webpack mix you've to download popper.js along with bootstrap 4 . 为了使用laravel webpack mix使用bootsrap4(测试版)弹出窗口,工具提示和下拉菜单,您必须将popper.js与bootstrap 4一起下载。
npm install bootstrap:4.0.0-beta popper.js --save
After that you've to edit the resources/assets/js/bootstrap.js file to include popper.js: 之后,您必须编辑resources / assets / js / bootstrap.js文件以包含popper.js:
try {
window.$ = window.jQuery = require('jquery');
window.Popper = require('popper.js/dist/umd/popper.js').default;
require('bootstrap/js/src/dropdown');
require('bootstrap/js/src/popover');
require('bootstrap/js/src/tooltip');
} catch (e) {
}
At the end you've to also edit webpack.mix.js file: 最后,您还必须编辑webpack.mix.js文件:
mix.autoload({
'jquery': ['$', 'window.jQuery', "jQuery", "window.$", "jquery", "window.jquery"],
'popper.js/dist/umd/popper.js': ['Popper', 'window.Popper']
});
After some investigations I figured out that the problem wasn't with the configuration but with the HTML code! 经过一番调查,我发现问题不在于配置,而在于HTML代码! Since i was migrating from bootstrap 4 alpha to beta i had to change the href="#currency-menu" to href="#" on the dropdown toogle so it looked has following 由于我是从Bootstrap 4 Alpha迁移到Beta的,因此我必须在下拉菜单中将href =“#currency-menu”更改为href =“#”,这样看来
HTML Code HTML代码
<li class="nav-drop dropdown">
<a href="#" data-toggle="dropdown">{{ moneyCurrencyCode() }}</a>
<ul id="currency-menu" class="list nav-drop-menu dropdown-menu">
<li><a data-toggle="currency" data-currency="MZN" href="#">MZN</a></li>
<li><a data-toggle="currency" data-currency="ZAR" href="#">ZAR</a></li>
<li><a data-toggle="currency" data-currency="USD" href="#">USD</a></li>
<li><a data-toggle="currency" data-currency="EUR" href="#">EUR</a></li>
</ul>
</li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.