我已经通过“npm i magnific-popup”命令安装了 magnificPopup,然后将其导入到 app.js 文件中。但在浏览器控制台中它显示(magnificPopup 不是函数)
app.js
import $ from "jQuery";
window.$ = window.jQuery = $;
import "magnific-popup";
$(document).ready(function() {
$('.play-btn').magnificPopup({ type: 'video' });
});
webpack.config.js
var path = require("path");
var webpack = require('webpack');
module.exports = {
entry: {
app: "./app/assets/scripts/app.js",
vendor: "./app/assets/scripts/vendor.js"
},
output: {
path: path.resolve(__dirname, "./app/temp/scripts"),
filename: "[name].js"
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ["es2015"]
}
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
'$': 'jquery',
'jQuery': 'jquery',
'window.jQuery': 'jquery'
}),
]
}
最佳答案
我已经解决了问题
jQuery不需要在app.js中导入
修复 app.js 文件后如下所示
import "magnific-popup";
$(document).ready(function() {
$('.play-btn').magnificPopup({ type: 'video' });
});
关于javascript - magnificPopup 无法与 webpack 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50462457/