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

cadells-vanilla-components

v1.5.3

Published

A basic component library built with [vanilla-extract](https://vanilla-extract.style/) for use in my NextJS sites, namely [prawn.cadell.dev](https://prawn.cadell.dev/) and [emojis.cadell.dev](https://emojis.cadell.dev/).

Downloads

40

Readme

Cadell's Vanilla Components

A basic component library built with vanilla-extract for use in my NextJS sites, namely prawn.cadell.dev and emojis.cadell.dev.

It uses tsup and np for building and publishing to NPM.

Commands

  • npm run build - Build the package.
  • npm run release - Publish a new version to NPM.
  • npm run build-release - Build and Publish to NPM.

Use with NextJS

Cadell's NextJS Template uses this package.

  1. Add cadells-vanilla-components.
    npm install cadells-vanilla-components @fontsource/source-sans-pro
  2. Add MDX dependencies.
    npm install --save-dev @next/mdx
  3. Add vanilla-extract dependencies.
    npm install --save-dev @vanilla-extract/css @vanilla-extract/next-plugin
  4. Setup next.config.js.
    const withMDX = require("@next/mdx")({
        extension: /\.mdx$/,
    });
    
    const { createVanillaExtractPlugin } = require("@vanilla-extract/next-plugin");
    const withVanillaExtract = createVanillaExtractPlugin();
    
    const nextConfig = {
        pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
    };
    
    module.exports = withVanillaExtract(withMDX(nextConfig));
  5. Configure _document.tsx inside /pages.
    import { InitialiseTheme } from "cadells-vanilla-components";
    import Document, { Html, Head, Main, NextScript } from "next/document";
    
    export default class MyDocument extends Document {
        static async getInitialProps(ctx: any) {
            const initialProps = await Document.getInitialProps(ctx);
            return { ...initialProps };
        }
    
        render() {
            return (
                <Html lang="en">
                    <Head>
                        <link
                            rel="icon"
                            href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>😏</text></svg>"
                        />
                    </Head>
                    <body>
                        <InitialiseTheme />
                        <Main />
                        <NextScript />
                    </body>
                </Html>
            );
        }
    }
  6. Configure _app.tsx inside /pages.
    import { Container, ThemeToggle } from "cadells-vanilla-components";
    import "cadells-vanilla-components/dist/index.css";
    import "@fontsource/source-sans-pro/400.css";
    import "@fontsource/source-sans-pro/600.css";
    
    const App = ({ Component, pageProps }) => (
        <Container>
            <ThemeToggle />
            <Component {...pageProps} />
        </Container>
    );
    
    export default App;
  7. Create mdx-components.tsx.
    import { mdComponents } from "cadells-vanilla-components";
    
    export function useMDXComponents() {
        return mdComponents;
    }

References:

  • https://nextjs.org/docs/advanced-features/using-mdx#setup-nextmdx-in-nextjs
  • https://vanilla-extract.style/documentation/integrations/next/

Implementation

I've built NextJS apps with MDX and custom components for projects like prawn.cadell.dev before but I wanted to split this out into a separate package for emojis.cadell.dev. This is the result! I also created template.cadell.dev as a template for showing how to use it.

Creating this package was a bit harder than first thought but I'm happy with the result and I think emojis.cadell.dev looks great. I originally tried using tsdx but the typescript types weren't correct and I couldn't work out why. I decided to change direction and started looking for a tool based on esbuild instead of Rollup and found tsup which pretty much worked out of the box. Happy days! Tsdx did introduce me to np for publishing to NPM so I kept that and it works really well. Everything happened for a reason.

Todo

  1. Storybook.
  2. Tests.

References

  • https://github.com/seek-oss/vanilla-extract/discussions/281
  • https://github.com/egoist/tsup
  • https://github.com/sindresorhus/np
  • Couldn't get this method working: https://souporserious.com/bundling-typescript-with-esbuild-for-npm/