Remix CLI

0.4.16 · active · verified Wed Apr 22

rmx-cli is a command-line interface tool designed specifically for Remix applications, providing utility functions to enhance development workflows. The current stable version, as of the provided information, is 0.4.16. Its primary feature highlighted is the `svg-sprite` command, which automates the generation of SVG sprite files along with corresponding, fully-typed React components. This command can create either a single default `Icon` component that accepts an `icon` prop, or individual named components for each SVG, based on command-line flags. It also exports the `href` to the sprite file, facilitating its use in Remix's `links` export for preloading. The project appears to be actively maintained, with new features like `svg-sprite` recently introduced, though a fixed release cadence is not explicitly stated. A key differentiator is its tight integration with the Remix ecosystem, including type generation for icon names and components optimized for Remix's server-side rendering and asset linking.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates installing `rmx-cli`, generating SVG sprites and React components, and then using them in a Remix route with proper link preloading.

import { json, type LinksFunction } from '@remix-run/node';
import { useLoaderData } from '@remix-run/react';
import tailwindCss from '~/styles/tailwind.css'; // Assuming you have tailwind CSS

// Install the CLI:
// npm install -D rmx-cli

// Create a directory for your SVG assets, e.g., 'assets/svg'
// Add some SVG files inside 'assets/svg'

// Run the SVG sprite generation command:
// npx rmx-cli svg-sprite assets/svg app/components/icons

// The command above generates files like `app/components/icons/icons.tsx` and `app/components/icons/icons.svg`

// Import the generated default Icon component and its sprite href
import Icon, { href as iconsSpriteHref } from '~/components/icons/icons';

// If you used the --components flag, you would import specific icons like this:
// import { BookmarkIcon, EnvelopeOpenIcon } from '~/components/icons/icons';

export const links: LinksFunction = () => [
  { rel: 'preload', href: iconsSpriteHref, as: 'image' },
  { rel: 'stylesheet', href: tailwindCss }
];

export const loader = async () => {
  return json({ message: 'Welcome to Remix!' });
};

export default function Index() {
  const { message } = useLoaderData<typeof loader>();

  return (
    <div className="font-sans p-4">
      <h1 className="text-3xl font-bold mb-4">{message}</h1>
      <div className="flex items-center space-x-2">
        <p>Using generated SVG icons:</p>
        {/* Example of using the default Icon component */}
        <Icon icon="bookmark" size="lg" className="text-blue-500" />
        <Icon icon="envelope-open" size="lg" className="text-green-500" />
        {/* If using --components, you would use:
        <BookmarkIcon className="text-blue-500 w-6 h-6" />
        <EnvelopeOpenIcon className="text-green-500 w-6 h-6" />
        */}
      </div>
    </div>
  );
}

view raw JSON →