In StackBlitz it's possible to add another JS file(s) (besides index.js) but it seems that only index.js is actually being loaded. All the functions defined in other JS files created in the same (root) folder are just undefined when I try to call them within the index.js. I tried to 'activate' other files via HTML (<script src='./filename.js'> tag) but it didn't help. What am I doing wrong?
Asked
Active
Viewed 2,222 times
12
Serg
- 6,742
- 4
- 36
- 54
2 Answers
10
in index.js:
import {func} from './myscript.js';
In myscript.js:
exports.func = function(){...}
Syr
- 166
- 1
- 4
-
But then how do you use a function described in `myscript.js` inside `index.js` ? – CodyBugstein Oct 19 '18 at 18:21
-
@CodyBugstein, like this: https://stackblitz.com/edit/svelte-imozn2?file=index.js – P.S. Oct 19 '18 at 18:56
-
Can you also take a look at this question? https://stackoverflow.com/questions/52898665/how-do-you-load-a-json-in-a-stackblitz-project – CodyBugstein Oct 19 '18 at 19:22
-
(btw I cannot award bounty for another 21 hours, but I will asap) – CodyBugstein Oct 19 '18 at 19:22
4
I have tried this and worked for me.
In index.js add below statement
import "./myscript.js";
Ranganath SN
- 41
- 3