简体   繁体   中英

How do I add a personal script to an existing node.js library?

I have a local copy of the hls.js library and I need to include a personal script with custom functions in it. How do I go about adding a new script to the library and how do I use the function written in the new script? Let's say that I want to add a script called hello.js that contains a function that logs "Hello World". When I call that function in my main.js I need it to execute. Any ideas on how to do this? Currently, I'm getting an error that the function is not defined. I placed the hello.js script in the src folder of the library but this (as expected) doesn't seem to work.

It should be possible to add functions to the exported hls.js object.

Your custom-script.js:

 var hls = require('hls.js') hls.customFunc1 = function () { } hls.customFunc2 = function () { } 

on main.js:

 require('custom-script') // your code follows 

Any other code would be able to use the custom functions by just require'ing hls.js .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM