Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问clear审计通过

bun-buildBun 构建

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

984

周安装

41

GitHub Stars

3

下载量

328
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:bun-build(Bun 构建)
来源仓库:https://github.com/daleseo/bun-skills
仓库路径:skills/bun-build
安装命令:
npx skills add https://github.com/daleseo/bun-skills --skill bun-build
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/daleseo/bun-skills --skill bun-build

简介

用于配置 Bun 的原生生产环境打包方案。

  • 无需 Webpack 或 esbuild,直接使用 Bun bundler。
  • 支持浏览器、Node.js 和库等多种构建目标。
  • 包含 tree-shaking、代码分割和分析工具集成。
  • 需根据项目类型选择合适的目标和优化策略。bun-build 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Bun Production Build Configuration

Set up production builds using Bun's native bundler - fast, optimized bundle creation without webpack or esbuild.

Quick Reference

For detailed patterns, see:

  • Build Targets: targets.md - Browser, Node.js, library, CLI configurations
  • Optimization: optimization.md - Tree shaking, code splitting, analysis
  • Plugins: plugins.md - Custom loaders and transformations

Core Workflow

1. Check Prerequisites

# Verify Bun installation
bun --version

# Check project structure
ls -la package.json src/

2. Determine Build Requirements

Ask the user about their build needs:

  • Application Type: Frontend SPA, Node.js backend, CLI tool, or library
  • Target Platform: Browser, Node.js, Bun runtime, or Cloudflare Workers
  • Output Format: ESM (modern), CommonJS (legacy), or both

3. Create Basic Build Script

Create build.ts in project root:

#!/usr/bin/env bun

const result = await Bun.build({
  entrypoints: ['./src/index.ts'],
  outdir: './dist',
  target: 'browser', // or 'node', 'bun'
  format: 'esm', // or 'cjs', 'iife'
  minify: true,
  splitting: true,
  sourcemap: 'external',
});

if (!result.success) {
  console.error('Build failed');
  for (const message of result.logs) {
    console.error(message);
  }
  process.exit(1);
}

console.log('✅ Build successful');
console.log(`📦 ${result.outputs.length} files generated`);

// Show bundle sizes
for (const output of result.outputs) {
  const size = (output.size / 1024).toFixed(2);
  console.log(`  ${output.path} - ${size} KB`);
}

4. Configure for Target Platform

For Browser/Frontend:

await Bun.build({
  entrypoints: ['./src/index.tsx'],
  outdir: './dist',
  target: 'browser',
  format: 'esm',
  minify: true,
  splitting: true,
  define: {
    'process.env.NODE_ENV': '"production"',
  },
  loader: {
    '.png': 'file',
    '.svg': 'dataurl',
    '.css': 'css',
  },
});

For Node.js Backend:

await Bun.build({
  entrypoints: ['./src/server.ts'],
  outdir: './dist',
  target: 'node',
  format: 'esm',
  minify: true,
  external: ['*'], // Don't bundle node_modules
});

For libraries, CLI tools, and other targets, see targets.md.

5. Add Production Optimizations

await Bun.build({
  entrypoints: ['./src/index.ts'],
  outdir: './dist',
  target: 'browser',

  // Maximum minification
  minify: {
    whitespace: true,
    identifiers: true,
    syntax: true,
  },

  // Code splitting for optimal caching
  splitting: true,

  // Content hashing for cache busting
  naming: {
    entry: '[dir]/[name].[hash].[ext]',
    chunk: 'chunks/[name].[hash].[ext]',
    asset: 'assets/[name].[hash].[ext]',
  },

  // Source maps for debugging
  sourcemap: 'external',
});

For advanced optimizations (tree shaking, bundle analysis, size limits), see optimization.md.

6. Environment-Specific Builds

Create build-env.ts:

#!/usr/bin/env bun

const env = process.env.NODE_ENV || 'development';

const configs = {
  development: {
    minify: false,
    sourcemap: 'inline',
    define: {
      'process.env.NODE_ENV': '"development"',
      'process.env.API_URL': '"http://localhost:3000"',
    },
  },
  production: {
    minify: true,
    sourcemap: 'external',
    define: {
      'process.env.NODE_ENV': '"production"',
      'process.env.API_URL': '"https://api.example.com"',
    },
  },
};

const config = configs[env as keyof typeof configs];

