Imagine having a function like this
index.js
greet = () => {
console.log('hello');
}
greet();
and you want it to execute as soon as the page loads, so you include greet();
. This works fine when the file is imported in your index.html
index.html
<! -- ... -->
<script src="./index.js"></script>
Now, you want to package this for others to use, so you publish it to npm and users can install it with
npm install greet-package
How will users run the greet()
function after installing the package?
I'm exploring different options, besides exporting and importing the function, is there a way to make the script run automatically for users who have installed the package via npm?