ChilliSniff
ChilliSniff3y ago

import a locel module from a webmodule

I have a module that i inport into my local scope and that module should also import a module from my local scope and not from its url , is this possible ?
3 Replies
ChilliSniff
ChilliSniffOP3y ago
if i use a module from a server in my local scope , can the script from the server import something from my local scope ? /home/user/local.js
import {script} from "https://deno.land/mymod/script.js"
import {script} from "https://deno.land/mymod/script.js"
/home/user/test.js
console.log("test")
console.log("test")
https://deno.land/mymod/script.js
var test = import("./test.js")
var test = import("./test.js")
AapoAlas
AapoAlas3y ago
So, as said this is how you'd do it: local.js
import { loadScript } from "https://deno.land/mymod/script.js";
loadScript(import.meta.url);
import { loadScript } from "https://deno.land/mymod/script.js";
loadScript(import.meta.url);
https://deno.land/mymod/script.js
export const loadScript = baseUrl => import(new URL("./test.js", baseUrl));
export const loadScript = baseUrl => import(new URL("./test.js", baseUrl));
You can also use the std/fs resolve function and there's some helper function in std to get a fs path from a URL to help you along. You can also try this out by creating a local script.js and using an import map to "rename" it into https://deno.land/mymod/script.js, I think.
ChilliSniff
ChilliSniffOP3y ago
oh i seee, thanks ! i tried it before but i was just passing a absolute system path like /var/www/html i just was missing the file:/// infront of it ! cool, thank you for your help but now i wasted some resources only for this test module https://deno.land/x/deno_module_playground@0.3 well i think i may be using it in the future for further tests

Did you find this page helpful?