2

I spent my day searching for a solution but I didn't mange to solve this, first am new to webpack and not much advanced with js I managed after a long day to export my 2 simple functions :

script.js

function scrollright(el) {
...
}

function scrollleft(el) {
...
}

export {
scrollright,
scrollleft,
}

and import them in index.js

import { scrollleft, scrollright } from './script';
scrollleft();
scrollright();

building finishes successfully but the problem is that those function take parameters and those parameters are passed to js (previously before webpack) through html onclick tag like this :

onclick="scrollleft(this)"

I didn't figure out how I can transfer this completely to webpack maybe it's a newbie question but I can't find anything that helps me or at least if this is not possible a simple clarification or a proposed solution would be appreciated.

beginner
  • 45
  • 8

1 Answers1

1

Okay so I managed to solve it like this :

index.js

import { scrollleft, scrollright } from './script';
window.scrollleft = scrollleft;
window.scrollright = scrollright;

so it seems that adding window will make the function global or smthg like that I don't understand 100% what this mean but if anyone faced this problem hope this newbie Q/A will help you and save you a day or more ;)

reference (for maybe clearer explanation) : https://stackoverflow.com/a/35825562/9153588

beginner
  • 45
  • 8