boneyard-js

repository·main·Indexed 24 days ago

https://github.com/0xgf/boneyard

A tool for generating pixel-perfect skeleton loading screens by capturing actual component layouts at build time. It provides a CLI to extract UI bones using Playwright and framework-specific <Skeleton> components for React, Vue, Svelte 5, Preact, Angular, and React Native. Features include a Vite plugin for automated capture, support for CDP to reuse browser sessions, and a configurable boneyard.config.json for managing breakpoints, output directories, and authentication.

Tokens
9.3K
Snippets
30
Records
56
Agent score
87%

What's inside boneyard-js

  1. Use the Skeleton component in various frameworks

    main

    Boneyard provides framework-specific imports for the <Skeleton> component. Wrap your component in <Skeleton> and provide a name and loading state. The CLI will then extract the layout based on that name.

    // React
    import { Skeleton } from 'boneyard-js/react'
    
    function BlogPage() {
      const { data, isLoading } = useFetch('/api/post')
    
      return (
        <Skeleton name="blog-card" loading={isLoading}>
          <BlogCard data={data} />
        </Skeleton>
      )
    }
  2. Use the boneyard Vite plugin

    main

    For Vite-based projects (React, Preact, Vue, Svelte), use the boneyardPlugin to automate bone capture during development without a separate terminal.

    // vite.config.ts
    import { boneyardPlugin } from 'boneyard-js/vite'
    
    export default defineConfig({
      plugins: [boneyardPlugin()]
    })
  3. Reuse an existing browser via CDP

    main

    To reuse an existing browser session (to avoid downloading Chromium or to use existing auth/cookies), launch Chrome with a remote debugging port and point the CLI to it using the --cdp flag.

    # 1. Start Chrome with remote debugging
    # macOS:
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
    
    # 2. CLI
    npx boneyard-js build --cdp 9222
  4. Configure boneyard via boneyard.config.json

    main

    Create a boneyard.config.json file in your project root to control CLI and runtime defaults. This includes breakpoints, output directories, colors, and animation settings.

    {
      "breakpoints": [375, 768, 1280],
      "out": "./src/bones",
    
      "color": "#e5e5e5",
      "darkColor": "#2a2a2a",
      "animate": "shimmer",
      "shimmerColor": "#ebebeb",
      "darkShimmerColor": "#333333",
      "speed": "2s",
      "shimmerAngle": 110
    }
  5. Use the boneyard-js CLI to capture bones

    main

    The boneyard-js build command visits your application in a headless browser, captures all named <Skeleton> components, and writes .bones.json files and a registry file to your specified output directory. It can automatically detect your dev server if no URL is provided.

    Web Setup

    1. Wrap your components with <Skeleton name="..." loading={...}>.
    2. Run the build command:
      npx boneyard-js build
    3. Import the generated registry in your app entry point:
      import './src/bones/registry'

    React Native Setup

    1. Wrap your components using the native adapter:
      import { Skeleton } from 'boneyard-js/native'
      <Skeleton name="blog-card" loading={isLoading}>
        <BlogCard />
      </Skeleton>
    2. Run the build command in native mode:
      npx boneyard-js build --native --out ./bones
    3. Open your app on a device or simulator; bones are captured automatically.
    4. Import the generated registry in your app entry point:
      import './bones/registry'
    npx boneyard-js build
  6. Use the boneyard-js CLI to build bones

    main

    The build command visits your running application at various breakpoints, captures named <Skeleton> components, and writes .bones.json files to disk. It can auto-detect your dev server or take an explicit URL.

    Basic Usage:

    • Auto-detect dev server: npx boneyard-js build
    • Explicit URL: npx boneyard-js build http://localhost:3000
    • Multiple URLs: npx boneyard-js build http://localhost:3000/blog http://localhost:3000/shop
    npx boneyard-js build [url] [options]
  7. Connect to an existing Chrome session via CDP

    main

    To reuse your existing Chrome cookies, authentication state, and manual certificate handling, run Chrome with remote debugging enabled and use the --cdp flag.

    1. Start Chrome:

      • macOS: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
      • Linux/Windows: google-chrome --remote-debugging-port=9222
    2. Run boneyard: npx boneyard-js build --cdp 9222

  8. Use Layout APIs for manual computation

    main

    For SSR or advanced responsive tooling, use the layout APIs to compute bone layouts without rendering the full component.

    import { computeLayout, compileDescriptor, invalidateDescriptor } from 'boneyard-js'
    
    // Simple usage
    const result = computeLayout(descriptor, 375)
    
    // Optimized usage for multiple breakpoints
    const compiled = compileDescriptor(descriptor)
    const mobile  = computeLayout(compiled, 375)
    const tablet  = computeLayout(compiled, 768)
    const desktop = computeLayout(compiled, 1280)
    
    // To force a rebuild if the descriptor is mutated
    invalidateDescriptor(descriptor)
  9. Use the Skeleton component in React

    main

    Import Skeleton from boneyard-js/react. Wrap your content with the component and provide a name and a loading boolean prop. The name determines the generated .bones.json file.

    import { Skeleton } from 'boneyard-js/react'
    
    function BlogPage() {
      const { data, isLoading } = useFetch('/api/post')
      return (
        <Skeleton name="blog-card" loading={isLoading}>
          {data && <BlogCard data={data} />}
        </Skeleton>
      )
    }