简体   繁体   中英

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. I don't have an in depth knowledge of the Browserify setup. 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. I ended up realising that the code it's wrapped in (see Gruntfile.js) makes it incompatible with Gulp and Browserify. Instead concat (either manually or with Gulp) the files in the src/js folder in this order:

core.js

inline.js

ajax.js

image.js

zoom.js

iframe.js

gallery.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

You can use browserify-shim

npm install browserify-shim --save-dev

package.json

"browserify": {
  "transform": ["browserify-shim"]
},
"browserify-shim": {
  "./path/to/magnific-popup.js": "magnific-popup",
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM