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 🙏

© 2025 – Pkg Stats / Ryan Hefner

plasmo-layout

v1.0.5

Published

Automate HTML layout generation for Plasmo browser extension components

Readme

We're open to technical consulting and engineering partnerships and contract opportunities. Initiated with Love ❤️ from Biafra.

Overview

plasmo-layout is a CLI tool that automatically generates HTML files for Plasmo browser extension components. It scans your component files for @layout decorators and generates the corresponding HTML files that Plasmo uses to override default component HTML.

Features

  • 🔍 Auto-discovery - Scans components for @layout('path') decorators
  • 🎨 Multiple engines - Supports JSX, Edge.js, and custom templating engines
  • 📁 Plasmo conventions - Follows Plasmo's HTML file naming conventions
  • 👀 Watch mode - Incremental rebuilds on file changes
  • 🧹 Clean command - Remove all generated files with one command
  • ⚙️ Configurable - Flexible include/exclude patterns

Installation

npm install --save-dev plasmo-layout

Note: When installed as a dev dependency, use npx plasmo-layout to run commands. For global installation (npm install -g plasmo-layout), you can use plasmo-layout directly.

Peer Dependencies

Depending on which templating engine you use, install the corresponding peer dependency:

# For JSX layouts (default)
npm install react react-dom

# For Edge.js layouts
npm install edge.js

Quick Start

  1. Initialize configuration (optional):

    npx plasmo-layout init
  2. Create a layout file in layouts/ directory:

    // layouts/default.tsx
    export default function DefaultLayout() {
      return (
        <html>
          <head>
            <title>My Extension</title>
          </head>
          <body>
            <div id="root"></div>
          </body>
        </html>
      );
    }
  3. Add @layout decorator to your Plasmo component:

    // src/popup/index.tsx
    // @layout('default')
    
    export default function Popup() {
      return <div>Hello from Popup!</div>;
    }
  4. Run the build:

    npx plasmo-layout build

    This generates src/popup/popup.html based on your layout.

CLI Commands

build

Scan components and generate HTML files.

npx plasmo-layout build [options]

Options:
  -c, --config <path>   Path to config file
  -r, --root <path>     Project root directory (default: cwd)
  -v, --verbose         Enable verbose logging

watch

Watch for file changes and rebuild incrementally.

npx plasmo-layout watch [options]

Options:
  -c, --config <path>   Path to config file
  -r, --root <path>     Project root directory (default: cwd)
  -v, --verbose         Enable verbose logging

clean

Remove all generated HTML files.

npx plasmo-layout clean [options]

Options:
  -c, --config <path>   Path to config file
  -r, --root <path>     Project root directory (default: cwd)
  -d, --dry-run         Show what would be deleted
  -v, --verbose         Enable verbose logging

init

Create a default configuration file.

npx plasmo-layout init [options]

Options:
  -r, --root <path>     Project root directory (default: cwd)
  -t, --typescript      Create TypeScript config file

Configuration

Create a plasmo-layout.config.js (or .ts, .mjs, .cjs) file in your project root:

/** @type {import('plasmo-layout').PlasmoLayoutConfig} */
export default {
  // Glob patterns for files to scan
  include: ['src/**/*.{tsx,jsx}'],
  
  // Glob patterns to exclude
  exclude: [
    '**/node_modules/**',
    '**/.git/**',
    '**/dist/**',
    '**/build/**',
  ],
  
  // Directory containing layout templates
  layoutsDir: 'layouts',
  
  // Templating engine: 'jsx' | 'edge' | 'custom'
  engine: 'jsx',
  
  // Enable verbose logging
  verbose: false,
};

Custom Engine

To use a custom templating engine:

// plasmo-layout.config.js
export default {
  engine: 'custom',
  customEngine: {
    path: './my-custom-engine.js',
  },
};

Your custom engine must implement the CustomEngine interface:

// my-custom-engine.js
export default {
  name: 'my-engine',
  extensions: ['.myext'],
  
  async render(templatePath, context) {
    // Read template, process it, return HTML string
    return '<html>...</html>';
  },
  
  // Optional hooks
  async initialize() {},
  async cleanup() {},
};

Layout Path Resolution

The @layout decorator uses dot notation to specify layout paths:

| Decorator | Resolved Path | | ----------------------------------- | ------------------------------------------ | | @layout('default') | layouts/default.{tsx,jsx} | | @layout('tabs.onboarding') | layouts/tabs/onboarding.{tsx,jsx} | | @layout('admin.dashboard.main') | layouts/admin/dashboard/main.{tsx,jsx} |

Output Naming Convention

Following Plasmo conventions:

| Component Path | Generated HTML | | ------------------------- | ---------------------------- | | src/popup/index.tsx | src/popup/popup.html | | src/popup.tsx | src/popup.html | | src/options/index.tsx | src/options/options.html | | src/tabs/settings.tsx | src/tabs/settings.html |

Generated File Tracking

Generated HTML files include a special comment header:

<!-- GENERATED BY PLASMO-LAYOUT - DO NOT EDIT MANUALLY -->

This allows the clean command to identify and remove only generated files.

Programmatic API

You can also use plasmo-layout programmatically:

import { loadConfig, executeBuild, executeClean, executeWatch } from 'plasmo-layout';

// Load configuration
const config = await loadConfig('./my-project');

// Run build
const summary = await executeBuild(config);
console.log(`Generated ${summary.successCount} files`);

// Run clean
const cleanResult = await executeClean(config);

// Start watch mode
const watcher = await executeWatch(config, {
  onProcessComplete: (file, success) => {
    console.log(`Processed: ${file}, Success: ${success}`);
  },
});

// Later: stop watching
await watcher.stop();

Troubleshooting

Command not found: plasmo-layout

If you get sh: plasmo-layout: command not found, this usually means:

  1. Using local installation incorrectly: When installed as a dev dependency (npm install --save-dev plasmo-layout), you must use npx:

    npx plasmo-layout build
  2. Package not built: Ensure the package is properly built and the dist folder exists:

    npm run build
  3. Missing in node_modules: The package wasn't installed correctly:

    rm -rf node_modules package-lock.json
    npm install
  4. Global installation: If you prefer using plasmo-layout directly without npx, install globally:

    npm install -g plasmo-layout

Package scripts alternative

You can also add npm scripts to your package.json:

{
  "scripts": {
    "layout:build": "plasmo-layout build",
    "layout:watch": "plasmo-layout watch",
    "layout:clean": "plasmo-layout clean"
  }
}

Then run: npm run layout:build

License

License: MIT

This Project is MIT Licensed