<p dir="auto">Is there a way to include static assets alongside a module that can be installed using deno install?</p>
<h2 dir="auto">Problem</h2>
<p dir="auto">I often find myself needing to load non-JavaScript non-TypeScript assets, and various problems arise:</p>
<ul dir="auto">
<li>Local module (in git repo) has to use <code class="notranslate">fs</code> but remote module has to use <code class="notranslate">fetch</code>.</li>
<li>The assets cannot be cached.</li>
<li>The assets cannot be bundled.</li>
</ul>
<h2 dir="auto">Suggestion</h2>
<p dir="auto">Add some way to annotate assets using comments, and <code class="notranslate">fetch</code> should support those assets. For example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// @deno-asset './assets/foo.wasm'
// @deno-asset './assets/bar.png'
await fetch(new URL('./assets/foo.wasm', import.meta.url))
await fetch(new URL('./assets/bar.png', import.meta.url))
// --allow-net is not required since it reads from cache"><pre class="notranslate"><span class="pl-c">// <span class="pl-k">@deno</span>-asset './assets/foo.wasm'</span>
<span class="pl-c">// <span class="pl-k">@deno</span>-asset './assets/bar.png'</span>
<span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">URL</span><span class="pl-kos">(</span><span class="pl-s">'./assets/foo.wasm'</span><span class="pl-kos">,</span> <span class="pl-k">import</span><span class="pl-kos">.</span><span class="pl-c1">meta</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-k">new</span> <span class="pl-smi">URL</span><span class="pl-kos">(</span><span class="pl-s">'./assets/bar.png'</span><span class="pl-kos">,</span> <span class="pl-k">import</span><span class="pl-kos">.</span><span class="pl-c1">meta</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-c">// --allow-net is not required since it reads from cache</span></pre></div>
<h2 dir="auto">Alternatives</h2>
<p dir="auto"><del>There is <a href="https://github.com/tc39/proposal-asset-references">asset reference proposal</a> that is likely not going to get to stage 3 anytime soon.</del></p>
<p dir="auto"><a href="https://github.com/tc39/proposal-import-assertions">import assertion proposal</a> had reached stage 3.</p>