scriptファイルのpathから相対Pathでindex.htmlとかcssファイルにアクセスできるようにしたい。
そのためにscript自身のpathを取得する最低限のソースが以下。
そのためにscript自身のpathを取得する最低限のソースが以下。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from "https://deno.land/std@0.97.0/path/mod.ts"; | |
function pathResolver(meta: ImportMeta): (p: string) => string { | |
return (p) => path.fromFileUrl(new URL(p, meta.url)); | |
} | |
const resolve = pathResolver(import.meta); | |
function test(pathBefore: string){ | |
const pathAfter = resolve(pathBefore) | |
console.log('['+pathBefore+'] -> ['+pathAfter+']') | |
} | |
test("./data/test.txt") | |
test("./css.css") | |
test("/css.css") |
0 件のコメント:
コメントを投稿