8000 GitHub - disberd/DenoESBuild.jl: Julia wrapper for the `esbuild.build` function via Deno_jll
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

disberd/DenoESBuild.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DenoESBuild.jl

Build Status Coverage Aqua QA

DenoESBuild.jl is a Julia package that provides a simple interface for bundling JavaScript/TypeScript code using the build function of the esbuild library through Deno using the Deno_jll.jl package.

It also exploits the esbuild-deno-plugin to allow deno caching, module resolution and loading as part of the esbuild build process.

Note

When bundling files that refer to remote imports (e.g. npm:...), an internet connection is in principle required to fetch the remote libraries. This is not the case if the target libraries are already availabile in the Deno cache.

This package does not export any function, but the following methods are considered part of the public API:

  • DenoESBuild.build
  • DenoESBuild.bundle
  • DenoESBuild.JSCode

Example Use

The two examples below are both for the bundle function as that is the easiest way to use this package.

The DenoESBuild.bundle function is simply a small wrapper around the DenoESBuild.build function, that automatically sets the following flags to be passed as options to esbuild.build:

  • bundle: true
  • minify: true
  • format: "esm"
  • platform: "browser"

See the docstring of the DenoESBuild.build function for more details on its use.

Bundle from input code

Here is a simple code snippet that will generate a single js (stored in ./dist/main.js) file containing an ESM module that extracts the ceil function from the lodash library and re-exports it

using DenoESBuild

DenoESBuild.bundle(
    DenoESBuild.JSCode("""
        import { ceil } from "npm:lodash-es"
        export { ceil }
    """),
    "dist/main.js"
)

Bundle from file

This works even for a module structure divided into multiple files, as in the simple example explained below, which is mirroring the structure of the test/multifile subfolder.

Folder Structure

test/multifile/
├── module.ts         # Source module with tree-shakable imports from the `npm:date-fns` library
├── main_remote.ts    # Imports directly from `module.ts`
├── main_local.ts     # Imports from the bundled output
└── bundled.js        # Bundled output (created by esbuild, not present by default)

module.ts contents

import { format, differenceInDays } from "npm:date-fns";

// Only using the format function (differenceInDays will be tree-shaken out)
function formatCurrentDate() {
  const now = new Date();
  // Format: "Monday, January 1, 2023"
  console.log("CHECK THIS");
  return format(now, "EEEE, MMMM d, yyyy");
}

export { formatCurrentDate };

main_remote.ts contents

import { formatCurrentDate } from "./module.ts";

console.log(formatCurrentDate());

main_local.ts contents

import { formatCurrentDate } from "./bundled.js";

console.log(formatCurrentDate());

Creating the bundle

using DenoESBuild

dir = joinpath("test", "multifile")
DenoESBuild.bundle(
    "module.ts", # Specifies that the file `module.ts` should be bundled
    "bundled.js"; # Specifies the file that will contain the bundled code
    dir # Specifies that the build command should be run in the `test/multifile` directory
)

About

Julia wrapper for the `esbuild.build` function via Deno_jll

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0