Is it possible to import a JS function to be used in a js.erb
file?
For example:
// hello_world.js
const helloWorld = () => console.log('hello world');
export default helloWorld;
And:
// our_file.js.erb
import helloWorld from 'path/to/hello_world.js';
helloWorld();
I've had a pop at it and can't get it firing, so presume the answer is no - will happily accept a one word answer if this is indeed the case.
If not, how does one go about getting this working? Thanks in advance for all help / constructive criticism / mockery.
Edit
I'm not sure the suggested duplicate is a duplicate of this - I'm specifically looking to import a function, not load an entire script into the DOM. Is this possible?