0

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?

omega
  • 35,693
  • 74
  • 215
  • 425

1 Answers1

0
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

omega
  • 35,693
  • 74
  • 215
  • 425