cathalogrady
cathalogrady2mo ago

Access project dependency through Deno API

Maybe I am solving the wrong problem here, but I want to copy a deno dependency into my esbuild bundle so that it can be accesable on the web. The specific dependency I want is svelte. The idea was to mark it as external in the esbuild build and then just copy the dependency into the dist/ folder, see my build.ts file here:
import esbuild from "esbuild"
import sveltePlugin from "esbuild-svelte"
import { sveltePreprocess } from "svelte-preprocess"

esbuild.build({
entryPoints: ["main.ts"],
// external: ["svelte"],
platform: "browser",
format: "esm",
outdir: "dist/",
bundle: true,
minify: false,
sourcemap: true,
plugins: [
sveltePlugin({
preprocess: sveltePreprocess(),
}),
],
})
import esbuild from "esbuild"
import sveltePlugin from "esbuild-svelte"
import { sveltePreprocess } from "svelte-preprocess"

esbuild.build({
entryPoints: ["main.ts"],
// external: ["svelte"],
platform: "browser",
format: "esm",
outdir: "dist/",
bundle: true,
minify: false,
sourcemap: true,
plugins: [
sveltePlugin({
preprocess: sveltePreprocess(),
}),
],
})
4 Replies
2saturdayscode
2saturdayscode2mo ago
Can you specify which issue are incurring in? Is your project a Deno project? If so, esbuild won't be capable to resolve and load your imports.
cathalogrady
cathalogradyOP2mo ago
that is exactly the issue I am having with just a native deno project (only deno.json)
2saturdayscode
2saturdayscode2mo ago
yeah that's because esbuild is tailored for node projects, but fortunately esbuild supports plugin to extend its functionalities, try using this plugin: https://github.com/lucacasonato/esbuild_deno_loader/ Also I've made a rewrite of that plugin, I'd be glad if you tried it out: https://github.com/twosaturdayscode/esbuild-deno-plugin let me know if you are stuck
cathalogrady
cathalogradyOP2mo ago
ill try that out ! thanks (tomorrow)

Did you find this page helpful?