Closed ghost closed 4 years ago
I looked at the source code for flickity
. Its main
file resolves to flickity/js/index.js
, not one of the flickity.pkgd*.js
files. Those files appear to be for the global environment and contain the code that attaches flickity as a jQuery plugin.
Therefore, it looks like Flickity is meant to be used directly without jQuery in a fully-featured module environment, like you get with Webpack.
In your application code then, you want something like this (adapted from the docs):
import Flickity from 'flickity'
document.addEventListener('DOMContentLoaded', () => {
const elem = document.querySelector('.main-carousel');
const flkty = new Flickity(elem, {
contain: true
});
})
You can leave jQuery out of this interaction altogether.
Sweet! Thanks a lot @rossta.
Rails 6, Webpacker and Flickity
Result: TypeError: $(...).flickity is not a function
rails webpacker:install
,yarn add jquery
andyarn add flickity
all ran successfully.HTML
app/javascript/packs/application.js
config/webpack/environment.js
node_modules/flickity/dist/