1.0.0 • Published 7 months ago

@tobedated/t-server v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

A simple static web server. Supports HMR, Made to be used mostly locally

This server is meant to serve static files only

HTML, CSS, JS (No framework support for now)

Getting Started

First, install globally:

npm i -g tserver

Go to your project root directory and start the server there

tserver

Example image

Options

OptionArgumentDefault
-p, --portSpecify which port tserver should run on e.g 40016001
-m, --modeSpecify server reload mode hmr or no-hmrhmr
-g, --globalSave other passed options as default

Open http://localhost:6001 with your browser to see the result.

You can start editing the page by modifying any file in your app directory. The page auto-updates as you edit the file.

Cleanup side effects during invalidation

To cleanup side effects that might keep running after invalidation e.g setTimeout

create a function named _tserver_cleanup${module} containing how to cleanup side effect and tserver will call it automatically

How it works

const module = change.replace("/", "").replace(".js", "");
const cleanup = `__tserver_cleanup_${module}`;
typeof (window as any)[cleanup] !== "undefined" &&
  await(window as any)[cleanup]();

TODO

Add a way to persist state between replacements