npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esbuild-server

v0.3.0

Published

**⚡️ Fast, lightweight and powerful development server for esbuild ⚡️**

Downloads

7,363

Readme

esbuild-server

⚡️ Fast, lightweight and powerful development server for esbuild ⚡️

  • Zero dependencies besides esbuild
  • API proxy support
  • Live reload
  • SPA support through History API fallback
  • Fully typed with TypeScript

Installation

npm install --save-dev esbuild esbuild-server

Usage

Create a new file for your dev server:

// dev-server.js
require('esbuild-server')
  .createServer(
    {
      bundle: true,
      entryPoints: ['src/app.js'],
    },
    {
      static: 'public',
    }
  )
  .start();

Assuming you have an index.html file in the public folder you can now run the server with node dev-server.js.

See example folder for examples.

API

createServer(esbuildOptions, serverOptions)

esbuildOptions

Options passed to esbuild Build API. If not specified watch defaults to true to enable continous build and live reload, and similarly if no type of output option is specified outdir is set to a temporary directory.

serverOptions

| Option | Description | Default | |--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------| ------- | | static | Path to your static assets folder, should contain an index.html file. | None | | port | Port number to listen for requests on. | 8080 | | historyApiFallback | For Single Page Apps using the HTML5 History API, the index.html page is served instead of 404 responses. | false | | injectLiveReload | Inject snippet to automatically reload the page when file changes are detected. | true | | open | Open the browser after server had been started. Set to a string to open a particular path. | false | | proxy | Proxy certain paths to a separate API backend when you want to serve API requests on the same domain. Pass a function for dynamic rewrites. | {} | | onProxyRewrite | Callback function when a proxy rewrite happens, useful for logging or altering the response. | None | | http | http options. | None | | https | https options. | None |

Proxying

Static

{
  proxy: {
    '/api': 'http://localhost:3000'
  }
}

A request to /api/users will now proxy the request to http://localhost:3000/api/users. If you want to rewrite the base use dynamic approach instead:

Dynamic

{
  proxy: (path) => {
    if (path.startsWith('/api')) {
      return path.replace(/^\/api/, 'http://localhost:3000');
    }
  };
}

A request to /api/users will now proxy the request to http://localhost:3000/users.

Modifying the response

{
  onProxyRewrite: (proxyRes, localUrl, proxyUrl) => {
    console.log(`Proxying ${localUrl} to ${proxyUrl}`);
    proxyRes.headers['x-my-custom-header'] = 'yep';
    return proxyRes;
  };
}

Https

{
    https: {
        key: fs.readFileSync('server.key'),
        cert: fs.readFileSync('server.crt'),
    }
}

Live reload

If you want more control over where the live reload script is injected you can place it manually with:

<script src="/esbuild-livereload.js" async></script>

License

MIT © Joel Arvidsson 2022 – present