I have to merge several files from my website with webpack, and for that I need to work with JS modules.
This is a child file.
export default () => {
$('[data-direction]').on('click', switchFeatured)
function switchFeatured (event) {
const icon = $(event.currentTarget);
if (icon.data().direction === 'right') {
if (featuredCurrent < featuredTotal) {
featuredCurrent++;
}
} else {
if (featuredCurrent > 1) {
featuredCurrent--;
}
}
$('#featured-list').css('left', ( (featuredCurrent - 1) * -100) + '%');
}
}
This is the main file.
window.$ = require ('jquery')
import Default from './pages/default'
import Home from './pages/home'
Default();
Home();
It’s working this way, but is the way I export and use the imported modules correct? Got a better way?