[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75PKWDHZBNYXWY2ECZ4DRP8":3,"skill-same:01M75PKWDHZBNYXWY2ECZ4DRP8":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M75PKWDHZBNYXWY2ECZ4DRP8","plugin-bundle-size",null,"Optimise Grafana app plugin bundle size using React.lazy, Suspense, and webpack code splitting. Use when the user asks to reduce plugin bundle size, optimise module.js, add code splitting, improve initial plugin load performance, split plugin chunks, lazy load plugin pages, or help implement lazy loading in a Grafana app plugin. Triggers on phrases like \"optimise plugin bundle size\", \"module.js is too large\", \"plugin is slow to load\", \"code split the plugin\", \"reduce initial JS payload\", or \"help me with Suspense in my plugin\".","stanfish06\u002Fskillquarium","stanfish06","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F93099613?v=4","01M75F1CK4ZW109ZK3T26VN52F","Zhiyuan","01M75F1CM53VH6F79DZ8GXKKES",12,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fplugin-bundle-size\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: plugin-bundle-size\nlicense: Apache-2.0\ndescription:\n  Optimise Grafana app plugin bundle size using React.lazy, Suspense, and webpack code splitting.\n  Use when the user asks to reduce plugin bundle size, optimise module.js, add code splitting,\n  improve initial plugin load performance, split plugin chunks, lazy load plugin pages, or\n  help implement lazy loading in a Grafana app plugin. Triggers on phrases like \"optimise plugin\n  bundle size\", \"module.js is too large\", \"plugin is slow to load\", \"code split the plugin\",\n  \"reduce initial JS payload\", or \"help me with Suspense in my plugin\".\n---\n\n# Grafana plugin bundle size optimisation\n\n`module.js` is the render-blocking entry point for every Grafana app plugin. The smaller it is, the less impact the plugin has on Grafana's overall startup time. A well-split plugin should have a `module.js` under ~200 KB that contains nothing but lazy-loaded wrappers — all feature code loads on demand.\n\n**Target:** ~15–25 JS chunks total. Fewer means too little splitting; far more (50+) means over-engineering.\n\n## Risk levels\n\nNot all splitting opportunities carry the same risk. Apply them in this order:\n\n| Level | What | Risk | Impact |\n|---|---|---|---|\n| **Safe** | `module.tsx` lazy wrappers (Priority 1) | Very low — no behaviour change | Highest — module.js drops 90%+ |\n| **Safe** | Route-level `lazy()` (Priority 2) | Low — each route is self-contained | High — one chunk per route |\n| **Safe** | Extension `lazy()` (Priority 3) | Low — extensions are isolated | Medium — independent chunk per extension |\n| **Moderate** | Component registries \u002F tab panels (Priority 4) | Medium — verify Suspense placement | Medium — splits heavy pages further |\n| **Do not touch** | Vendor libraries (`@grafana\u002Fscenes`, `@reduxjs\u002Ftoolkit`) | N\u002FA | N\u002FA — webpack splits these automatically |\n| **Do not touch** | Shared utility components (Markdown, Spinner) used across many files | High churn, many callsites | Low — already in shared vendor chunks |\n\nWhen in doubt, stop after Priority 2. Routes alone typically reduce `module.js` by 95%+.\n\n---\n\n## Step 1: Add bundle size CI reporting (recommended)\n\nAdd the `grafana\u002Fplugin-actions\u002Fbundle-size` action to get automatic bundle size comparison comments on every PR. This posts a table showing entry point size changes, file count diffs, and total bundle impact.\n\n**Root-level plugins** (plugin at repo root):\n\n```yaml\n# .github\u002Fworkflows\u002Fbundle-size.yml\nname: Bundle Size\non:\n  pull_request:\n  push:\n    branches: [main]\n  workflow_dispatch:\n\njobs:\n  bundle-size:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n      id-token: write\n      pull-requests: write\n      actions: read\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version-file: .nvmrc\n      - name: Install and build\n        run: yarn install\n      - name: Bundle Size\n        uses: grafana\u002Fplugin-actions\u002Fbundle-size@a66a1c96cdbb176f9cccf10cf23593e250db7cce # bundle-size\u002Fv1.1.0\n```\n\n**Subdirectory plugins** (e.g. `plugin\u002F` in a monorepo):\n\nThe action's install step runs at the repo root and cannot find `yarn.lock` in a subdirectory. Work around this by installing deps yourself and symlinking to root:\n\n```yaml\njobs:\n  bundle-size:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n      id-token: write\n      pull-requests: write\n      actions: read\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version-file: .\u002Fplugin\u002F.nvmrc\n      - name: Install dependencies\n        working-directory: .\u002Fplugin\n        run: yarn install\n      - name: Symlink plugin to root for bundle-size action\n        run: |\n          ln -s plugin\u002Fyarn.lock yarn.lock\n          ln -s plugin\u002Fpackage.json package.json\n          ln -s plugin\u002F.yarnrc.yml .yarnrc.yml\n          ln -s plugin\u002Fnode_modules node_modules\n      - name: Bundle Size\n        uses: grafana\u002Fplugin-actions\u002Fbundle-size@a66a1c96cdbb176f9cccf10cf23593e250db7cce # bundle-size\u002Fv1.1.0\n        with:\n          working-directory: .\u002Fplugin\n```\n\n**How it works:** On push to main, builds and uploads a baseline artifact. On PRs, compares against it and posts a diff comment. Use `workflow_dispatch` to generate the first baseline.\n\n**Reference:** [grafana-k8s-plugin workflow](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fgrafana-k8s-plugin\u002Fblob\u002Fmain\u002F.github\u002Fworkflows\u002Fgrafana.yml)\n\n---\n\n## Step 2: Detect plugin context\n\n```bash\n# Confirm this is an app plugin (type: \"app\" — datasource\u002Fpanel plugins have different needs)\njq -r '\"\\(.id) — \\(.type)\"' src\u002Fplugin.json\n\n# Locate the entry point\nls src\u002Fmodule.ts src\u002Fmodule.tsx 2>\u002Fdev\u002Fnull\n\n# Measure the current PRODUCTION bundle size BEFORE making any changes\n# Dev builds are unminified and much larger — always measure production\nyarn build 2>\u002Fdev\u002Fnull || npm run build\necho \"=== module.js ===\" && ls -lah dist\u002Fmodule.js\necho \"=== all JS chunks ===\" && ls -lah dist\u002F*.js | sort -k5 -rh | head -20\necho \"=== chunk count ===\" && ls dist\u002F*.js | wc -l\n```\n\nRecord the baseline. A pre-split plugin commonly has a `module.js` of 1–3 MB with no other JS chunks.\n\n---\n\n## Step 3: Check and update create-plugin\n\nThe `@grafana\u002Fcreate-plugin` tool controls `.config\u002Fwebpack\u002F`, `.config\u002Fjest\u002F`, and other build scaffolding. Updating it often unlocks faster SWC compilation and better chunk output.\n\n```bash\ncat .config\u002F.cprc.json 2>\u002Fdev\u002Fnull || grep '\"@grafana\u002Fcreate-plugin\"' package.json\nnpm view @grafana\u002Fcreate-plugin version\nnpx @grafana\u002Fcreate-plugin@latest update\n```\n\nAfter updating, review the diff (especially `.config\u002Fwebpack\u002Fwebpack.config.ts`) and run a test build. If the plugin has a top-level `webpack.config.ts` that `webpack-merge`s the base config, review the merge for conflicts.\n\n---\n\n## Step 4: Analyse the codebase — find what to split\n\nDo **not** start implementing until you have read all of these.\n\n```bash\n# Entry point — look for direct (non-lazy) imports of App, ConfigPage, exposeComponent targets\ncat src\u002Fmodule.ts 2>\u002Fdev\u002Fnull || cat src\u002Fmodule.tsx\n\n# Root App component — look for direct page\u002Froute imports that should be lazy\ncat src\u002FApp.tsx src\u002Fcomponents\u002FApp.tsx src\u002Ffeature\u002Fapp\u002Fcomponents\u002FApp.tsx 2>\u002Fdev\u002Fnull | head -80\n\n# Extension registrations — each should become an independent chunk\ngrep -r \"exposeComponent\\|addComponent\\|addLink\" src\u002F --include=\"*.ts\" --include=\"*.tsx\" -n\n\n# Exported side-effect singletons (Faro, analytics) — must be extracted before splitting\ngrep -n \"^export const\\|^export let\" src\u002Fmodule.ts src\u002Fmodule.tsx 2>\u002Fdev\u002Fnull\ngrep -rn \"from '.*module'\" src\u002F --include=\"*.ts\" --include=\"*.tsx\" | grep -v node_modules\n\n# Heavy synchronous imports\ngrep -rn \"from 'monaco-editor\\|@codemirror\\|d3\\b\\|recharts\\|chart\\.js\" \\\n  src\u002F --include=\"*.ts\" --include=\"*.tsx\" | grep -v node_modules\n```\n\n**Key rule:** If a file is imported by `module.ts` directly (even transitively), it ends up in `module.js`. Everything reachable from a lazy boundary becomes its own chunk.\n\n---\n\n## Step 5: Implement splits — in priority order\n\n> **Named vs default exports:** `React.lazy()` requires a `default` export. Most Grafana plugin components use named exports — use `.then()` to re-map:\n> ```ts\n> \u002F\u002F Named export\n> const LazyMyComp = lazy(() => import('.\u002FMyComponent').then(m => ({ default: m.MyComponent })));\n> \u002F\u002F Default export\n> const LazyMyComp = lazy(() => import('.\u002FMyComponent'));\n> ```\n\n### Priority 1: module.tsx (highest impact, always do this first)\n\nIf the entry point is `module.ts`, rename it: `git mv src\u002Fmodule.ts src\u002Fmodule.tsx`\n\nMake `module.tsx` import **nothing** from feature code except through `lazy()`:\n\n```tsx\nimport React, { lazy, Suspense } from 'react';\nimport { AppPlugin, AppRootProps } from '@grafana\u002Fdata';\nimport { LoadingPlaceholder } from '@grafana\u002Fui';\n\nimport type { MyExtensionProps } from '.\u002Fextensions\u002FMyExtension';  \u002F\u002F import type — erased at compile time\nimport type { JsonData } from '.\u002Ffeatures\u002Fapp\u002Fstate\u002Fslice';\n\n\u002F\u002F Lazy Faro init — keeps @grafana\u002Ffaro-react out of module.js\nlet faroInitialized = false;\nasync function initFaro() {\n  if (faroInitialized) { return; }\n  faroInitialized = true;\n  const { initializeFaro } = await import('faro');\n  initializeFaro();\n}\n\nconst LazyApp = lazy(async () => {\n  await initFaro();\n  return import('.\u002Ffeatures\u002Fapp\u002FApp').then(m => ({ default: m.App }));\n});\n\nfunction App(props: AppRootProps\u003CJsonData>) {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CLazyApp {...props} \u002F>\u003C\u002FSuspense>;\n}\n\nconst LazyMyExtension = lazy(() =>\n  import('.\u002Fextensions\u002FMyExtension').then(m => ({ default: m.MyExtension }))\n);\nfunction MyExtension(props: MyExtensionProps) {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CLazyMyExtension {...props} \u002F>\u003C\u002FSuspense>;\n}\n\nexport const plugin = new AppPlugin\u003CJsonData>().setRootPage(App);\nplugin.exposeComponent({ id: 'my-plugin\u002Fmy-extension\u002Fv1', title: 'My Extension', component: MyExtension });\n```\n\n**Key details:**\n- `import type` for props prevents webpack from following the import into the eager bundle\n- Use `new AppPlugin\u003CJsonData>()` if App uses `AppRootProps\u003CJsonData>` — without the generic, `setRootPage()` type won't match\n- Remove any `App as unknown as ComponentClass\u003CAppRootProps>` cast — the lazy wrapper is a valid function component\n\n**Expected impact:** `module.js` drops from MB range to ~50–200 KB.\n\n**Singletons (e.g. Faro):** If `module.ts` has `export const faro = initializeFaro()`, do NOT keep it as a top-level import. Extract it to `src\u002Ffaro.ts`, update all internal imports from `'*\u002Fmodule'` → `'*\u002Ffaro'`, then use the dynamic `initFaro()` pattern above.\n\n---\n\n### Priority 2: Route-based splitting in App.tsx\n\n```tsx\nimport React, { lazy, Suspense } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport { LoadingPlaceholder } from '@grafana\u002Fui';\n\nconst HomePage     = lazy(() => import('..\u002Fpages\u002FHome'));\nconst SettingsPage = lazy(() => import('..\u002Fpages\u002FSettings'));\nconst DetailPage   = lazy(() => import('..\u002Fpages\u002FDetail'));\n\nfunction App(props: AppRootProps) {\n  return (\n    \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\n      \u003CRoutes>\n        \u003CRoute path=\"home\"       element={\u003CHomePage \u002F>} \u002F>\n        \u003CRoute path=\"settings\"   element={\u003CSettingsPage \u002F>} \u002F>\n        \u003CRoute path=\"detail\u002F:id\" element={\u003CDetailPage \u002F>} \u002F>\n        \u003CRoute path=\"\"           element={\u003CHomePage \u002F>} \u002F>\n      \u003C\u002FRoutes>\n    \u003C\u002FSuspense>\n  );\n}\nexport default App;\n```\n\n**Bypass barrel files:** Target the actual component file in the `import()`, not an `index.ts` barrel that re-exports multiple things:\n\n```tsx\n\u002F\u002F Risky — barrel may pull in other heavy modules\nconst Catalog = lazy(() => import('features\u002Fcatalog'));\n\u002F\u002F Better — only pulls in Catalog's tree\nconst Catalog = lazy(() => import('features\u002Fcatalog\u002FCatalog').then(m => ({ default: m.Catalog })));\n```\n\n### Priority 3: Extension components\n\nEach extension should `export default` its component. Use `fallback={null}` for extensions that load quickly:\n\n```tsx\n\u002F\u002F src\u002Fextensions\u002FMyExtension.tsx\nexport default function MyExtension(props: MyExtensionProps) {\n  return \u003CAppProviders>\u003CMyExtensionContent {...props} \u002F>\u003C\u002FAppProviders>;\n}\n```\n\n**Surgical split:** If an extension wrapper must stay eager in `module.tsx`, lazy-load the heavy component it renders:\n\n```tsx\nconst HeavyInner = lazy(() => import('components\u002Ffeatures\u002FHeavyInner'));\nexport function MyExtension() {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CHeavyInner \u002F>\u003C\u002FSuspense>;\n}\n```\n\n### Priority 4: Component registries and tab panels\n\nFor arrays of objects containing React components (e.g. tab panels), lazy-load each entry. **Critical:** ensure a `\u003CSuspense>` boundary exists where the component renders.\n\n```tsx\nconst ConfigDetails = lazy(() => import('.\u002FConfigDetails\u002FConfigDetails').then(m => ({ default: m.ConfigDetails })));\nconst Overview      = lazy(() => import('.\u002FOverview\u002FOverview').then(m => ({ default: m.Overview })));\n\nconst tabs = [\n  { id: 'overview', component: Overview },\n  { id: 'config',   component: ConfigDetails },\n];\n\n\u002F\u002F In the parent that renders the active tab:\n\u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\n  {ActiveTab && \u003CActiveTab \u002F>}\n\u003C\u002FSuspense>\n```\n\nFor **datasource plugins** (`setConfigEditor`, `setQueryEditor`, `VariableSupport`, `AnnotationSupport`), see [references\u002Fdatasource-plugins.md](references\u002Fdatasource-plugins.md).\n\n---\n\n## Step 6: Group related chunks if over-splitting\n\nIf the build produces more than ~25 JS files, use webpack magic comments:\n\n```tsx\nconst FleetList   = lazy(() => import(\u002F* webpackChunkName: \"fleet\" *\u002F '..\u002Fpages\u002FFleetList'));\nconst FleetDetail = lazy(() => import(\u002F* webpackChunkName: \"fleet\" *\u002F '..\u002Fpages\u002FFleetDetail'));\n```\n\nOne `webpackChunkName` per logical feature area. Don't group unrelated pages.\n\n---\n\n## Step 7: Measure and verify\n\n```bash\nyarn build 2>\u002Fdev\u002Fnull || npm run build\necho \"=== module.js ===\" && ls -lah dist\u002Fmodule.js\necho \"=== all JS chunks (largest first) ===\" && ls -lah dist\u002F*.js | sort -k5 -rh | head -30\necho \"=== chunk count ===\" && ls dist\u002F*.js | wc -l\n```\n\n| Metric | Target |\n|---|---|\n| `module.js` size | \u003C 200 KB |\n| Total JS chunk count | 15–25 |\n| Largest single chunk | \u003C 1 MB |\n\n```bash\n# Analyse bundle composition if a chunk is unexpectedly large\nnpx webpack-bundle-analyzer dist\u002Fstats.json 2>\u002Fdev\u002Fnull\n```\n\n---\n\n## Step 8: Test the running plugin\n\n1. Open the plugin in a Grafana instance\n2. Navigate to **every route** — each triggers a new chunk download\n3. **DevTools → Network → JS**: confirm lazy chunks load on navigation, not all upfront\n4. Check **Console** for errors\n5. Test any `exposeComponent` extensions from other Grafana apps\n\nFor troubleshooting common issues, see [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md).\n\n---\n\n## References\n\n- [grafana-collector-app](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fgrafana-collector-app) — app plugin reference implementation\n- [grafana\u002Fplugin-actions](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fplugin-actions) — official Grafana plugin CI actions\n- [Web.dev — code splitting with lazy and Suspense](https:\u002F\u002Fweb.dev\u002Farticles\u002Fcode-splitting-suspense)\n- [SurviveJS — webpack code splitting](https:\u002F\u002Fsurvivejs.com\u002Fbooks\u002Fwebpack\u002Fbuilding\u002Fcode-splitting\u002F)\n- [webpack magic comments](https:\u002F\u002Fwebpack.js.org\u002Fapi\u002Fmodule-methods\u002F#magic-comments)\n","# Grafana plugin bundle size optimisation\n\n`module.js` is the render-blocking entry point for every Grafana app plugin. The smaller it is, the less impact the plugin has on Grafana's overall startup time. A well-split plugin should have a `module.js` under ~200 KB that contains nothing but lazy-loaded wrappers — all feature code loads on demand.\n\n**Target:** ~15–25 JS chunks total. Fewer means too little splitting; far more (50+) means over-engineering.\n\n## Risk levels\n\nNot all splitting opportunities carry the same risk. Apply them in this order:\n\n| Level | What | Risk | Impact |\n|---|---|---|---|\n| **Safe** | `module.tsx` lazy wrappers (Priority 1) | Very low — no behaviour change | Highest — module.js drops 90%+ |\n| **Safe** | Route-level `lazy()` (Priority 2) | Low — each route is self-contained | High — one chunk per route |\n| **Safe** | Extension `lazy()` (Priority 3) | Low — extensions are isolated | Medium — independent chunk per extension |\n| **Moderate** | Component registries \u002F tab panels (Priority 4) | Medium — verify Suspense placement | Medium — splits heavy pages further |\n| **Do not touch** | Vendor libraries (`@grafana\u002Fscenes`, `@reduxjs\u002Ftoolkit`) | N\u002FA | N\u002FA — webpack splits these automatically |\n| **Do not touch** | Shared utility components (Markdown, Spinner) used across many files | High churn, many callsites | Low — already in shared vendor chunks |\n\nWhen in doubt, stop after Priority 2. Routes alone typically reduce `module.js` by 95%+.\n\n---\n\n## Step 1: Add bundle size CI reporting (recommended)\n\nAdd the `grafana\u002Fplugin-actions\u002Fbundle-size` action to get automatic bundle size comparison comments on every PR. This posts a table showing entry point size changes, file count diffs, and total bundle impact.\n\n**Root-level plugins** (plugin at repo root):\n\n```yaml\n# .github\u002Fworkflows\u002Fbundle-size.yml\nname: Bundle Size\non:\n  pull_request:\n  push:\n    branches: [main]\n  workflow_dispatch:\n\njobs:\n  bundle-size:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n      id-token: write\n      pull-requests: write\n      actions: read\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version-file: .nvmrc\n      - name: Install and build\n        run: yarn install\n      - name: Bundle Size\n        uses: grafana\u002Fplugin-actions\u002Fbundle-size@a66a1c96cdbb176f9cccf10cf23593e250db7cce # bundle-size\u002Fv1.1.0\n```\n\n**Subdirectory plugins** (e.g. `plugin\u002F` in a monorepo):\n\nThe action's install step runs at the repo root and cannot find `yarn.lock` in a subdirectory. Work around this by installing deps yourself and symlinking to root:\n\n```yaml\njobs:\n  bundle-size:\n    runs-on: ubuntu-latest\n    permissions:\n      contents: write\n      id-token: write\n      pull-requests: write\n      actions: read\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version-file: .\u002Fplugin\u002F.nvmrc\n      - name: Install dependencies\n        working-directory: .\u002Fplugin\n        run: yarn install\n      - name: Symlink plugin to root for bundle-size action\n        run: |\n          ln -s plugin\u002Fyarn.lock yarn.lock\n          ln -s plugin\u002Fpackage.json package.json\n          ln -s plugin\u002F.yarnrc.yml .yarnrc.yml\n          ln -s plugin\u002Fnode_modules node_modules\n      - name: Bundle Size\n        uses: grafana\u002Fplugin-actions\u002Fbundle-size@a66a1c96cdbb176f9cccf10cf23593e250db7cce # bundle-size\u002Fv1.1.0\n        with:\n          working-directory: .\u002Fplugin\n```\n\n**How it works:** On push to main, builds and uploads a baseline artifact. On PRs, compares against it and posts a diff comment. Use `workflow_dispatch` to generate the first baseline.\n\n**Reference:** [grafana-k8s-plugin workflow](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fgrafana-k8s-plugin\u002Fblob\u002Fmain\u002F.github\u002Fworkflows\u002Fgrafana.yml)\n\n---\n\n## Step 2: Detect plugin context\n\n```bash\n# Confirm this is an app plugin (type: \"app\" — datasource\u002Fpanel plugins have different needs)\njq -r '\"\\(.id) — \\(.type)\"' src\u002Fplugin.json\n\n# Locate the entry point\nls src\u002Fmodule.ts src\u002Fmodule.tsx 2>\u002Fdev\u002Fnull\n\n# Measure the current PRODUCTION bundle size BEFORE making any changes\n# Dev builds are unminified and much larger — always measure production\nyarn build 2>\u002Fdev\u002Fnull || npm run build\necho \"=== module.js ===\" && ls -lah dist\u002Fmodule.js\necho \"=== all JS chunks ===\" && ls -lah dist\u002F*.js | sort -k5 -rh | head -20\necho \"=== chunk count ===\" && ls dist\u002F*.js | wc -l\n```\n\nRecord the baseline. A pre-split plugin commonly has a `module.js` of 1–3 MB with no other JS chunks.\n\n---\n\n## Step 3: Check and update create-plugin\n\nThe `@grafana\u002Fcreate-plugin` tool controls `.config\u002Fwebpack\u002F`, `.config\u002Fjest\u002F`, and other build scaffolding. Updating it often unlocks faster SWC compilation and better chunk output.\n\n```bash\ncat .config\u002F.cprc.json 2>\u002Fdev\u002Fnull || grep '\"@grafana\u002Fcreate-plugin\"' package.json\nnpm view @grafana\u002Fcreate-plugin version\nnpx @grafana\u002Fcreate-plugin@latest update\n```\n\nAfter updating, review the diff (especially `.config\u002Fwebpack\u002Fwebpack.config.ts`) and run a test build. If the plugin has a top-level `webpack.config.ts` that `webpack-merge`s the base config, review the merge for conflicts.\n\n---\n\n## Step 4: Analyse the codebase — find what to split\n\nDo **not** start implementing until you have read all of these.\n\n```bash\n# Entry point — look for direct (non-lazy) imports of App, ConfigPage, exposeComponent targets\ncat src\u002Fmodule.ts 2>\u002Fdev\u002Fnull || cat src\u002Fmodule.tsx\n\n# Root App component — look for direct page\u002Froute imports that should be lazy\ncat src\u002FApp.tsx src\u002Fcomponents\u002FApp.tsx src\u002Ffeature\u002Fapp\u002Fcomponents\u002FApp.tsx 2>\u002Fdev\u002Fnull | head -80\n\n# Extension registrations — each should become an independent chunk\ngrep -r \"exposeComponent\\|addComponent\\|addLink\" src\u002F --include=\"*.ts\" --include=\"*.tsx\" -n\n\n# Exported side-effect singletons (Faro, analytics) — must be extracted before splitting\ngrep -n \"^export const\\|^export let\" src\u002Fmodule.ts src\u002Fmodule.tsx 2>\u002Fdev\u002Fnull\ngrep -rn \"from '.*module'\" src\u002F --include=\"*.ts\" --include=\"*.tsx\" | grep -v node_modules\n\n# Heavy synchronous imports\ngrep -rn \"from 'monaco-editor\\|@codemirror\\|d3\\b\\|recharts\\|chart\\.js\" \\\n  src\u002F --include=\"*.ts\" --include=\"*.tsx\" | grep -v node_modules\n```\n\n**Key rule:** If a file is imported by `module.ts` directly (even transitively), it ends up in `module.js`. Everything reachable from a lazy boundary becomes its own chunk.\n\n---\n\n## Step 5: Implement splits — in priority order\n\n> **Named vs default exports:** `React.lazy()` requires a `default` export. Most Grafana plugin components use named exports — use `.then()` to re-map:\n> ```ts\n> \u002F\u002F Named export\n> const LazyMyComp = lazy(() => import('.\u002FMyComponent').then(m => ({ default: m.MyComponent })));\n> \u002F\u002F Default export\n> const LazyMyComp = lazy(() => import('.\u002FMyComponent'));\n> ```\n\n### Priority 1: module.tsx (highest impact, always do this first)\n\nIf the entry point is `module.ts`, rename it: `git mv src\u002Fmodule.ts src\u002Fmodule.tsx`\n\nMake `module.tsx` import **nothing** from feature code except through `lazy()`:\n\n```tsx\nimport React, { lazy, Suspense } from 'react';\nimport { AppPlugin, AppRootProps } from '@grafana\u002Fdata';\nimport { LoadingPlaceholder } from '@grafana\u002Fui';\n\nimport type { MyExtensionProps } from '.\u002Fextensions\u002FMyExtension';  \u002F\u002F import type — erased at compile time\nimport type { JsonData } from '.\u002Ffeatures\u002Fapp\u002Fstate\u002Fslice';\n\n\u002F\u002F Lazy Faro init — keeps @grafana\u002Ffaro-react out of module.js\nlet faroInitialized = false;\nasync function initFaro() {\n  if (faroInitialized) { return; }\n  faroInitialized = true;\n  const { initializeFaro } = await import('faro');\n  initializeFaro();\n}\n\nconst LazyApp = lazy(async () => {\n  await initFaro();\n  return import('.\u002Ffeatures\u002Fapp\u002FApp').then(m => ({ default: m.App }));\n});\n\nfunction App(props: AppRootProps\u003CJsonData>) {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CLazyApp {...props} \u002F>\u003C\u002FSuspense>;\n}\n\nconst LazyMyExtension = lazy(() =>\n  import('.\u002Fextensions\u002FMyExtension').then(m => ({ default: m.MyExtension }))\n);\nfunction MyExtension(props: MyExtensionProps) {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CLazyMyExtension {...props} \u002F>\u003C\u002FSuspense>;\n}\n\nexport const plugin = new AppPlugin\u003CJsonData>().setRootPage(App);\nplugin.exposeComponent({ id: 'my-plugin\u002Fmy-extension\u002Fv1', title: 'My Extension', component: MyExtension });\n```\n\n**Key details:**\n- `import type` for props prevents webpack from following the import into the eager bundle\n- Use `new AppPlugin\u003CJsonData>()` if App uses `AppRootProps\u003CJsonData>` — without the generic, `setRootPage()` type won't match\n- Remove any `App as unknown as ComponentClass\u003CAppRootProps>` cast — the lazy wrapper is a valid function component\n\n**Expected impact:** `module.js` drops from MB range to ~50–200 KB.\n\n**Singletons (e.g. Faro):** If `module.ts` has `export const faro = initializeFaro()`, do NOT keep it as a top-level import. Extract it to `src\u002Ffaro.ts`, update all internal imports from `'*\u002Fmodule'` → `'*\u002Ffaro'`, then use the dynamic `initFaro()` pattern above.\n\n---\n\n### Priority 2: Route-based splitting in App.tsx\n\n```tsx\nimport React, { lazy, Suspense } from 'react';\nimport { Route, Routes } from 'react-router-dom';\nimport { LoadingPlaceholder } from '@grafana\u002Fui';\n\nconst HomePage     = lazy(() => import('..\u002Fpages\u002FHome'));\nconst SettingsPage = lazy(() => import('..\u002Fpages\u002FSettings'));\nconst DetailPage   = lazy(() => import('..\u002Fpages\u002FDetail'));\n\nfunction App(props: AppRootProps) {\n  return (\n    \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\n      \u003CRoutes>\n        \u003CRoute path=\"home\"       element={\u003CHomePage \u002F>} \u002F>\n        \u003CRoute path=\"settings\"   element={\u003CSettingsPage \u002F>} \u002F>\n        \u003CRoute path=\"detail\u002F:id\" element={\u003CDetailPage \u002F>} \u002F>\n        \u003CRoute path=\"\"           element={\u003CHomePage \u002F>} \u002F>\n      \u003C\u002FRoutes>\n    \u003C\u002FSuspense>\n  );\n}\nexport default App;\n```\n\n**Bypass barrel files:** Target the actual component file in the `import()`, not an `index.ts` barrel that re-exports multiple things:\n\n```tsx\n\u002F\u002F Risky — barrel may pull in other heavy modules\nconst Catalog = lazy(() => import('features\u002Fcatalog'));\n\u002F\u002F Better — only pulls in Catalog's tree\nconst Catalog = lazy(() => import('features\u002Fcatalog\u002FCatalog').then(m => ({ default: m.Catalog })));\n```\n\n### Priority 3: Extension components\n\nEach extension should `export default` its component. Use `fallback={null}` for extensions that load quickly:\n\n```tsx\n\u002F\u002F src\u002Fextensions\u002FMyExtension.tsx\nexport default function MyExtension(props: MyExtensionProps) {\n  return \u003CAppProviders>\u003CMyExtensionContent {...props} \u002F>\u003C\u002FAppProviders>;\n}\n```\n\n**Surgical split:** If an extension wrapper must stay eager in `module.tsx`, lazy-load the heavy component it renders:\n\n```tsx\nconst HeavyInner = lazy(() => import('components\u002Ffeatures\u002FHeavyInner'));\nexport function MyExtension() {\n  return \u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\u003CHeavyInner \u002F>\u003C\u002FSuspense>;\n}\n```\n\n### Priority 4: Component registries and tab panels\n\nFor arrays of objects containing React components (e.g. tab panels), lazy-load each entry. **Critical:** ensure a `\u003CSuspense>` boundary exists where the component renders.\n\n```tsx\nconst ConfigDetails = lazy(() => import('.\u002FConfigDetails\u002FConfigDetails').then(m => ({ default: m.ConfigDetails })));\nconst Overview      = lazy(() => import('.\u002FOverview\u002FOverview').then(m => ({ default: m.Overview })));\n\nconst tabs = [\n  { id: 'overview', component: Overview },\n  { id: 'config',   component: ConfigDetails },\n];\n\n\u002F\u002F In the parent that renders the active tab:\n\u003CSuspense fallback={\u003CLoadingPlaceholder text=\"\" \u002F>}>\n  {ActiveTab && \u003CActiveTab \u002F>}\n\u003C\u002FSuspense>\n```\n\nFor **datasource plugins** (`setConfigEditor`, `setQueryEditor`, `VariableSupport`, `AnnotationSupport`), see [references\u002Fdatasource-plugins.md](references\u002Fdatasource-plugins.md).\n\n---\n\n## Step 6: Group related chunks if over-splitting\n\nIf the build produces more than ~25 JS files, use webpack magic comments:\n\n```tsx\nconst FleetList   = lazy(() => import(\u002F* webpackChunkName: \"fleet\" *\u002F '..\u002Fpages\u002FFleetList'));\nconst FleetDetail = lazy(() => import(\u002F* webpackChunkName: \"fleet\" *\u002F '..\u002Fpages\u002FFleetDetail'));\n```\n\nOne `webpackChunkName` per logical feature area. Don't group unrelated pages.\n\n---\n\n## Step 7: Measure and verify\n\n```bash\nyarn build 2>\u002Fdev\u002Fnull || npm run build\necho \"=== module.js ===\" && ls -lah dist\u002Fmodule.js\necho \"=== all JS chunks (largest first) ===\" && ls -lah dist\u002F*.js | sort -k5 -rh | head -30\necho \"=== chunk count ===\" && ls dist\u002F*.js | wc -l\n```\n\n| Metric | Target |\n|---|---|\n| `module.js` size | \u003C 200 KB |\n| Total JS chunk count | 15–25 |\n| Largest single chunk | \u003C 1 MB |\n\n```bash\n# Analyse bundle composition if a chunk is unexpectedly large\nnpx webpack-bundle-analyzer dist\u002Fstats.json 2>\u002Fdev\u002Fnull\n```\n\n---\n\n## Step 8: Test the running plugin\n\n1. Open the plugin in a Grafana instance\n2. Navigate to **every route** — each triggers a new chunk download\n3. **DevTools → Network → JS**: confirm lazy chunks load on navigation, not all upfront\n4. Check **Console** for errors\n5. Test any `exposeComponent` extensions from other Grafana apps\n\nFor troubleshooting common issues, see [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md).\n\n---\n\n## References\n\n- [grafana-collector-app](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fgrafana-collector-app) — app plugin reference implementation\n- [grafana\u002Fplugin-actions](https:\u002F\u002Fgithub.com\u002Fgrafana\u002Fplugin-actions) — official Grafana plugin CI actions\n- [Web.dev — code splitting with lazy and Suspense](https:\u002F\u002Fweb.dev\u002Farticles\u002Fcode-splitting-suspense)\n- [SurviveJS — webpack code splitting](https:\u002F\u002Fsurvivejs.com\u002Fbooks\u002Fwebpack\u002Fbuilding\u002Fcode-splitting\u002F)\n- [webpack magic comments](https:\u002F\u002Fwebpack.js.org\u002Fapi\u002Fmodule-methods\u002F#magic-comments)\n",{"name":5,"license":15,"description":7},"master","49e49abf2f670d429e0b7e2c0349739c3fdd5cbe","skills\u002Fplugin-bundle-size",5,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium","https:\u002F\u002Fgithub.com\u002Fstanfish06","https:\u002F\u002Fwww.stanfish.dev\u002F","2026-11-14 21:31:37",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add stanfish06\u002Fskillquarium --skill plugin-bundle-size",{"tool":38,"command":39},"bunx","bunx skills add stanfish06\u002Fskillquarium --skill plugin-bundle-size",{"tool":41,"command":42},"pnpm","pnpm dlx skills add stanfish06\u002Fskillquarium --skill plugin-bundle-size","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fplugin-bundle-size\u002FSKILL.md",true,[46,52,56],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"agents\u002Fopenai.yaml","REFERENCE","参考文档",172,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fplugin-bundle-size\u002Fagents\u002Fopenai.yaml",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"references\u002Fdatasource-plugins.md",2453,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fplugin-bundle-size\u002Freferences\u002Fdatasource-plugins.md",{"path":57,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":58,"sourceHtmlUrl":59},"references\u002Ftroubleshooting.md",2830,"https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fplugin-bundle-size\u002Freferences\u002Ftroubleshooting.md",[61,69,77,84,91,98],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":65,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M76ZJTRVA456GD7K8Y3EP82H","zarr-python","Stores and queries chunked N-D scientific arrays with Zarr-Python 3, including codecs, sharding, S3\u002FGCS storage, and NumPy\u002FDask\u002FXarray integration. Use for array layout, bounded I\u002FO, format migration, or scientific metadata preservation.","MIT","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":73,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M76ZJQZ15Q1HKC5V85NHE325","yeet","Publish local changes to GitHub by confirming scope, committing intentionally, pushing the branch, and opening a draft PR through the GitHub app from this plugin, with `gh` used only as a fallback where connector coverage is insufficient.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fyeet\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M76ZJ8ASZ4QYQ70Y6SBA4Z4S","xarray","N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF\u002FGRIB\u002FZarr files, climate\u002Fweather\u002Foceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fxarray\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":65,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M76ZHFBXD6VXPQ02VCEG202B","writing-mstest-tests","Use when asked to fix, rewrite, update, improve, modernize, show corrected code for, or explain existing MSTest tests or MSTest-specific configuration. Use for \"review\" when corrected code or edits are wanted, even for one pasted assertion or passing tests with bad failure output. Covers expected\u002Factual labels; generic Boolean, collection, string, numeric, null, identity, exception, hard-cast, and object[] checks; TestContext\u002Flifecycle; timeout\u002Fcancellation; OS\u002FCI conditions, retry, cleanup, parallelization, MSTest.Sdk project setup, and MSTESTxxxx. Honor the installed MSTest version. DO NOT USE to design new test cases (code-testing), perform report-only audits, create project files rather than explain MSTest setup, run tests, migrate frameworks, or handle non-MSTest\u002Fnon-.NET code.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwriting-mstest-tests\u002FSKILL.md",[],[],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":65,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":19},"01M76ZDFDF4N88RH6HSYGS7GP2","wgs-prs","End-to-end WGS to polygenic risk score pipeline. Takes paired-end FASTQ files (or a pre-existing VCF) through nf-core\u002Fsarek for variant calling, applies VCF QC (normalisation, hard filtering, Ti\u002FTv and Het\u002FHom checks), then computes polygenic risk scores via the PGS Catalog. Fills the FASTQ to VCF gap upstream of the gwas-prs skill.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwgs-prs\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":102,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":19},"01M76ZCC1SC68J42QK4MDC8RCG","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fstanfish06\u002Fskillquarium\u002Fblob\u002Fmaster\u002Fskills\u002Fwebapp-testing\u002FSKILL.md",[],[]]