Shi*_*ain 3 javascript jquery magnific-popup webpack
我已经通过“npm i magnific-popup”命令安装了 magnificPopup,然后将其导入到 app.js 文件中。但在浏览器控制台中它显示(magnificPopup不是一个函数)
应用程序.js
import $ from "jQuery";
window.$ = window.jQuery = $;
import "magnific-popup";
$(document).ready(function() {
$('.play-btn').magnificPopup({ type: 'video' });
});
Run Code Online (Sandbox Code Playgroud)
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'
}),
]
}
Run Code Online (Sandbox Code Playgroud)
我已经解决了问题
jQuery不需要在app.js中导入
修复 app.js 文件后如下所示
import "magnific-popup";
$(document).ready(function() {
$('.play-btn').magnificPopup({ type: 'video' });
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5764 次 |
| 最近记录: |