GithubHelp home page GithubHelp logo

hhy5277 / esm.sh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esm-dev/esm.sh

0.0 1.0 0.0 9.34 MB

A fast, global content delivery network for ES Modules.

Home Page: https://esm.sh

License: MIT License

Shell 1.07% JavaScript 13.37% Go 54.44% Rust 24.00% TypeScript 4.16% CSS 1.79% HTML 1.08% Dockerfile 0.10%

esm.sh's Introduction

ESM

A fast, global content delivery network for NPM packages with ES Module format.

Import from URL

import React from "https://esm.sh/react"

Specify version

import React from "https://esm.sh/[email protected]"

You may also use a semver or a dist-tag instead of a fixed version number, or omit the version/tag entirely to use the latest tag:

import React from "https://esm.sh/react@17"   // 17.0.2
import React from "https://esm.sh/react@next" // 18.0.0-rc.0-next-13036bfbc-20220121

Submodule

import { renderToString } from "https://esm.sh/react-dom/server"

or import non-module(js) files:

import "https://esm.sh/react/package.json" assert { type: "json" }

You can also use the ?path to specify the submodule, this is friendly for import maps:

{
  "imports": {
    "react-dom/": "https://esm.sh/react-dom?target=es2015&path=/"
  }
}
// equals to https://esm.sh/react-dom/server?target=es2015
import { renderToString } from "react-dom/server" 

Bundle mode

import { Button } from "https://esm.sh/antd?bundle"

In bundle mode, all dependencies will be bundled into a single JS file.

Development mode

import React from "https://esm.sh/react?dev"

The ?dev mode builds modules with process.env.NODE_ENV equals to development, that is useful to build modules like React to allow you to get more development warn/error details.

Specify external dependencies

import React from "https://esm.sh/[email protected]"
import useSWR from "https://esm.sh/[email protected]"

By default, esm.sh rewrites import specifier based on the package's dependency statement. To specify version of dependencies, you can use the ?deps=PACKAGE@VERSION query. You can separate multiple dependencies with commas: [email protected],[email protected].

Aliasing dependencies

import useSWR from "https://esm.sh/swr?alias=react:preact/compat"

in combination with ?deps:

import useSWR from "https://esm.sh/swr?alias=react:preact/compat&[email protected]"

The origin idea was coming from @lucacasonato.

ESBuild options

By default, esm.sh will check the User-Agent header to get the build target automatically. You can specify it with the ?target query. Available targets: es2015 - es2022, esnext, node, and deno.

import React from "https://esm.sh/react?target=es2020"

Other supported options of esbuild:

  • Keep names
    import React from "https://esm.sh/react?keep-names"
  • Ignore annotations
    import React from "https://esm.sh/react?ignore-annotations"

Package CSS

import Daygrid from "https://esm.sh/@fullcalendar/daygrid"
<link rel="stylesheet" href="https://esm.sh/@fullcalendar/daygrid?css">

This only works when the NPM module imports CSS files in JS directly.

Web Worker

esm.sh supports ?worker mode to load modules as web worker:

import editorWorker from "https://esm.sh/monaco-editor/esm/vs/editor/editor.worker?worker"
  
const worker = editorWorker()

Deno compatibility

esm.sh will resolve the node internal modules (fs, child_process, etc.) with deno.land/std/node to support some packages working in Deno, like postcss:

import postcss from "https://esm.sh/postcss"
import autoprefixer from "https://esm.sh/autoprefixer"

const { css } = await postcss([ autoprefixer ]).process(`
  backdrop-filter: blur(5px);
  user-select: none;
`).async()

X-Typescript-Types

By default, esm.sh will respond with a custom X-TypeScript-Types HTTP header when the types (.d.ts) is defined. This is useful for deno type checks (link).

Figure #1

You can pass the ?no-check query to disable the X-TypeScript-Types header if some types are incorrect:

import unescape from "https://esm.sh/lodash/unescape?no-check"

Pin the build version

Since we update esm.sh server frequently, sometime we may break packages that work fine previously by mistake, the server will rebuild all modules when the patch pushed. To avoid this, you can pin the build version by the ?pin=BUILD_VERSON query. This will give you an immutable cached module.

import React from "https://esm.sh/[email protected]?pin=v86"

Global CDN

The Global CDN of esm.sh is provided by Cloudflare, one of the world's largest and fastest cloud network platforms.

Self-Hosting

To host esm.sh by yourself, check the hosting documentation.

esm.sh's People

Contributors

abetaev avatar akimon658 avatar alienzhou avatar asafamr avatar canrau avatar cristiano-belloni avatar detachhead avatar douglasduteil avatar ije avatar jimisaacs avatar loynoir avatar marcushultman avatar marktiedemann avatar mashaal avatar motss avatar rivy avatar voces avatar wleonardo avatar zhoukekestar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.