sakuta96
sakuta962y ago

how to use esbuild_deno_loader for local file?

i have [join(tmpDir, './bundle.js')] as entry point (resulting as string e.g. c:\Users\User\AppData\Local\Temp\tempdir-33c4f2f8\bundle.js, but that gives me a Do not know how to load path error on console? what am i doing wrong?
5 Replies
NDH
NDH2y ago
Are you bundling a bundle.js?? You have what looks like you desired output as the entry point. an esbuild example // build.ts
import * as esbuild from "https://deno.land/x/esbuild@v0.14.51/mod.js";
import { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.2/mod.ts";

type buildCFG = {
entry: string[],
out: string,
minify: boolean
}

// bundles an entrypoint into a single ESM output.
const build = async (cfg: buildCFG) => {
await esbuild.build({
plugins: [denoPlugin({})],
entryPoints: cfg.entry,
outfile: cfg.out,
bundle: true,
minify: cfg.minify,
keepNames: true,
banner: { js: '// deno-lint-ignore-file' },
format: "esm"
}).catch((e) => console.info(e));
esbuild.stop();
}

const cfg: buildCFG = {
entry: ["./mod.ts"],
minify: true,
out: './bundle.js'
}

build(cfg).then(() => {
console.log('Built bundle.js!')
}).catch((err) => {
console.info('build err - ', err)
})

// deno run build-A --unstable build.ts
import * as esbuild from "https://deno.land/x/esbuild@v0.14.51/mod.js";
import { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.2/mod.ts";

type buildCFG = {
entry: string[],
out: string,
minify: boolean
}

// bundles an entrypoint into a single ESM output.
const build = async (cfg: buildCFG) => {
await esbuild.build({
plugins: [denoPlugin({})],
entryPoints: cfg.entry,
outfile: cfg.out,
bundle: true,
minify: cfg.minify,
keepNames: true,
banner: { js: '// deno-lint-ignore-file' },
format: "esm"
}).catch((e) => console.info(e));
esbuild.stop();
}

const cfg: buildCFG = {
entry: ["./mod.ts"],
minify: true,
out: './bundle.js'
}

build(cfg).then(() => {
console.log('Built bundle.js!')
}).catch((err) => {
console.info('build err - ', err)
})

// deno run build-A --unstable build.ts
The above utility builds/bundles starting from ./mod.ts and outputs a bundle at './bundle.js`
sakuta96
sakuta962y ago
just stupid naming xd but basically i have a full path as entry point as i'm in a totally different directory than the cwd like i already mentioned, my entry point is a full path like c:\Users\User\AppData\Local\Temp\tempdir-33c4f2f8\file.js and that doesn't work when i use the deno plugin
NDH
NDH2y ago
I see. Sorry I wasn't any help.
KyleJune
KyleJune2y ago
I haven't tried using an absolute path for the entrypoint. I've always used a relative path. I have used esbuild where the directory is different than the current directory. To do that, i set the workingDirectory to the directory my app is in, then set entry point as a relative path from the workingDirectory. Oh actually the build option is called absWorkingDir. I believe the outdir can be an absolute path if you want or need it to be outside of the absWorkingDir that you set.
sakuta96
sakuta962y ago
oh thanks @kylejune1415, i'll try it out right tomorrow! sounds promising