我试着在谷歌上搜索这个话题的解决方案,但是他们都是老的webpack或者不工作的解决方案。在webpack网站上也是没有帮助的。请帮帮Here is the error
webpack.config.js
const webpack = require('webpack');
const path = require('path');
module.exports = {
entry: {
'bundle.js': [
path.resolve(__dirname, 'js/back-to-top.js')
]
},
output: {
filename: '[name]',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
"window.jQuery": "jquery",
})
]
};back-to-top.js
$(document).ready(function(){
//Back to top
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-to-top').click(function () {
$('#back-to-top').tooltip('hide');
$('body,html').animate({
scrollTop: 0
}, 800);
return false;
});
$('#back-to-top').tooltip('show');
});发布于 2018-04-21 19:49:42
看起来.tooltip是一个jQuery插件,你也import了吗?如果是这样,请确保在运行给定代码之前已将其导入。
发布于 2018-04-22 00:26:00
我找到了一种解决方案,不是在插件中添加ProvidePlugin,而是使用以下代码
externals: {
jquery: 'jQuery'
}https://stackoverflow.com/questions/49954758
复制相似问题