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

webpack-udev-server

v1.0.0

Published

A better [dev-server] for [webpack].

Downloads

47

Readme

webpack-udev-server

A better dev-server for webpack.

build status coverage license version downloads

Features:

  • Run server-side node applications in development mode.
  • Supports react-native.
  • Supports webpack@1, webpack@2, webpack@3, webpack@4.
  • Parallelized builds for multi-webpack configurations.
  • Sick emoji logging.
  • Custom HMR runtime.
  • Hot-reloading of webpack configuration files.
  • Universal, detachable IPC.
  • Simple, dynamic proxying.
  • Host multiple applications at once.

IMPORTANT: We're not super battle-tested. Use at your own risk. The current version is a fairly major rewrite and while the external API you use for spawning the server hasn't changed much for the typical use case, a lot of stuff has changed.

Usage

No changes to your webpack configuration are required for using the universal dev server. All you need to do is to run the dev server using whatever configuration files you want it to run:

#!/bin/sh
webpack-udev-server --config client.webpack.config.js --config server.webpack.config.js

Globs are totally supported too:

#!/bin/sh
webpack-udev-server --config config/*.webpack*.js

API

createClient()

If your server requires access to some data that's not available on the local file system you'll need to use createClient to connect to your webpack-udev-server instance – since web assets are generated in memory, (in development mode), you won't be able to read them with traditional fs calls. A simple example of this scenario using express:

import {createClient} from 'webpack-udev-server';
import express from 'express';
import fs from 'fs';

const app = express();

if (process.env.NODE_ENV === 'development' || !process.env.NODE_ENV) {
  const devServer = createClient();
  app.use((req, res, next) => {
    devServer.getStats('client').then(
      (stats) => {
        req.stats = stats;
        next();
      },
      (err) => next(err)
    );
  });
} else {
  // In production mode we can just read the data from disk instead.
  const stats = JSON.parse(fs.readFileSync('stats.json', 'utf8'));
  app.use((req, res, next) => {
    req.stats = stats;
    next();
  });
}

Architecture

There is a central IPC hub from which all other services connect:

==================== hub ====================
^         ^        ^      ^       ^        ^
compiler  watcher  proxy  logger  runtime  ..

When you start webpack-udev-server is generally automatically starts this hub for you and then any child processes that are spawned or any web pages that need access to the information then connect to the hub.

proxy

The proxy is what handles routing requests to the children. It watches PROXY_SET events to know which paths to proxy to what URLs.

watcher

The watcher handles generating and removing webpack config files to be compiled. It received PATH_WATCHED and PATH_UNWATCHED events to know what paths to monitor. In turn it generates CONFIG_LOADED and CONFIG_UNLOADED events to indicate which files should be compiled.

supervisor

The supervisor handles spawning child processes to compile the webpack config files. It monitors CONFIG_LOADED and CONFIG_UNLOADED to determine which compilation processes to start and end.

compiler

The compiler actually compiles the webpack config files and does any associated output management. For web this means providing a URL to access the generated assets at and informing the proxy, for node this means spawning the node child process and keeping it alive. Generally this means there will be a PROXY_SET event at some point so that you can access the results of your compilation through the main server.

The compiler additionally handles demand for files. So if someone needs to read the contents of a stats.json file then the compiler will handle this. This is done using FILE_CONTENTS demands.

runtime

The dev runtime (the JS bundle that gets embedded into your application) watches for WEBPACK_STATS events to see if the stats file that corresponds to the JS bundle has changed. When this happens either HMR is triggered or you need to restart/reload your application. The node runtime additionally hijacks http.createServer to automatically send a PROXY_SET event when you create a server that starts listening.

logger

The logger is just a dummy service that watches a variety of events and outputs them to the console. Most of the time people want to see what's going on in their app so this lets them do that. However sometimes you would prefer to have a different UI (e.g. something using react-blessed) and so you can turn off the console entirely if you need to.