How to import libraries directly from index

Asked

Viewed 33 times

-2

I’ve been reading up on some topics on how to do this, but I haven’t found any to explain it. What I’d like to do is, instead of using:

<script src="node_modules/php/index.js">
</script>

I wanted to know if there is a way to pull everything you need, why there in src, I defined that I would pull from the index of php, but if in the code it asks a require of some other lib, how can I put this in it? I thought of using two src, being

<script src="node_modules/php/index.js" src="node_modules/execa/index.js">
</script>

But I don’t know if it works. Well, I keep getting on my console that php is asking for execa, but I don’t know how to add it right there in the code, how can I do that? I have the execa, but I don’t know how to do it right on the index.

.

1 answer

0

Use script import more than once:

<script src="node_modules/php/index.js"></script>
<script src="node_modules/execa/index.js"></script>

Use as many times as you need, but never more than one src within the same tag.

  • If I do <script src="node_modules/php/index.js"></script> its content closes in </script> then, when making a new script, it will be related to the previous?

  • It will. All scripts indexed in HTML will have their Javascript instantiated at the top of the page. That is, all libraries or scripts you insert will have access to each other the same functions and events declared in the script.

  • It means that when you insert several scripts all will be inserted in a single page. It will be like a large js file, sharing all the content among themselves.

  • I drew, so for that I have to import inside the head, and not in the body?

  • You can put it anywhere. The ideal is for you to always put javascript Imports at the end of html, before closing the body tag, so the content of the page will not need to wait for js to load to be displayed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.