Size Limit preset for small open source libraries that combines esbuild and file plugins to track bundle sizes
npx @tessl/cli install tessl/npm-size-limit--preset-small-lib@11.2.00
# @size-limit/preset-small-lib
1
2
@size-limit/preset-small-lib is a Size Limit preset for small open source libraries. It provides a preconfigured setup that combines esbuild and file plugins to efficiently track the size of all files and dependencies in JavaScript libraries, enabling developers to automatically monitor and control bundle sizes in their CI pipelines.
3
4
## Package Information
5
6
- **Package Name**: @size-limit/preset-small-lib
7
- **Package Type**: npm
8
- **Language**: JavaScript (ES modules)
9
- **Module Type**: ES module (type: "module")
10
- **Installation**: `npm install --save-dev size-limit @size-limit/preset-small-lib`
11
12
## Core Imports
13
14
Size Limit automatically loads this preset when installed. For advanced use cases where you need to import the preset directly:
15
16
```javascript
17
import preset from "@size-limit/preset-small-lib";
18
```
19
20
For CommonJS environments:
21
22
```javascript
23
const preset = require("@size-limit/preset-small-lib").default;
24
```
25
26
## Basic Usage
27
28
The preset is automatically loaded by Size Limit when installed. Configure it in your package.json:
29
30
```json
31
{
32
"size-limit": [
33
{
34
"path": "index.js"
35
}
36
],
37
"scripts": {
38
"size": "size-limit"
39
}
40
}
41
```
42
43
Run the size check:
44
45
```bash
46
npm run size
47
```
48
49
When using this preset, Size Limit will automatically:
50
1. Bundle your library using esbuild
51
2. Calculate the actual file size including all dependencies and polyfills
52
3. Support multiple compression methods (none, gzip, brotli)
53
4. Provide accurate size measurements optimized for small libraries
54
55
## Architecture
56
57
This preset is built on Size Limit's plugin architecture and combines two essential plugins:
58
59
- **@size-limit/esbuild**: Handles JavaScript bundling using esbuild with optimized configurations
60
- **@size-limit/file**: Calculates actual file sizes with compression support (gzip, brotli)
61
62
The preset integrates with Size Limit's step-based processing system where plugins execute in numbered phases (step20, step40, step60, step61) to build, measure, and adjust size calculations.
63
64
## Capabilities
65
66
### Preset Configuration
67
68
The main export that provides the combined plugin configuration for Size Limit.
69
70
```javascript { .api }
71
/**
72
* Default export containing the preset configuration
73
* Combines @size-limit/esbuild and @size-limit/file plugins
74
*/
75
declare const preset: SizeLimitPlugin[];
76
77
export default preset;
78
```
79
80
### Plugin Components
81
82
This preset internally combines the following Size Limit plugins:
83
84
The preset combines plugins that handle different phases of Size Limit's processing:
85
86
- **@size-limit/esbuild**: Handles JavaScript bundling using esbuild with optimized configurations
87
- **@size-limit/file**: Calculates actual file sizes with compression support (gzip, brotli)
88
89
Each plugin implements various processing steps (step20, step40, step60, step61) in Size Limit's execution pipeline.
90
91
## Types
92
93
```javascript { .api }
94
/**
95
* The preset exports an array of Size Limit plugins
96
*/
97
type PresetExport = SizeLimitPlugin[];
98
99
interface SizeLimitPlugin {
100
name: string;
101
before?(config: object): Promise<void>;
102
finally?(config: object, check: object): Promise<void>;
103
step20?(config: object, check: object): Promise<void>;
104
step40?(config: object, check: object): Promise<void>;
105
step60?(config: object, check: object): Promise<void>;
106
step61?(config: object, check: object): Promise<void>;
107
wait40?: string;
108
}
109
```
110
111
## Dependencies
112
113
This preset has the following dependencies:
114
115
**Peer Dependencies:**
116
- **size-limit**: 11.2.0 (the core Size Limit framework)
117
118
**Direct Dependencies:**
119
- **@size-limit/esbuild**: 11.2.0 (esbuild bundling functionality)
120
- **@size-limit/file**: 11.2.0 (file size calculation)
121
- **size-limit**: 11.2.0 (also included as direct dependency)
122
123
## Use Cases
124
125
This preset is ideal for:
126
127
- **Small npm libraries** that need accurate size tracking
128
- **Open source libraries** requiring CI-based size monitoring
129
- **Performance-critical packages** where bundle size matters for end-users
130
- **Libraries with dependencies** that need comprehensive size calculation including polyfills
131
- **Projects using modern build tools** that benefit from esbuild's fast bundling