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

neutrino-middleware-styleguidist

v2.0.0

Published

Neutrino middleware for previewing sets of React components

Downloads

38

Readme

Neutrino Styleguidist Middleware

neutrino-middleware-styleguidist is a Neutrino middleware that supports previewing components using React Styleguidist. Plays mostly nicely with other Neutrino middleware, so you can preview and build styleguides from components in an app or standalone component repo.

NPM version NPM downloads Join the Neutrino community on Spectrum

Features

  • Zero upfront configuration necessary to start a styleguidist app.
  • Integrates with existing Neutrino middleware and presets.

Requirements

  • Node.js v6 LTS, v8, v9
  • Yarn v1.2.1+, or npm v5.4+
  • Neutrino v8

Installation

neutrino-middleware-styleguidist can be installed via the Yarn or npm clients. Inside your project, make sure neutrino and neutrino-middleware-styleguidist are development dependencies. You will also need middleware or a preset for building your components separately from this middleware. For example, if you are building a React app, you may be using @neutrinojs/react, or you may be using @neutrinojs/react-components to build standalone React components. You can use neutrino-middleware-styleguidist to build a styleguide for either.

In the example below, we are using the @neutrinojs/react-components preset along with this. Follow the instructions for your particular middleware or preset prior for installation details.

Yarn

❯ yarn add --dev neutrino-middleware-styleguidist

npm

❯ npm install --save-dev neutrino-middleware-styleguidist

It is recommended to add some scripts to your package.json to make starting and building the styleguide easier:

{
  "scripts": {
    "styleguide:start": "neutrino styleguide:start",
    "styleguide:build": "neutrino styleguide:build"
  }
}

Project Layout

neutrino-middleware-styleguidist follows the standard project layout specified by Neutrino. This means that by default all project source code should live in a directory named src in the root of the project. This includes JavaScript files that would be available to your compiled project.

All components should be their own module within a directory named components inside the source directory.

In your .neutrinorc.js file, add this preset to your use array, but put it before your other building presets:

module.exports = {
  use: [
    // PUT THE STYLEGUIDIST MIDDLEWARE BEFORE
    // YOUR OTHER BUILD PRESETS!
    'neutrino-middleware-styleguidist',
    '@neutrinojs/react-components'
  ]
};

Commands

neutrino-middleware-styleguidist exposes two Neutrino commands for starting and building a styleguide.

Starting the local styleguide server

Yarn

❯ yarn styleguide:start

✔ Styleguidist server running at 0.0.0.0:6060

npm

❯ npm run styleguide:start

✔ Styleguidist server running at 0.0.0.0:6060

Building

neutrino-middleware-styleguidist builds components to the styleguide directory by default when running neutrino styleguide:build. Using the example above as a reference:

❯ yarn styleguide:build

✔ Style guide published to /project/styleguide
✔ Running styleguide:build completed

You can then host this styleguide on GitHub pages or other static site hosting platform.

Customizing

To override the build configuration, start with the documentation on customization. neutrino-middleware-styleguidist allows you to pass options for customizing the operation of react-styleguidist. Pass an array-pair instead of a string to customize the options for this middleware.

Example: Show props usage in the guide, and skip displaying components with no docs:

module.exports = {
  use: [
    ['neutrino-middleware-styleguidist', {
      showUsage: true,
      skipComponentsWithoutExample: true,
    }]
  ]
}

Any options that are acceptable by React Styleguidist can be passed to this middleware, except webpackConfig.

Important Note!

This middleware works mostly well, except React Styleguidist has trouble when the ExtractTextWebpackPlugin is being used. If you have this plugin, for example with Neutrino's Web-based plugins, you'll want to disable extraction when running the styleguide commands in your .neutrinorc.js:

const buildingStyleguide = process.argv[2].includes('styleguide');

module.exports = {
  use: [
    'neutrino-middleware-styleguidist',
    ['@neutrinojs/react', {
      style: {
        extract: buildingStyleguide ? false : {}
      }
    }]
  ]
};