Closed mcfiredrill closed 6 years ago
Does your code work if you run it with FASTBOOT_DISABLED=true ember s
?
(Also, I hope you're only serving fastboot to bots, because if you serve the HTML to users they're going to see everything weirdly jump when masonry finally takes over and runs in the browser.)
I think you're going to need to make sure masonry doesn't even try to load in fastboot because it won't work there. One thing you could try is to move import 'masonry-layout'
into a browser-only initializer.
Does your code work if you run it with FASTBOOT_DISABLED=true ember s?
Thanks for the reply. I don't get that error anymore if I disable fastboot, however I am getting this error browser side. (Sorry I forgot to mention that originally.)
TypeError: Ember.$(...).masonry is not a function
I should be able to avoid loading masonry in fastboot to avoid the first error.
I think I see what's going on here. masony and flickity (as reported in #68) install themselves via side-effect onto jQuery. We probably need to mark jQuery
as an external dependency so they find the existing one rather than trying to pull in their own.
My guess above was wrong, because neither of these things has a direct dependency on jQuery, because both consider it optional. They both have have documented steps that are required to make them work as jQuery plugins when building with webpack:
https://flickity.metafizzy.co/api.html#flickity-setjquery https://masonry.desandro.com/extras.html#webpack
If you follow those steps, both work with ember-auto-import. I confirmed by adding jquery-bridget, masonry-layout, and flickity to a project and putting this into app.js:
import $ from 'jquery';
import jQueryBridget from 'jquery-bridget';
import Masonry from 'masonry-layout';
import Flickity from 'flickity';
// flickity needs both of these steps to get full event support
Flickity.setJQuery( $ );
jQueryBridget( 'flickity', Flickity, $ );
// masonry just need this one
jQueryBridget( 'masonry', Masonry, $ );
After that you'll see that $('.something').masonry
and $('.something').flickity
are defined.
But my recommendation is to use these libraries directly, instead of plugging them into jQuery. Using them via jQuery buys you very little in an Ember app, because you already have the element, so you don't need jQuery to help find it:
import Flickity from 'flickity';
export default Component.extend({
didInsertElement() {
new Flickity(this.element, {
// some options
})
}
});
Thanks for this Ed
Hi I'm trying to use masonry-layout with auto-import.
app/routes/blog.js
I get this error, I guess because its trying to run masonry in fastboot maybe?