# serve-esm

> Static file serving and directory listing

Latest version **1.0.1** (published 2017-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install serve-esm
pnpm add serve-esm
yarn add serve-esm
bun add serve-esm
```

Provides the command `serve-esm`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-12-03 |
| First published | 2017-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.9.0 |
| Dependencies | 24 |
| Known vulnerabilities | 0 (+23 in 3 direct dependencies) |
| Install scripts | no |
| Author | leo |
| Maintainers | adrianhelvik |
| Keywords | now, serve, micro, http-server |

## Links

- npm: https://www.npmjs.com/package/serve-esm
- Repository: https://github.com/zeit/serve
- npm.io page: https://npm.io/package/serve-esm

## Dependencies (24)

- [ip](https://npm.io/package/ip.md) 1.1.5
- [opn](https://npm.io/package/opn.md) 5.1.0
- [args](https://npm.io/package/args.md) 3.0.7
- [send](https://npm.io/package/send.md) 0.16.1
- [boxen](https://npm.io/package/boxen.md) 1.2.2
- [chalk](https://npm.io/package/chalk.md) 2.3.0
- [dargs](https://npm.io/package/dargs.md) 5.1.0
- [micro](https://npm.io/package/micro.md) 9.0.0
- [bluebird](https://npm.io/package/bluebird.md) 3.5.1
- [filesize](https://npm.io/package/filesize.md) 3.5.11
- [fs-extra](https://npm.io/package/fs-extra.md) 4.0.2
- [path-type](https://npm.io/package/path-type.md) 3.0.0
- [basic-auth](https://npm.io/package/basic-auth.md) 2.0.0
- [clipboardy](https://npm.io/package/clipboardy.md) 1.1.4
- [handlebars](https://npm.io/package/handlebars.md) 4.0.11
- [mime-types](https://npm.io/package/mime-types.md) 2.1.17
- [detect-port](https://npm.io/package/detect-port.md) 1.2.1
- [resolve-cwd](https://npm.io/package/resolve-cwd.md) 2.0.0
- [resolve-pkg](https://npm.io/package/resolve-pkg.md) 1.0.0
- [node-version](https://npm.io/package/node-version.md) 1.1.0
- [package-json](https://npm.io/package/package-json.md) 4.0.1
- [micro-compress](https://npm.io/package/micro-compress.md) 1.0.0
- [update-notifier](https://npm.io/package/update-notifier.md) 2.3.0
- [openssl-self-signed-certificate](https://npm.io/package/openssl-self-signed-certificate.md) 1.1.6

## Recent versions

- 1.0.1 (latest) — 2017-12-03
- 1.0.0 — 2017-12-03

## README

# Proposal

Non-url imports could be prefixed with e.g. `/ESM/` to create a url.
This would allow module resolution to be performed server side. For
imports from an ESM module this would have to be 

## Proposed usage

```javascript
import React from 'react' // Resolves to the url "/ESM/react"
```

## (An incomplete list of) working modules

For now, React does not work with this module, there are however
several modules that I've found work fine.

- preact (through the module-field)
- left-pad (through module.exports compat mode)
- mobx (through the module-field)

## Non-working modules
- React (uses require within the main file)
- mobx-react (imports other modules. Would work with this proposal)

# serve-esm

This is an experimental module for integrating the ESM modules with node_modules. It is not complete,
as that would require transpilation. It is intended as a proposal for how module loading without
a prefix could be resolved server-side instead of increasing complexity on the frontend.
A simple prefix `/ESM/` is added before modules that you wish to import

## A note on this fork

This is a fork of the `serve` project. It adds support for node_modules, with some important caveats.
A module must be imported like this:

```javascript
// Import preact by using the module field in package.json
import { h, Component } from '/ESM/preact'
```

There is also support for module.exports.

```javascript
// Import left-pad by using the main field in package.json
// and exporting module.exports
import leftPad from '/ESM/left-pad'
```
There is however no support for transitive imports or requires.

```javascript
// This will fail because of transitive imports
import mobxReact from '/ESM/mobx-react'
```

## Usage

Install it:

```bash
npm install -g serve-esm
```

And run this command in your terminal:

```bash
serve-esm [options] <path>
```

### More info

See [The original repo](https://github.com/zeit/serve) for more usage information.

---
_Source: https://npm.io/package/serve-esm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
