0.0.15 • Published 8 months ago
@zipadee/javascript v0.0.15
@zipadee/javascript
Zipadee middleware for serving JavaScript modules
!CAUTION Zipadee is very early, under construction, will change a lot, and may never be sufficiently maintained for any level of use. If you want to try it, please consider contributing!
@zipadee/javascript
serves static JavaScript files from disk and transforms
them to resolve bare import specifiers to relative paths.
Usage
import {App} from 'zipadee';
import {serve as serveJS} from '@zipadee/javascript';
import {serve} from '@zipadee/static';
const app = new App();
// Serves all JS files in the directory {cwd}/files/
app.use(serveJS({root: 'files'}));
// Serves all other files in the directory {cwd}/files/
app.use(serve({root: 'files'}));
app.listen();
Options
base
: The directory that paths are resolved against to find on disk. This directory is typically where first-party JavaScript files are located. Must be a subpath ofroot
. Defaults to the value ofroot
.root
: The root directory that files are restricted to. Import specifiers can resolve to a path outside ofbase
(this is common with npm dependencies, and monorepos), but they are disallowed to be served from outside ofroot
. Defaults to the current working directory.rootPathPrefix
: Imports that resolve to outside of the base directory are prefixed with therootPathPrefix
in order to resolve them against theroot
directory instead of thebase
directory. Defaults to'/__root__'
.extensions
: Array of file extensions to serve. Defaults to['.js', '.mjs']
. Files not matching these extensions will not be handled by this middleware. They can be served by other downstream middleware.