Skip to content

Commit 1c296cc

Browse files
committed
Improvements
1 parent 5f90b87 commit 1c296cc

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

CLAUDE.md

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
Microbundle is a zero-configuration bundler for tiny JavaScript libraries, powered by Rollup. It takes source code and produces multiple output formats (modern ES modules, CommonJS, UMD) with minimal setup.
88

9+
## Quick Reference
10+
11+
```bash
12+
npm run build # Full build (Babel + self-build)
13+
npm test # Lint + build + tests
14+
npm run jest # Tests only
15+
npm run lint # ESLint
16+
npm run format # Prettier
17+
npm run changeset # Create changelog entry
18+
npm run release # Publish (prepare + test + changeset publish)
19+
```
20+
921
## Development Commands
1022

1123
### Building
@@ -28,42 +40,12 @@ Microbundle is a zero-configuration bundler for tiny JavaScript libraries, power
2840

2941
### Changesets and Versioning
3042

31-
This project uses [@changesets/cli](https://github.com/changesets/changesets) to track notable changes and generate changelogs.
32-
33-
#### Creating a Changeset
34-
35-
When making a change that should be documented in the changelog:
36-
37-
```bash
38-
npm run changeset
39-
```
40-
41-
This will:
42-
43-
1. Prompt you to select the type of change (major, minor, or patch)
44-
2. Ask you to describe the change
45-
3. Create a markdown file in `.changeset/` with a randomly generated name
46-
47-
#### Changeset Configuration
48-
49-
- **Changelog Format**: Uses `@changesets/changelog-github` to generate GitHub-flavored changelogs
50-
- **Base Branch**: `master` (configured in .changeset/config.json:10)
51-
- **Access**: Public (for npm publishing)
52-
- **Commit Mode**: Changesets are not automatically committed (commit: false)
43+
This project uses [@changesets/cli](https://github.com/changesets/changesets) for changelog management.
5344

54-
#### Changeset File Format
55-
56-
Changeset files in `.changeset/` follow this format:
57-
58-
```markdown
59-
---
60-
"microbundle": patch
61-
---
62-
63-
Description of the change
64-
```
65-
66-
The version bump type can be: `major`, `minor`, or `patch`
45+
- `npm run changeset` - Create a new changeset (prompts for type: major/minor/patch)
46+
- `npm run release` - Full release: prepare + test + changeset publish
47+
- Base branch: `master`
48+
- Changesets are not auto-committed
6749

6850
### Running Tests
6951

@@ -74,6 +56,16 @@ npm run jest -- --testNamePattern="build shebang"
7456
npm run jest -- test/index.test.js
7557
```
7658

59+
## Code Style
60+
61+
This project uses Prettier with:
62+
- **Tabs** for indentation (not spaces)
63+
- **Single quotes** for strings
64+
- **Trailing commas** in multi-line structures
65+
- **No parens** around single arrow function parameters
66+
67+
ESLint extends `eslint-config-developit` with Prettier integration.
68+
7769
## Architecture
7870

7971
### Entry Points
@@ -84,24 +76,24 @@ npm run jest -- test/index.test.js
8476

8577
### Core Build Flow
8678

87-
1. **Input Resolution** (`getInput()` in src/index.js:205)
79+
1. **Input Resolution** (`getInput()` in src/index.js)
8880

8981
- Resolves entry files from CLI args, `source` field in package.json, or defaults (src/index.js, index.js)
9082
- Supports glob patterns for multiple entries
9183
- Handles TypeScript (.ts/.tsx) and JavaScript files
9284

93-
2. **Output Resolution** (`getOutput()` in src/index.js:227)
85+
2. **Output Resolution** (`getOutput()` in src/index.js)
9486

9587
- Determines output location from CLI args or package.json `main` field
9688
- Defaults to dist/ directory
9789

98-
3. **Format Generation** (`getMain()` in src/index.js:278)
90+
3. **Format Generation** (`getMain()` in src/index.js)
9991

10092
- Maps each format (modern, es, cjs, umd) to appropriate output filenames
10193
- Reads from package.json fields: `module`, `main`, `exports`, `unpkg`, etc.
10294
- Respects `{"type":"module"}` for ES Module packages
10395

104-
4. **Configuration Creation** (`createConfig()` in src/index.js:327)
96+
4. **Configuration Creation** (`createConfig()` in src/index.js)
10597

10698
- Creates Rollup configuration for each entry/format combination
10799
- Configures plugins: Babel, TypeScript, PostCSS, Terser, etc.
@@ -130,37 +122,35 @@ npm run jest -- test/index.test.js
130122
- **css-modules.js** - CSS Modules configuration logic
131123
- **compressed-size.js** - Calculates gzipped/brotli bundle sizes
132124
- **option-normalization.js** - Parses CLI arguments (--alias, --define, etc.)
125+
- **transform-fast-rest.js** - Babel plugin for optimized rest/spread transforms
126+
- **\_\_entry\_\_.js** - Entry point wrapper for worker builds
133127

134128
**test/fixtures/** - Integration test fixtures (each subdirectory is a test case with package.json and source)
135129

136130
### External Dependencies Handling
137131

138-
- **Externals** (src/index.js:331-357): By default, `dependencies` and `peerDependencies` are external (not bundled)
139-
- **Bundled**: `devDependencies` are bundled into the output
132+
- By default, `dependencies` and `peerDependencies` are external (not bundled)
133+
- `devDependencies` are bundled into the output
140134
- Override with `--external` flag or `--external none` to bundle everything
141135

142136
### Special Features
143137

144-
**TypeScript Support** (src/index.js:533-564):
145-
138+
**TypeScript Support:**
146139
- Automatically detected by .ts/.tsx file extension
147140
- Uses rollup-plugin-typescript2
148141
- Generates declaration files when `types` or `typings` is set in package.json
149142
- Respects tsconfig.json with overrides for `module: "ESNext"` and `target: "esnext"`
150143

151-
**CSS Handling** (src/index.js:490-502):
152-
144+
**CSS Handling:**
153145
- PostCSS with autoprefixer
154146
- CSS Modules support (files ending in .module.css or via --css-modules flag)
155147
- Output modes: external (default) or inline
156148

157-
**Property Mangling** (src/index.js:385-433):
158-
149+
**Property Mangling:**
159150
- Reads from `mangle.json` or package.json `mangle`/`minify` field
160151
- Name cache persisted across builds for consistent output
161152

162-
**Worker Support** (src/index.js:648):
163-
153+
**Worker Support:**
164154
- Bundles Web Workers via @surma/rollup-plugin-off-main-thread
165155
- Only works with es/modern formats
166156
- Enable with --workers flag
@@ -182,17 +172,17 @@ npm run jest -- test/index.test.js
182172

183173
### Adding Rollup Plugins
184174

185-
Add to the plugins array in src/index.js:488-701, typically with conditional logic and `.filter(Boolean)` to remove falsy entries
175+
Add to the plugins array in `createConfig()` in src/index.js, typically with conditional logic and `.filter(Boolean)` to remove falsy entries.
186176

187177
### Debugging Builds
188178

189179
- Use `--no-compress` to disable minification
190-
- Check rollup warnings in `onwarn` handler (src/index.js:469-482)
191-
- Modern format disables Rollup cache (src/index.js:437) to prevent legacy transpilation leaking
180+
- Check rollup warnings in `onwarn` handler in src/index.js
181+
- Modern format disables Rollup cache to prevent legacy transpilation leaking
192182

193183
## Important Notes
194184

195185
- The build is "self-hosted": microbundle builds itself (see build:self script)
196-
- CJS format always builds first to populate cache for other formats (src/index.js:109)
186+
- CJS format always builds first to populate cache for other formats
197187
- Modern format uses Babel's bugfixes mode to target browsers with `<script type="module">` support
198-
- Shebang lines are extracted and re-added to preserve them (src/index.js:524-531, 712-713)
188+
- Shebang lines are extracted and re-added to preserve them in CLI scripts

0 commit comments

Comments
 (0)