const result = await Bun.build({
  entrypoints: ['./src/index.ts'],
  outdir: './dist',
  target: 'browser',
  format: 'esm',
  splitting: true,
  ...config,
});

if (!result.success) {
  console.error('❌ Build failed');
  process.exit(1);
}

console.log(`✅ ${env} build successful`);

Run with:

NODE_ENV=production bun run build-env.ts

7. Update package.json

Add build scripts:

{
  "scripts": {
    "build": "bun run build.ts",
    "build:dev": "NODE_ENV=development bun run build-env.ts",
    "build:prod": "NODE_ENV=production bun run build-env.ts",
    "build:watch": "bun run build.ts --watch",
    "clean": "rm -rf dist"
  }
}

For libraries, also add:

{
  "type": "module",
  "main": "./dist/cjs/index.js",
  "module": "./dist/esm/index.js",
  "types": "./dist/esm/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js",
      "types": "./dist/esm/index.d.ts"
    }
  },
  "files": ["dist"]
}

8. Generate Type Declarations (Libraries)

For libraries, generate TypeScript declarations:

// build-lib-with-types.ts
import { $ } from 'bun';

// Build JavaScript
await Bun.build({
  entrypoints: ['./src/index.ts'],
  outdir: './dist',
  target: 'node',
  format: 'esm',
  minify: true,
});

// Generate type declarations
await $`bunx tsc --declaration --emitDeclarationOnly --outDir dist`;

console.log('✅ Built library with type declarations');

Build Options Reference

Target

  • browser: For web applications (includes browser globals)
  • node: For Node.js applications (assumes Node.js APIs)
  • bun: For Bun runtime (optimized for Bun-specific features)

Format

  • esm: ES Modules (modern, tree-shakeable) - Recommended
  • cjs: CommonJS (legacy Node.js)
  • iife: Immediately Invoked Function Expression (browser scripts)

Minification

minify: true                  // Basic minification
minify: {                     // Granular control
  whitespace: true,
  identifiers: true,
  syntax: true,
}

Source Maps

  • external: Separate.map files (production)
  • inline: Inline in bundle (development)
  • none: No source maps

Verification

After building:

# 1. Check output directory
ls -lh dist/

# 2. Verify bundle size
du -sh dist/*

# 3. Test bundle
bun run dist/index.js

# 4. Check for errors
echo $?  # Should be 0

Common Build Patterns

Watch mode for development:

import { watch } from 'fs';

async function build() {
  await Bun.build({
    entrypoints: ['./src/index.ts'],
    outdir: './dist',
    minify: false,
  });
}

await build();

watch('./src', { recursive: true }, async (event, filename) => {
  if (filename?.endsWith('.ts')) {
    console.log(`Rebuilding...`);
    await build();
  }
});

Custom asset loaders:

loader: {
  '.png': 'file',     // Copy file, return path
  '.svg': 'dataurl',  // Inline as data URL
  '.txt': 'text',     // Inline as string
  '.json': 'json',    // Parse and inline
}

For custom plugins and advanced transformations, see plugins.md.

Troubleshooting

Build fails:

if (!result.success) {
  for (const log of result.logs) {
    console.error(log);
  }
}

Bundle too large: See optimization.md for:

  • Bundle analysis
  • Code splitting
  • Tree shaking
  • Size limits

Module not found: Check external configuration:

external: ['*']         // Exclude all node_modules
external: ['react']     // Exclude specific packages
external: []            // Bundle everything

Completion Checklist

  • ✅ Build script created
  • ✅ Target platform configured
  • ✅ Minification enabled
  • ✅ Source maps configured
  • ✅ Environment-specific builds set up
  • ✅ Package.json scripts added
  • ✅ Build tested successfully
  • ✅ Bundle size verified

Next Steps

After basic build setup:

  1. Optimization: Add bundle analysis and size limits
  2. CI/CD: Automate builds in your pipeline
  3. Type Checking: Add pre-build type checking
  4. Testing: Run tests before building
  5. Deployment: Integrate with bun-deploy for containerization

For detailed implementations, see the reference files linked above.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

32.68%
按下载量换算107

Cursor

22.88%
按下载量换算75

Gemini CLI

19.98%
按下载量换算66

OpenCode

12.19%
按下载量换算40

Codex

7.45%
按下载量换算24

github-copilot

3.72%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills