This project is no longer maintained.
Life got busy — work, kids, and the usual chaos. I no longer have the time or energy to keep up with issues or updates. Use it if it works for you, but don't expect updates or support.

Configuration

Preview.js may not work out of the box for your project, but fear not! You could be one line of config away from your goal.

You can configure your project for Preview.js by adding a file named preview.config.js next to your package.json.

// preview.config.js

import { defineConfig } from "@previewjs/config";

export default defineConfig({
  /**
   * Configure a public assets directory.
   */
  publicDir: "public",

  /**
   * Set up a custom component to wrap around previewed components.
   *
   * Useful to set up context providers and global CSS.
   */
  wrapper: {
    path: "__previewjs__/Wrapper.tsx",
    componentName: "Wrapper",
  },

  /**
   * Specify a custom Vite configuration.
   *
   * See https://vitejs.dev/config.
   */
  vite: {
    resolve: {
      /**
       * Configure custom aliases (auto-detected if you use TypeScript).
       */
      alias: {
        foo: "src/foo",
      },
    },
  },
});

Read on to learn about:

  • configuring module aliases
  • handling static assets
  • setting up CSS rules
  • wrapping components (including providing context)
  • customising SVGR components (React only)