AgentSkillsCN

storefront-widget

当用户询问“门店小部件”“scripttag”“面向客户”“Preact”“包体积”“懒加载”“性能优化”,或任何门店前端开发相关需求时,可运用此技能。它将提供 Preact 模式,助力打造轻量级的门店小部件。

SKILL.md
--- frontmatter
name: storefront-widget
description: Use this skill when the user asks about "storefront widget", "scripttag", "customer-facing", "Preact", "bundle size", "lazy loading", "performance optimization", or any storefront frontend work. Provides Preact patterns for lightweight storefront widgets.

Scripttag Development (Storefront Widget)

Quick Reference

TopicReference File
Bundle Size, Lazy Loading, Tree Shakingreferences/performance.md
Preact Hooks, Sharing Componentsreferences/preact-patterns.md
Fetch/XHR/Form Interceptionreferences/request-interception.md

Overview

The scripttag package contains customer-facing storefront widgets injected into merchant stores. Performance is CRITICAL - every KB and millisecond impacts merchant store speed and conversion rates.


Tech Stack

TechnologyPurposeWhy
PreactUI library3KB vs React's 40KB+
SCSSStylingScoped styles, minimal footprint
RspackBundler10x faster than webpack
Theme App ExtensionScript loadingShopify-native

Styling: Always use custom SCSS/CSS. Avoid UI libraries.


Directory Structure

code
packages/scripttag/
├── src/                      # Main widget entry
│   ├── index.js              # Main entry point
│   ├── loader.js             # Minimal loader script
│   ├── components/           # Shared components
│   └── styles/               # Global styles
├── [feature-name]/           # Feature-specific modules
└── rspack.config.js          # Build configuration

Loading via Theme App Extension

liquid
{% comment %} blocks/app-embed.liquid {% endcomment %}
<script>
  window.AVADA_APP_DATA = {
    shop: {{ shop | json }},
    customer: {{ customer | json }},
    settings: {{ block.settings | json }},
    config: {{ shop.metafields['$app:feature']['config'].value | json }}
  };
</script>

<script src="{{ app_url }}/widget.min.js" defer></script>

Styling (SCSS with BEM)

scss
.widget {
  &__button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background: var(--primary-color);
    color: white;

    &--secondary {
      background: transparent;
      border: 1px solid var(--primary-color);
    }
  }
}

Environment Configuration

javascript
// rspack.config.js loads in order:
// 1. .env.{ENVIRONMENT}
// 2. .env.local
// 3. .env

process.env.API_URL      // Backend API URL
process.env.HOST         // Current host URL
process.env.PUBLIC_PATH  // CDN path for assets

Development Commands

bash
npm run watch         # Development with watch
npm run build         # Production build
npm run build:analyze # Analyze bundle size

Checklist

Before Commit

code
- No barrel imports (use direct paths)
- Heavy components lazy loaded
- No console.log in production
- Custom SCSS with BEM naming
- No UI library dependencies

Bundle Size Check

code
- Loader < 3KB gzipped
- Main bundle < 50KB gzipped
- No unexpected large chunks