rollup-bundler
Rollup.jsによるモジュールバンドルの設定、ESモジュールの取り扱い、およびライブラリのバンドルに関するベストプラクティスとガイドラインを提供します。設定ファイルの最適化やプラグインの活用方法など、Rollup.jsを効果的に使いこなすための知識をサポートします。
description の原文を見る
Best practices and guidelines for Rollup.js module bundler configuration, ES modules, and library bundling
SKILL.md 本文
Rollup Bundler
あなたは Rollup.js の専門家です。Rollup.js は ES modules に最適化された JavaScript モジュールバンドラです。Rollup の設定を操作する際は、以下のガイドラインに従ってください。
Core Principles
- Rollup は ES modules 向けに設計されており、より小さくクリーンなバンドルを生成します
- 深い実行パス分析による優れた tree-shaking
- 他のプロジェクトで使用されるライブラリとパッケージに最適
- 効率的で読みやすい出力コードを作成することに焦点を当てる
Project Structure
project/
├── src/
│ ├── index.js # Main entry point
│ ├── modules/ # Internal modules
│ └── utils/ # Utility functions
├── dist/ # Build output
│ ├── bundle.esm.js # ES module format
│ ├── bundle.cjs.js # CommonJS format
│ └── bundle.umd.js # UMD format
├── rollup.config.mjs # Configuration file
└── package.json
Configuration Basics
Basic Configuration
// rollup.config.mjs
export default {
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'esm',
sourcemap: true
}
};
Multiple Output Formats
export default {
input: 'src/index.js',
output: [
{
file: 'dist/bundle.esm.js',
format: 'esm',
sourcemap: true
},
{
file: 'dist/bundle.cjs.js',
format: 'cjs',
sourcemap: true
},
{
file: 'dist/bundle.umd.js',
format: 'umd',
name: 'MyLibrary',
sourcemap: true
}
]
};
Output Formats
ES Modules (esm)
- バンドルを ES module ファイルとして保持
- モダンなバンドラとブラウザに最適
- 使用するプロジェクトの tree-shaking をサポート
CommonJS (cjs)
- Node.js 環境向け
- require() 構文と互換性
UMD (Universal Module Definition)
- AMD、CJS、IIFE として動作
- 広い互換性が必要なライブラリに最適
IIFE (Immediately Invoked Function Expression)
- 自己実行関数
- ブラウザの script タグに適している
ES Modules Best Practices
Use Named Exports
// Prefer named exports for better tree-shaking
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;
// Avoid default exports when possible
// export default { add, subtract }; // Less tree-shakeable
Static Imports
// Static imports enable tree-shaking
import { specificFunction } from './utils';
// Avoid dynamic requires in library code
// const utils = require('./utils'); // CommonJS - no tree-shaking
Essential Plugins
Node Resolve
import resolve from '@rollup/plugin-node-resolve';
export default {
plugins: [
resolve({
browser: true,
preferBuiltins: false
})
]
};
CommonJS Conversion
import commonjs from '@rollup/plugin-commonjs';
export default {
plugins: [
commonjs()
]
};
Babel Transpilation
import babel from '@rollup/plugin-babel';
export default {
plugins: [
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-env']
})
]
};
TypeScript Support
import typescript from '@rollup/plugin-typescript';
export default {
input: 'src/index.ts',
plugins: [
typescript({
tsconfig: './tsconfig.json'
})
]
};
Minification
import terser from '@rollup/plugin-terser';
export default {
plugins: [
terser()
]
};
Environment Variables
import replace from '@rollup/plugin-replace';
export default {
plugins: [
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production')
})
]
};
External Dependencies
Marking Dependencies as External
export default {
input: 'src/index.js',
external: ['react', 'react-dom', 'lodash'],
output: {
file: 'dist/bundle.js',
format: 'esm',
globals: {
react: 'React',
'react-dom': 'ReactDOM'
}
}
};
Peer Dependencies Pattern
import pkg from './package.json';
export default {
external: [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {})
]
};
Code Splitting
Multiple Entry Points
export default {
input: {
main: 'src/index.js',
utils: 'src/utils/index.js'
},
output: {
dir: 'dist',
format: 'esm'
}
};
Dynamic Imports
// Rollup handles dynamic imports automatically
async function loadModule() {
const module = await import('./heavy-module.js');
return module.default;
}
Tree Shaking Optimization
Pure Function Annotations
// Mark functions as pure for better tree-shaking
export const compute = /*#__PURE__*/ createCompute();
Side Effects Configuration
{
"name": "my-library",
"sideEffects": false
}
Watch Mode
// rollup.config.mjs
export default {
watch: {
include: 'src/**',
clearScreen: false
}
};
コマンドラインでの実行:
rollup -c -w
Package.json Configuration
{
"name": "my-library",
"version": "1.0.0",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
"browser": "dist/bundle.umd.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/bundle.esm.js",
"require": "./dist/bundle.cjs.js"
}
},
"files": ["dist"],
"sideEffects": false
}
Best Practices
すべき こと
- ES6 モジュール構文を一貫して使用する
- サードパーティ製の依存関係を external にマークする
- デバッグ用にソースマップを生成する
- tree-shaking を向上させるために named exports を使用する
- すべての出力形式をテストする
- 開発中は watch mode を使用する
すべきではない こと
- ピア依存関係をバンドルする
- ES modules が利用可能な場合に CommonJS モジュールを使用する
- バンドルサイズを無視する
- ライブラリの TypeScript 宣言ファイルをスキップする
Common Configuration Patterns
Library Configuration
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import pkg from './package.json';
export default {
input: 'src/index.ts',
external: Object.keys(pkg.peerDependencies || {}),
plugins: [
resolve(),
commonjs(),
typescript({ tsconfig: './tsconfig.json' }),
terser()
],
output: [
{ file: pkg.main, format: 'cjs', sourcemap: true },
{ file: pkg.module, format: 'esm', sourcemap: true }
]
};
Debugging and Analysis
- 設定のデバッグに
--configDebugフラグを使用する - すべての形式でソースマップを生成する
- バンドル分析に rollup-plugin-visualizer を使用する
- 出力コードの可読性を確認する
ライセンス: Apache-2.0(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- mindrally
- リポジトリ
- mindrally/skills
- ライセンス
- Apache-2.0
- 最終更新
- 不明
Source: https://github.com/mindrally/skills / ライセンス: Apache-2.0
関連スキル
superfluid
Superfluidプロトコルおよびそのエコシステムに関するナレッジベースです。Superfluidについて情報を検索する際は、ウェブ検索の前にこちらを参照してください。対応キーワード:Superfluid、CFA、GDA、Super App、Super Token、stream、flow rate、real-time balance、pool(member/distributor)、IDA、sentinels、liquidation、TOGA、@sfpro/sdk、semantic money、yellowpaper、whitepaper
civ-finish-quotes
実質的なタスクが真に完了した際に、文明風の儀式的な引用句を追加します。ユーザーやエージェントが機能追加、リファクタリング、分析、設計ドキュメント、プロセス改善、レポート、執筆タスクといった実際の成果物を完成させるときに、明示的な依頼がなくても使用します。短い返信や小さな修正、未完成の作業には適用しません。
nookplot
Base(Ethereum L2)上のAIエージェント向け分散型調整ネットワークです。エージェントがオンチェーンアイデンティティを登録する、コンテンツを公開する、他のエージェントにメッセージを送る、マーケットプレイスで専門家を雇う、バウンティを投稿・請求する、レピュテーションを構築する、共有プロジェクトで協業する、リサーチチャレンジを解くことでNOOKをマイニングする、キュレーションされたナレッジを備えたスタンドアロンオンチェーンエージェントをデプロイする、またはアグリーメントとリワードで収益を得る場合に利用できます。エージェントネットワーク、エージェント調整、分散型エージェント、NOOKトークン、マイニングチャレンジ、ナレッジバンドル、エージェントレピュテーション、エージェントマーケットプレイス、ERC-2771メタトランザクション、Prepare-Sign-Relay、AgentFactory、またはNookplotが言及された場合にトリガーされます。
web3-polymarket
Polygon上でのPolymarket予測市場取引統合です。認証機能(L1 EIP-712、L2 HMAC-SHA256、ビルダーヘッダー)、注文発注(GTC/GTD/FOK/FAK、バッチ、ポストオンリー、ハートビート)、市場データ(Gamma API、Data API、オーダーブック、サブグラフ)、WebSocketストリーミング(市場・ユーザー・スポーツチャネル)、CTF操作(分割、統合、償却、ネガティブリスク)、ブリッジ機能(入金、出金、マルチチェーン)、およびガスレスリレイトランザクションに対応しています。AIエージェント、自動マーケットメーカー、予測市場UI、またはPolygraph上のPolymarketと統合するアプリケーション構築時に活用できます。
ethskills
Ethereum、EVM、またはブロックチェーン関連のリクエストに対応します。スマートコントラクト、dApps、ウォレット、DeFiプロトコルの構築、監査、デプロイ、インタラクションに適用されます。Solidityの開発、コントラクトアドレス、トークン規格(ERC-20、ERC-721、ERC-4626など)、Layer 2ネットワーク(Base、Arbitrum、Optimism、zkSync、Polygon)、Uniswap、Aave、Curveなどのプロトコルとの統合をカバーします。ガスコスト、コントラクトのデシマル設定、オラクルセキュリティ、リエントランシー、MEV、ブリッジング、ウォレット管理、オンチェーンデータの取得、本番環境へのデプロイ、プロトコル進化(EIPライフサイクル、フォーク追跡、今後の変更予定)といったトピックを含みます。
xxyy-trade
このスキルは、ユーザーが「トークン購入」「トークン売却」「トークンスワップ」「暗号資産取引」「取引ステータス確認」「トランザクション照会」「トークンスキャン」「フィード」「チェーン監視」「トークン照会」「トークン詳細」「トークン安全性確認」「ウォレット一覧表示」「マイウォレット」「AIスキャン」「自動スキャン」「ツイートスキャン」「オンボーディング」「IP確認」「IPホワイトリスト」「トークン発行」「自動売却」「損切り」「利益確定」「トレーリングストップ」「保有者」「トップホルダー」「KOLホルダー」などをリクエストした場合、またはSolana/ETH/BSC/BaseチェーンでXXYYを経由した取引について言及した場合に使用します。XXYY Open APIを通じてオンチェーン取引とデータ照会を実現します。