By using require(./filename)
I can include and execute the code inside filename without any export defined inside filename itself.
What is the equivalent in ES6 using import
?
Thanks
By using require(./filename)
I can include and execute the code inside filename without any export defined inside filename itself.
What is the equivalent in ES6 using import
?
Thanks
The answer should be changed, this does not work anymore as is. If you still want to use import './otherfile.js'
without using exports, just to split your code up for readability you have to add type="module
to the import of your js file in the html
<script src="js/main.js" type="module"></script>
Edit: It seems you also have to add the .js (otherfile.js) or it doesn't work anymore either.
The equivalent is simply:
Here are some of the possible syntax variations:
SOURCE: MDN