[英]How to get Magnific Popup working with Browserify
I'm trying to get Magnific Popup to work alongside Browserify and I can't seem to get it to work. 我正在尝试使Magnific Popup与Browserify一起工作,但似乎无法正常工作。 I don't have an in depth knowledge of the Browserify setup.
我对Browserify设置没有深入的了解。 All I keep getting is the following error:
我得到的只是以下错误:
Uncaught TypeError: cache.$btn_enlarge.magnificPopup is not a function
Any help would be gratefully received! 任何帮助将不胜感激!
Thanks, Tom 谢谢汤姆
I tried everything possible with the dist files — even with a shim. 我尝试使用dist文件进行所有可能的操作,甚至使用了垫片。 I ended up realising that the code it's wrapped in (see Gruntfile.js) makes it incompatible with Gulp and Browserify.
我最终意识到,它包装的代码(请参阅Gruntfile.js)使其与Gulp和Browserify不兼容。 Instead concat (either manually or with Gulp) the files in the src/js folder in this order:
而是按以下顺序(手动或使用Gulp)连接src / js文件夹中的文件:
core.js core.js
inline.js inline.js
ajax.js ajax.js
image.js image.js
zoom.js zoom.js
iframe.js iframe.js
gallery.js gallery.js
retina.js retina.js
It will work then. 然后它将起作用。 I've packaged the files for the latest release here if you want them: https://github.com/texelate/magnificPopupGulpBrowserify/blob/master/README.md
如果您需要这些文件,我已经将它们打包为最新版本: https : //github.com/texelate/magnificPopupGulpBrowserify/blob/master/README.md
You can use browserify-shim 您可以使用browserify-shim
npm install browserify-shim --save-dev
package.json 的package.json
"browserify": {
"transform": ["browserify-shim"]
},
"browserify-shim": {
"./path/to/magnific-popup.js": "magnific-popup",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.