devito
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

devito

Fast web dev server

npm i devito -g pnpm add devito -g yarn global add devito

CLI

devito is a fast web dev server, inspired by vite.

It also uses esbuild.

devito my-file.tsx

The above will serve my-file.tsx and will refresh on every change.

Open in editor

Allows opening file[:line[:col]] links from the DevTools console output, right into your editor. Use --editor=<editor> to set your own (defaults to code).

Get the Chrome DevTools extension.

See the supported editors.

import.meta.url

import.meta.url is transformed to <location.origin>/@fs/<path>.

The relative base path /@fs/ is computed with --homedir=<path>. It defaults to os.homedir().

Workers/Worklets/iframe

// Worker
new Worker(new URL('./my-worker.js', import.meta.url).href, { type: 'module' })

// AudioWorklet
audioContext.audioWorklet.addModule(
  new URL('./my-audio-worklet.js', import.meta.url).href
)

// iframe
const src = new URL('sandbox-iframe.js', import.meta.url).href
iframe.srcdoc = `<script src="${src}" type="module"></script>`

CSS

import 'some.css'

Statically bundled modules will bundle all css to bundle.css.

Dynamically discovered modules (such when using import()) will create a <style> element and it'll be appended in <head>.

JSON

import json from 'some.json'

JSX

// @jsxImportSource jsx-lib

tsconfig.json:

"compilerOptions": {
  ...
  "jsx": "react-jsx",
  ...
}

Markdown

devito README.md

Caching ~ Certificate

To enable browser caching in order to get all the speed benefits, you'll need to create a certificate.

devito will try to find a cert+key for devito.test under process.env.SSL_CERTS_DEVITO, ~/.ssl-certs/ or using --cert=xxx (minus the -key.pem and .pem suffixes).

Make certificate:

mkcert -install
mkcert devito.test
cp devito.test* ~/.ssl-certs/

Then add an entry 127.0.0.1 devito.test in /etc/hosts.

Chrome/Firefox should now cache assets properly for that location.

More info here: https://jonathanbossenger.com/2019/02/08/setting-up-trusted-ssl-certificates-for-local-development-using-mkcert-on-ubuntu-18-04-with-apache/

API

# DevitoOptions

    # constructor(options)
    # alias

      Record<string, string>

    # bundle  =  true

      boolean

    # cache  =  true

      boolean

    # cert  =  ...

      string | ServerOptions

    # editor  =  'code'

      string

    # entryResolveDir

      string

    # entrySource

      string

    # extraAnalyzePaths  =  []

      string []

    # file

      string

    # hmr  =  false

      boolean

    # homedir  =  '~'

      string

    # hostname  =  'devito.test'

      string

    # inlineSourceMaps  =  false

      boolean

    # ipAddress  =  '0.0.0.0'

      string

    # port  =  ...

      number

    # quiet  =  false

      boolean

    # root  =  '.'

      string

    # startPort  =  3000

      number

    # watch  =  true

      boolean

    # entryFile
    # rootPath

# ResourceCache

# ResourceCacheItem

    # payload
    # stats

      Stats

# FS_PREFIX  =  '@fs'

    "@fs"

# caches  =  ...

    Set<Map<any, any>>

# esbuildCommonOptions  =  ...

    BuildOptions

# clearDevitoCaches()

    clearDevitoCaches()  =>

      void
# createResourceCache(getStats, getPayload)

    # getStats(pathname)

      # pathname

        string

      getStats(pathname)  =>

        Promise<Stats>

# getPayload(pathname, args)

    # pathname

      string

    # args

      any []

    getPayload(pathname, args)  =>

      Promise<T>

createResourceCache<T>(getStats, getPayload)  =>

# devito(partialOptions)

    # partialOptions

    devito(partialOptions)  =>

      Promise<{

      # esbuild

        undefined | Esbuild

      # options
      # url  =  localAddress

        string

      # close()

        close()  =>

          Promise<void>

}>
# forgetFile(pathname)

    # pathname

      string

    forgetFile(pathname)  =>

      void
# readFile(key, args)

    # key

      string

    # args

      [ ]

    readFile(key, args)  =>

      Promise<string>
# roundSeconds(x)

    # x

      number | Date

    roundSeconds(x)  =>

      number

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2022 stagas

Readme

Keywords

none

Package Sidebar

Install

npm i devito

Weekly Downloads

68

Version

2.1.0

License

MIT

Unpacked Size

305 kB

Total Files

49

Last publish

Collaborators

  • stagas