D
Deno

help

How to bundle my project

Wweegee10/19/2023
I have a mod.js file that I wrote with Deno and I want to bundle it and it depends on bunch of other file I ran esbuild mod.js --bundle --format=esm --outdir=dist and I try to use that in the browser but it doesn't download the dependecies
No description
DAHDeno AI Helper10/19/2023
According to the documentation, the deno bundle command has been deprecated and it's recommended to use alternatives like deno_emit, esbuild, or rollup. However, it's important to note that the output of deno bundle is intended for consumption in Deno and not for use in a web browser or other runtimes. Depending on the input, it may work in other environments, but if you wish to bundle for the web, the documentation recommends other solutions such as esbuild. If you're having issues with esbuild not downloading the dependencies, it might be because esbuild doesn't handle dependency management like a package manager would. It only bundles the code that's directly imported in your files. If your dependencies aren't being included, it might be because they're not being directly imported in your code. If you're looking to create a bundle that includes all dependencies, you might want to consider using a tool like rollup or webpack which have more advanced code-splitting and tree-shaking capabilities. Remember, the information I provided about esbuild not downloading dependencies isn't in the documentation, it's general advice based on common bundling practices. 🦕
AJAlex Jeffcott10/19/2023
I wish that Deno would officially support a working out-of-the-box solution to bundling which would work for 'just Deno' and for web applications. That developers new to Deno would have to spend any time at all writing or debugging esbuild plugins for a new project is absurdly off-putting. I some how get the impression that people want to wait around for import assertions to be fleshed out…
LLeokuma10/19/2023
They said that bundling is not as trivial as it looks and decided to let it to userland Have a look at this module:
LLeokuma10/19/2023
Packup
📦 Zero-config web application packager for Deno 🦕
Wweegee10/19/2023
@Leokuma How would I use it to package my js project into a js file I have this as my build.js
import { esbuild, cache, load } from "./deps.js";

const importMap = { imports: {} };
const env = await load({ export: true });

let envVariables = {};

for (const [key, value] of Object.entries(env)) {
// That's how esbuild likes it
envVariables["process.env." + key] = `"${String(value)}"`;
}

console.log("Bundling..");

esbuild
.build({
entryPoints: ["src/mod.js"],
bundle: true,
format: "esm",
outfile: "dist/wallet.js",
plugins: [cache({ importMap, directory: "./cache" })],
define: envVariables,
})
.then(() => {
console.log("Bundling Completed");
esbuild.stop();
})
.catch((e) => console.log("Error occured while bundling library: " + e));
import { esbuild, cache, load } from "./deps.js";

const importMap = { imports: {} };
const env = await load({ export: true });

let envVariables = {};

for (const [key, value] of Object.entries(env)) {
// That's how esbuild likes it
envVariables["process.env." + key] = `"${String(value)}"`;
}

console.log("Bundling..");

esbuild
.build({
entryPoints: ["src/mod.js"],
bundle: true,
format: "esm",
outfile: "dist/wallet.js",
plugins: [cache({ importMap, directory: "./cache" })],
define: envVariables,
})
.then(() => {
console.log("Bundling Completed");
esbuild.stop();
})
.catch((e) => console.log("Error occured while bundling library: " + e));
LLeokuma10/19/2023
oh wait I just realized... Not everything from the Standard Library can run in the browser. For example, you're using dotenv, which doesn't work in the browser. So even if you bundle it correctly, it still probably won't work
Wweegee10/19/2023
yea I have Deno in my code
Wweegee10/19/2023
No description
Wweegee10/19/2023
Should I just switch to node ?
LLeokuma10/19/2023
you will have the same problem with Node if you use Node-specific APIs like fs for example if you want your module to be browser-compatible, ideally you should get rid of all those APIs and use Web APIs only there are solutions (eg Browserify) that can turn Node code into browser-compatible code, but they are limited, they don't always work
Wweegee10/19/2023
I don't get where I'm using Deno std lib anywhere in my code, the only place i use dotenv is in the build.js
LLeokuma10/19/2023
run deno info mod.js. It should show you
Wweegee10/19/2023
That fixed it I just moved esbuild deps from the deps.js which I use in my code to build.js

Looking for more? Join the community!

Recommended Posts
Odd server requests on my Delpoy project...I was logging the requested paths to static files yesterday while troubleshooting an issue with a seerror on installingi do not know if im doing it right or something elseDeno equivalent os.cpus().lengthWhat’s the Deno Equivalent for `os.cpus().length`?How can I get deno to access internal packages from a workspace in npm or bun?I have the following workspace setup. I would like to have a deno/oak/kv project in the same folderHow to resolve requires without `.js` extension in a very basic NPM resolver?I have an NPM resolver that without caching that expects everything to be in a `node_modules` folderHow do I have a subrouter in Oak?I want to use a subrouter in oak to handle part of the routing, how would I do that in Oak? here is rust ffi buffer overflowhi, do i have to null-terminate array when using rust ffi? i'm getting buffer overflows. ```rs #[no_How to actually sign out using deno_kv_authNot sure if bug or feature, but I have problems signing out from deno_kv_auth. I'm using Auth0 for tDistroless Docker image fails with `libc.so: cannot open shared object file: No such file`I am building a 1:1 with a Node project using the same base for a docker image `distroless/cc`. BothBootstrapping a minimal node-compatible runtimeI'm trying to bootstrap a minimal node-compatible runtime, so I've basically been copying and pastinI want to adjust around tls using fetch APIWith nodejs, you could specify a cipher suite or version to be used with tls. Can't you do the same RUN deno task in DockerfileI have made a script to make DB migrations happen using "deno task migration", and I'd love for it tHelp Web.jsrq need help in web.js \ ```js window.paypal .Buttons({ style: { shape: "rect", laUnable to load env variables in localI'm starting again with deno since a long time with a small telegram bot using the `grammy` frameworWhy Bad resource ID occurs?I ran the following and got `error: BadResource: Bad resource ID` on seek. ```typescript import { toStorybook: some lightweight alternative for Deno?Do you know some lightweight alternative for [Storybook](https://storybook.js.org) to run on Deno?How can i change the location of Cache.open('somedb')We're deploying to docker containers which needs to write to an attached volume (specific path)How do I make Objects, Maps, etc. in rusty_v8 into easy-to-understand String?Hello. I wrote the following code in rusty_v8 ```rs let isolate = &mut v8::Isolate::new(Default:Usage of Deno.Command?Hey guys we use Deno.run to launch shell cmd and pipe the result to log. But Deno.run will be deprecWhen the destination server is down, WebSocketStream stops and the program crashes.I'm running the following code: ```const ws = new WebSocketStream("wss://localhost"); setInterval((