https://github.com/mobily-enterprises/es6-dev-server
Serve ES6 modules ensuring node resolution via the node algorithm. Express middleware included.
https://github.com/mobily-enterprises/es6-dev-server
Last synced: 3 months ago
JSON representation
Serve ES6 modules ensuring node resolution via the node algorithm. Express middleware included.
- Host: GitHub
- URL: https://github.com/mobily-enterprises/es6-dev-server
- Owner: mobily-enterprises
- License: gpl-3.0
- Created: 2021-02-09T02:22:49.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-01T09:01:02.000Z (over 3 years ago)
- Last Synced: 2025-03-22T20:05:22.853Z (3 months ago)
- Language: JavaScript
- Size: 80.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serve ES6 modules
This module serves ES6 modules ensuring node resolution via the node algorithm. Express middleware included.
Resolution is done via the node algorithm, but letting "module" or "jsnext" fields in package.json take precedence over "main".
_NOTE: this module draws strong inspiration (and large chunks of repurposed code) from
Marijn Haverbeke's awesome [esmoduleserve](https://github.com/marijnh/esmoduleserve)._## Usage as a stand alone server
You can use es6-dev-server as a server:
````
$ ../es6-dev-server/server --help
Usage: server [options]Options:
-V, --version output the version number
-p, --port Set the port (default: 3000)
-e, --entry Default file for SPAs (never returning "not found"). (default: "")
-h, --help display help for command
````It will run the server in the current directory; javascript modules will be translate so that `import 'lit-element'` will be translated into `import '../../node_modules/lit-element.js'
## Usage as middleware
You can use it as middleware in your programs:
````
const moduleMiddleware = require('es6-dev-server').moduleMiddleware(...)
app.use(moduleMiddleware({ root: '.') })
````The parameter is the directory that will be served.
## Usage as middleware (advanced)
You can call the internal middleware function of es6-dev-server, and have full control over
the way the middleware is called:````
const ModuleMiddleware = require('es6-dev-server').ModuleMiddlewareconst mm = new ModuleMiddleware({ root: '.' })
app.use((req, res, next) => {
if (mm.handleRequest(req, res)) {
// The request WAS handled by the middleware's handleRequest() function
} else {
// The request was NOT handled by the middleware's handleRequest() function
next()
}
})
````