If some JS code has this
import("path/to/file.js")
and then file.js has this
export default async function() {
// I want to get "path/to" here
return {};
}
How can I get the directory of where file.js
is?
If some JS code has this
import("path/to/file.js")
and then file.js has this
export default async function() {
// I want to get "path/to" here
return {};
}
How can I get the directory of where file.js
is?
export default async function() {
var current_file = import.meta.url;
var dir_path = import.meta.url.substring(0, import.meta.url.lastIndexOf("/"));
return {};
}
See compatibility here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta