• Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Deno module resolution for `esbuild`

esbuild_deno_loader

Deno module resolution for esbuild.

  • Support for file:, https:, and data: specifiers
  • Support for npm: specifiers
  • Support for import maps (including embedded into deno.json)
  • Native loader using Deno's global cache directory
  • Portable loader that words in environments with limited permissions

Example

This example bundles an entrypoint into a single ESM output.

import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
// Import the WASM build on platforms where running subprocesses is not
// permitted, such as Deno Deploy, or when running without `--allow-run`.
// import * as esbuild from "https://deno.land/x/[email protected]/wasm.js";

import { denoPlugins } from "https://deno.land/x/[email protected]/mod.ts";

const result = await esbuild.build({
  plugins: [...denoPlugins()],
  entryPoints: ["https://deno.land/[email protected]/bytes/mod.ts"],
  outfile: "./dist/bytes.esm.js",
  bundle: true,
  format: "esm",
});

console.log(result.outputFiles);

esbuild.stop();

Limitations

  • The "portable" loader does not use the Deno module cache, so all remote specifiers are downloaded on every run.
  • When using the "portable" loader, all npm: dependencies must be pre-downloaded into a local node_modules/ directory.
  • npm: specifiers are not supported on WASM esbuild builds due to FS access limitations (see evanw/esbuild#2968).

Documentation

The Deno integration for Deno consists of two separate plugins (that are however most commonly used together):

  1. The resolver, which resolves specifiers within a file relative to the file itself (absolutization), taking into account import maps.
  2. The loader, which takes a fully resolved specifier, and attempts to load it. If the loader encounters redirects, these are processed until a final module is found.

Most commonly these two plugins are used together, chained directly after each other using the denoPlugins() function. This function returns an array of esbuild.Plugin instances, which can be spread directly into the plugins array of the esbuild build options.

In depth documentation for each of the plugins, and the denoPlugins() function can be found in the generated docs.

Using with other plugins

For some use-cases these plugins should be manually instantiated. For example if you want to add your own loader plugins that handles specific file extensions or URL schemes, you should insert these plugins between the Deno resolver, and Deno loader.

In most cases, the denoResolverPlugin should be the first plugin in the plugin array.

The resolver performs initial resolution on the path. This includes making relative specifiers absolute and processing import maps. It will then send the fully resolved specifiers back into esbuild's resolver stack to be processed by other plugins. In the second path, the representation of the module is a fully qualified URL. The namespace of the second resolve pass is the scheme of the URL. The path is the remainder of the URL. The second resolve pass does not have a resolveDir property, as the URL is fully qualified already.

The denoLoaderPlugin registers resolvers that are hit in the secondary resolve pass for the schemes http, https, data, and file.

The output of the second resolve pass is then passed to the loader stack. The loader stack is responsible for loading the module. Just like in the resolver stack, the namespace of the loader stack is the scheme of the URL, and the path is the remainder of the URL.

The denoLoaderPlugin registers loaders that are hit in the secondary resolve pass for the schemes http, https, data, and file.

The examples directory contains an example for how to integrate with custom plugins. The examples/custom_scheme_plugin.ts example shows how to add a plugin that handles a custom scheme.

Permissions

This plugins requires the following permissions:

  • --allow-read if you need to resolve local files.
  • --allow-net if you need to resolve remote files.

If the program is run with --allow-run, the plugin will use the deno binary to resolve remote files. This allows the plugin to re-use the Deno module cache.

More Repositories

1

deno-puppeteer

A port of puppeteer running on Deno
TypeScript
445
star
2

now-deno

Deno builder for Vercel - run Deno on Vercel. 🦕 + λ = ❤️
TypeScript
264
star
3

dext.ts

The Preact Framework for Deno
TypeScript
241
star
4

armadajs

A custom JavaScript runtime for the ArmadaJS conference
Rust
87
star
5

fresh-with-signals

Using @preact/signals in Fresh
TypeScript
82
star
6

deno_s3

Amazon S3 for Deno
TypeScript
54
star
7

deploy_chat

A live chat app running on Deno Deploy
TypeScript
40
star
8

proposal-binary-encoding

A proposal to add modern, easy to use binary encoders to the web platform.
JavaScript
40
star
9

deno_httpcache

HTTP Caching for Deno - in memory and redis storage support. Inspired by the Service Worker Cache API.
TypeScript
25
star
10

freshworkshop

TypeScript
21
star
11

workerkit

A library to make writing Cloudflare Workers way nicer
TypeScript
21
star
12

ammonia-wasm

WASM bindings for the Ammonia HTML sanitizer
TypeScript
20
star
13

wrap

wrap is an abstraction layer on top of mongodb 🍃 to make it feel like sorta like firestore 🔥
Go
19
star
14

deno_googleapis

TypeScript
19
star
15

comrak-wasm

WASM bindings for the comrak markdown renderer
TypeScript
17
star
16

mqtt

A nice MQTT client library that wraps paho.mqtt.golang
Go
17
star
17

puppeteer_on_deploy

Running puppeteer on Deno Deploy!
TypeScript
16
star
18

deno_local_file_fetch

This polyfills file:// support for `fetch`
TypeScript
12
star
19

deno-fetchevent

FetchEvent based server compatible with browser.
TypeScript
11
star
20

deno_aws_sign_v4

Generate AWS Signature V4 for AWS low-level REST APIs.
TypeScript
10
star
21

messageformat.dev

TypeScript
10
star
22

denopaste

TypeScript
9
star
23

fetchevent_examples

Examples that make use of web standard FetchEvent
JavaScript
9
star
24

floatplaneapi

An unofficial API to interface with floatplane.com from own systems. This is not in any way affiliated with floatplane.com.
TypeScript
8
star
25

cases

TypeScript
7
star
26

rethinkdb-deno

A RethinkDB driver for deno.
TypeScript
6
star
27

deno_sqs

Amazon SQS for Deno
TypeScript
6
star
28

proposal-semaphore

6
star
29

deno_xhr

XMLHttpRequest polyfill for Deno
6
star
30

x.lcas.dev

A CDN that serves X-TypeScript-Types headers.
JavaScript
6
star
31

deno_ssm

Amazon SSM sdk from Deno
TypeScript
5
star
32

rethinkdb-kubernetes

RethinkDB on Kubernetes
Shell
4
star
33

flag

TypeScript
4
star
34

stream-utils

TypeScript
4
star
35

antictf

A CTF platform that uses Google Cloud for infinite scalability.
TypeScript
4
star
36

runtime-detector

TypeScript
4
star
37

greeter

TypeScript
3
star
38

branch-protection-test

3
star
39

lspower

Rust library for the Language Server Protocol (LSP)
Rust
3
star
40

luca

TypeScript
3
star
41

deno_doc_discord

A discord integration for deno doc
TypeScript
3
star
42

deno_metrics

Runtime metrics for Deno
TypeScript
3
star
43

wgpu_cts_runner

A minimal JS runtime built on Deno (deno_core / extensions) that can be used to test WebGPU CTS outside of full Deno.
Rust
3
star
44

reqwest_connection_pooling_bug

Reproduction for reqwest connection pooling bug
Rust
3
star
45

base64_streams

TypeScript
2
star
46

deno_webidl

A toolbox for WebIDL, written for Deno.
TypeScript
2
star
47

gojs

JS running in Go using v8worker2 🤯
Go
2
star
48

deno_aws

AWS SDK for Deno
2
star
49

deno_analyzer

The analyzer used to score deno.land/x modules
TypeScript
2
star
50

frontmatter

handle frontmatter in files
Go
1
star
51

module-harmony-usecases

JavaScript
1
star
52

Go_Websocket

This is a go websocket api!
Go
1
star
53

stream-utils-demo

TypeScript
1
star
54

demooidc

TypeScript
1
star
55

test

1
star
56

date_extensions

Extensions to the default dart DateTime class
Dart
1
star
57

deploy_examples

JavaScript
1
star
58

dash-todo

A server rendered TODO application
TypeScript
1
star
59

modernfrontends2022-bench

JavaScript
1
star
60

tcq2

TypeScript
1
star
61

PayEnabledOrderSystem

PEOS is the standard for insecure transactions using Google Sheets
HTML
1
star
62

mf2-tools

This repo contains a language server for the Message Format 2 message localization system from Unicode.
Rust
1
star