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

storyblok-generator

v1.0.5

Published

Generate Storyblok components out of your components.json file and get full type-safety and bundle splitting out of the box

Downloads

99

Readme

Storyblok Generator

GitHub Repo stars npm GitHub npm npm GitHub top language

Storyblok React component generator for Vite Storyblok apps (React/Remix.run).

  • Pulls in your components from Storyblok and generates the types for you.
  • Generates the components in either a file or folder structure.
  • Makes all components editable via the bridge by default.
  • Adds per component bundle splitting for better performance.
  • Adds full typesafety to your components.
  • Supports both kebab-case and camel-case file names.
  • Adds shortcuts to regenerate the components and types.

Setup

To get up and running quickly, you first install the vite plugin as a dev dependency in your project.

npm install -D storyblok-generator

Then, in your vite.config.ts file, add the following:

import { storyblokPlugin } from "storyblok-generator"

export default defineConfig({
	plugins: [
		storyblokPlugin({
			spaceId: "<your space id>",
			componentsDir: "./storyblok/components",
		}),
	],
})

Usage

Once the plugin is installed and configured, it will generate the components and types for you. You can then import the components in your code and use them as you normally would.

import { components } from "./storyblok/components";
import { storyblokInit, apiPlugin } from "@storyblok/react"

storyblokInit({
	accessToken: "<your access token>",
	use: [apiPlugin],
	// You pass in the components here, the components will be lazy loaded when actually used.
	components,
})

Storyblok CLI Caveats

The Plugin uses the Storyblok CLI to pull the components from your Storyblok space. This means that you need to have the CLI installed on your machine and available in your path.

You will also need to be logged in to the Storyblok CLI properly. You should login via SSO instead of using the username and password combo as that keeps you logged in but after some time the login expires and you need to login again by first logging out and logging in again.

Configuration

The plugin accepts the following configuration options:

| Option | Type | Description | Default | Required | | ----------------- | -------- | --------------- | ------- | -------- | | spaceId | string | Your Storyblok space ID. | - | Yes | | componentsDir | string | The directory where the components will be generated. | - | Yes | | typeFileLoc | string | The location of the type file. | ./storyblok/types.d.ts | No | | pullCommand | string | The command to use to pull the components from Storyblok via the CLI | storyblok pull-components --space <spaceId> --path <pathToComponentsDir> | No | | typesCommand | string | The command to use to generate the types for the components via the CLI | storyblok generate-typescript-typedefs --sourceFilePaths <pathToComponentsDir> --destinationFilePath <pathToTypeFileLoc> | No | | componentsJsonLoc | string | The location of the components JSON file. | ./storyblok/components.<spaceId>.json | No | | fileNameConvention | string | The file name convention for the components. Can be either kebab-case or camel-case. | kebab-case | No | | componentAs | string | The component structure. Can be either file or folder. | file | No | | debug | boolean | Whether to enable debug mode. If enabled, the plugin will print additional information to the console. | false | No |

Development

To develop this plugin, you can clone the repository and run the following commands:

npm install
npm run dev

This will build the plugin, install the dependencies, and start the development server.