I enqueue JS file as a script with type="module" and need to get the src attribute of the script inside of the script
But if I trying
document.currentScript
it returns null
Is there a similar way as currentScript for type="module" ?
Ok, I see there is a duplicate so I’ve closed my question
>Solution :
import.meta
You can use import.meta.
For example:
In page.html:
<script src="module1.js" type="module"></script>
In module1.js:
import './module2.js';
console.log(import.meta);
In module2.js:
console.log(import.meta);