Kay
Kay3w ago

Emit with dynamic imports?

Does deno emit work with dynamic imports?
3 Replies
Deno AI Helper
Yes, Deno's deno compile command supports dynamic imports. According to the documentation, if your dynamic import statements are statically analyzable, meaning you use string literals inside import(), the specifiers will be automatically included in the produced binaries. Here's an example from the documentation:
const dynamicModule = await import("./dynamic_module.js");
console.log(dynamicModule.hello());

export function hello() {
return "hello world!";
}

// Then you compile your program like this:
// $ deno compile -o dynamic_import_example main.js
// Compile file:///dev/main.js
// Emit dynamic_import_example
// $ ./dynamic_import_example
// hello world!
const dynamicModule = await import("./dynamic_module.js");
console.log(dynamicModule.hello());

export function hello() {
return "hello world!";
}

// Then you compile your program like this:
// $ deno compile -o dynamic_import_example main.js
// Compile file:///dev/main.js
// Emit dynamic_import_example
// $ ./dynamic_import_example
// hello world!
For cases where the specifiers are not statically analyzable, you can use the new --include flag to specify additional files to include in the binary. This flag can be used multiple times to include multiple files. 🦕
Deno AI Helper
🦕 Oops! Can you pinpoint where I went wrong to help me improve? 📈
Kay
Kay3w ago
i was not talking about the deno compile command. i was talking abbout the deno emit package