D
Deno

help

import a locel module from a webmodule

CChilliSniff9/21/2022
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 ? 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")
AAapoAlas9/21/2022
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.
CChilliSniff9/21/2022
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

Looking for more? Join the community!