@jmlweb/tsup-config-base 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # @jmlweb/tsup-config-base
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@jmlweb/tsup-config-base)](https://www.npmjs.com/package/@jmlweb/tsup-config-base)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18.0.0-339933.svg)](https://nodejs.org/)
6
+ [![tsup](https://img.shields.io/badge/tsup-8.0%2B-yellow.svg)](https://tsup.egoist.dev/)
7
+
8
+ > Base tsup configuration for jmlweb projects. Provides sensible defaults and a clean API for creating consistent build configurations.
9
+
10
+ ## Features
11
+
12
+ - **Sensible Defaults**: Pre-configured with common settings for TypeScript libraries
13
+ - **Dual Format**: Generates both CommonJS and ESM outputs by default
14
+ - **TypeScript Declarations**: Automatic `.d.ts` generation enabled
15
+ - **Clean API**: Simple function to create configurations with external dependencies
16
+ - **Zero Config**: Works out of the box with minimal setup
17
+ - **Fully Typed**: Complete TypeScript support with exported types
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install --save-dev @jmlweb/tsup-config-base tsup
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ Create a `tsup.config.ts` file in your project root:
28
+
29
+ ```typescript
30
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
31
+
32
+ export default createTsupConfig();
33
+ ```
34
+
35
+ ## Examples
36
+
37
+ ### Basic Setup (No Externals)
38
+
39
+ ```typescript
40
+ // tsup.config.ts
41
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
42
+
43
+ export default createTsupConfig();
44
+ ```
45
+
46
+ ### With External Dependencies
47
+
48
+ ```typescript
49
+ // tsup.config.ts
50
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
51
+
52
+ export default createTsupConfig({
53
+ external: ['eslint', 'typescript-eslint', '@eslint/js'],
54
+ });
55
+ ```
56
+
57
+ ### With Internal Workspace Dependencies
58
+
59
+ ```typescript
60
+ // tsup.config.ts
61
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
62
+
63
+ export default createTsupConfig({
64
+ external: [
65
+ // Internal packages
66
+ '@jmlweb/eslint-config-base-js',
67
+ // External peer dependencies
68
+ '@eslint/js',
69
+ 'eslint',
70
+ 'eslint-config-prettier',
71
+ 'typescript-eslint',
72
+ ],
73
+ });
74
+ ```
75
+
76
+ ### Custom Entry Point
77
+
78
+ ```typescript
79
+ // tsup.config.ts
80
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
81
+
82
+ export default createTsupConfig({
83
+ entry: ['src/main.ts'],
84
+ external: ['some-dependency'],
85
+ });
86
+ ```
87
+
88
+ ### With Additional Options
89
+
90
+ ```typescript
91
+ // tsup.config.ts
92
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
93
+
94
+ export default createTsupConfig({
95
+ external: ['vitest'],
96
+ options: {
97
+ minify: true,
98
+ sourcemap: true,
99
+ splitting: true,
100
+ },
101
+ });
102
+ ```
103
+
104
+ ### Multiple Entry Points
105
+
106
+ ```typescript
107
+ // tsup.config.ts
108
+ import { createTsupConfig } from '@jmlweb/tsup-config-base';
109
+
110
+ export default createTsupConfig({
111
+ entry: ['src/index.ts', 'src/cli.ts'],
112
+ external: ['commander'],
113
+ });
114
+ ```
115
+
116
+ ## Configuration Details
117
+
118
+ ### Default Settings
119
+
120
+ | Setting | Default Value | Description |
121
+ | ---------- | ------------------ | ----------------------------------- |
122
+ | `entry` | `['src/index.ts']` | Entry point(s) for the build |
123
+ | `format` | `['cjs', 'esm']` | Output formats (dual publishing) |
124
+ | `dts` | `true` | Generate TypeScript declarations |
125
+ | `clean` | `true` | Clean output directory before build |
126
+ | `outDir` | `'dist'` | Output directory |
127
+ | `external` | `[]` | External packages to exclude |
128
+
129
+ ### API Reference
130
+
131
+ #### `createTsupConfig(options?: TsupConfigOptions): Options`
132
+
133
+ Creates a tsup configuration with sensible defaults.
134
+
135
+ **Parameters:**
136
+
137
+ | Option | Type | Default | Description |
138
+ | ---------- | ------------------------------ | ------------------ | -------------------------------- |
139
+ | `entry` | `string[]` | `['src/index.ts']` | Entry point files |
140
+ | `format` | `('cjs' \| 'esm' \| 'iife')[]` | `['cjs', 'esm']` | Output formats |
141
+ | `dts` | `boolean` | `true` | Generate declaration files |
142
+ | `clean` | `boolean` | `true` | Clean output before build |
143
+ | `outDir` | `string` | `'dist'` | Output directory |
144
+ | `external` | `(string \| RegExp)[]` | `[]` | Packages to exclude from bundle |
145
+ | `options` | `Partial<Options>` | `{}` | Additional tsup options to merge |
146
+
147
+ **Returns:** A complete tsup `Options` object.
148
+
149
+ #### `BASE_DEFAULTS`
150
+
151
+ Exported constant containing the default configuration values for reference.
152
+
153
+ #### `Options` (re-exported from tsup)
154
+
155
+ The tsup Options type is re-exported for convenience when extending configurations.
156
+
157
+ ## When to Use
158
+
159
+ Use this configuration when you want:
160
+
161
+ - Consistent build configuration across multiple packages
162
+ - Dual-format output (CommonJS + ESM) for maximum compatibility
163
+ - Automatic TypeScript declaration generation
164
+ - A clean, simple API for specifying externals
165
+ - Easy customization without repeating boilerplate
166
+
167
+ ## Externals Strategy
168
+
169
+ When configuring `external`, include:
170
+
171
+ 1. **Peer dependencies**: Packages that consumers should install themselves
172
+ 2. **Workspace dependencies**: Internal `@jmlweb/*` packages used via `workspace:*`
173
+ 3. **Optional dependencies**: Packages that may or may not be present
174
+
175
+ ```typescript
176
+ // Example: ESLint config package
177
+ export default createTsupConfig({
178
+ external: [
179
+ // Internal workspace dependency
180
+ '@jmlweb/eslint-config-base-js',
181
+ // Peer dependencies
182
+ '@eslint/js',
183
+ 'eslint',
184
+ 'eslint-config-prettier',
185
+ 'eslint-plugin-simple-import-sort',
186
+ 'typescript-eslint',
187
+ ],
188
+ });
189
+ ```
190
+
191
+ ## Usage with Scripts
192
+
193
+ Add build scripts to your `package.json`:
194
+
195
+ ```json
196
+ {
197
+ "scripts": {
198
+ "build": "tsup",
199
+ "clean": "rm -rf dist",
200
+ "prepublishOnly": "pnpm build"
201
+ }
202
+ }
203
+ ```
204
+
205
+ Then run:
206
+
207
+ ```bash
208
+ npm run build # Build the package
209
+ npm run clean # Clean build output
210
+ ```
211
+
212
+ ## Requirements
213
+
214
+ - **Node.js** >= 18.0.0
215
+ - **tsup** >= 8.0.0
216
+
217
+ ## Peer Dependencies
218
+
219
+ This package requires the following peer dependency:
220
+
221
+ - `tsup` (>=8.0.0)
222
+
223
+ ## Related Packages
224
+
225
+ - [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint config for TypeScript projects
226
+ - [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
227
+ - [`@jmlweb/tsconfig-base`](../tsconfig-base) - TypeScript configuration
228
+ - [`@jmlweb/vitest-config`](../vitest-config) - Vitest configuration for testing
229
+
230
+ ## License
231
+
232
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BASE_DEFAULTS: () => BASE_DEFAULTS,
24
+ createTsupConfig: () => createTsupConfig
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var BASE_DEFAULTS = {
28
+ entry: ["src/index.ts"],
29
+ format: ["cjs", "esm"],
30
+ dts: true,
31
+ clean: true,
32
+ outDir: "dist"
33
+ };
34
+ var createTsupConfig = (config = {}) => {
35
+ const {
36
+ entry = BASE_DEFAULTS.entry,
37
+ format = BASE_DEFAULTS.format,
38
+ dts = BASE_DEFAULTS.dts,
39
+ clean = BASE_DEFAULTS.clean,
40
+ outDir = BASE_DEFAULTS.outDir,
41
+ external = [],
42
+ options = {}
43
+ } = config;
44
+ return {
45
+ entry,
46
+ format,
47
+ dts,
48
+ clean,
49
+ outDir,
50
+ ...external.length > 0 && { external },
51
+ ...options
52
+ };
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ BASE_DEFAULTS,
57
+ createTsupConfig
58
+ });
@@ -0,0 +1,88 @@
1
+ import { Options } from 'tsup';
2
+ export { Options } from 'tsup';
3
+
4
+ /**
5
+ * Options for creating a base tsup configuration
6
+ */
7
+ interface TsupConfigOptions {
8
+ /**
9
+ * Entry points for the build
10
+ * @default ['src/index.ts']
11
+ */
12
+ entry?: string[];
13
+ /**
14
+ * Output formats
15
+ * @default ['cjs', 'esm']
16
+ */
17
+ format?: ('cjs' | 'esm' | 'iife')[];
18
+ /**
19
+ * Generate TypeScript declaration files
20
+ * @default true
21
+ */
22
+ dts?: boolean;
23
+ /**
24
+ * Clean output directory before build
25
+ * @default true
26
+ */
27
+ clean?: boolean;
28
+ /**
29
+ * Output directory
30
+ * @default 'dist'
31
+ */
32
+ outDir?: string;
33
+ /**
34
+ * External packages to exclude from the bundle
35
+ * Typically includes peer dependencies and internal workspace packages
36
+ * @default []
37
+ */
38
+ external?: (string | RegExp)[];
39
+ /**
40
+ * Additional tsup options to merge with the base configuration
41
+ */
42
+ options?: Omit<Options, 'entry' | 'format' | 'dts' | 'clean' | 'outDir' | 'external'>;
43
+ }
44
+ /**
45
+ * Base tsup configuration defaults used across all @jmlweb packages
46
+ */
47
+ declare const BASE_DEFAULTS: {
48
+ entry: string[];
49
+ format: ("cjs" | "esm")[];
50
+ dts: true;
51
+ clean: true;
52
+ outDir: string;
53
+ };
54
+ /**
55
+ * Creates a base tsup configuration with sensible defaults
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Simple usage without externals
60
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
61
+ * export default createTsupConfig();
62
+ * ```
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // With external dependencies
67
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
68
+ * export default createTsupConfig({
69
+ * external: ['eslint', 'typescript-eslint', '@eslint/js'],
70
+ * });
71
+ * ```
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // With additional options
76
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
77
+ * export default createTsupConfig({
78
+ * external: ['vitest'],
79
+ * options: {
80
+ * minify: true,
81
+ * sourcemap: true,
82
+ * },
83
+ * });
84
+ * ```
85
+ */
86
+ declare const createTsupConfig: (config?: TsupConfigOptions) => Options;
87
+
88
+ export { BASE_DEFAULTS, type TsupConfigOptions, createTsupConfig };
@@ -0,0 +1,88 @@
1
+ import { Options } from 'tsup';
2
+ export { Options } from 'tsup';
3
+
4
+ /**
5
+ * Options for creating a base tsup configuration
6
+ */
7
+ interface TsupConfigOptions {
8
+ /**
9
+ * Entry points for the build
10
+ * @default ['src/index.ts']
11
+ */
12
+ entry?: string[];
13
+ /**
14
+ * Output formats
15
+ * @default ['cjs', 'esm']
16
+ */
17
+ format?: ('cjs' | 'esm' | 'iife')[];
18
+ /**
19
+ * Generate TypeScript declaration files
20
+ * @default true
21
+ */
22
+ dts?: boolean;
23
+ /**
24
+ * Clean output directory before build
25
+ * @default true
26
+ */
27
+ clean?: boolean;
28
+ /**
29
+ * Output directory
30
+ * @default 'dist'
31
+ */
32
+ outDir?: string;
33
+ /**
34
+ * External packages to exclude from the bundle
35
+ * Typically includes peer dependencies and internal workspace packages
36
+ * @default []
37
+ */
38
+ external?: (string | RegExp)[];
39
+ /**
40
+ * Additional tsup options to merge with the base configuration
41
+ */
42
+ options?: Omit<Options, 'entry' | 'format' | 'dts' | 'clean' | 'outDir' | 'external'>;
43
+ }
44
+ /**
45
+ * Base tsup configuration defaults used across all @jmlweb packages
46
+ */
47
+ declare const BASE_DEFAULTS: {
48
+ entry: string[];
49
+ format: ("cjs" | "esm")[];
50
+ dts: true;
51
+ clean: true;
52
+ outDir: string;
53
+ };
54
+ /**
55
+ * Creates a base tsup configuration with sensible defaults
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Simple usage without externals
60
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
61
+ * export default createTsupConfig();
62
+ * ```
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * // With external dependencies
67
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
68
+ * export default createTsupConfig({
69
+ * external: ['eslint', 'typescript-eslint', '@eslint/js'],
70
+ * });
71
+ * ```
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // With additional options
76
+ * import { createTsupConfig } from '@jmlweb/tsup-config-base';
77
+ * export default createTsupConfig({
78
+ * external: ['vitest'],
79
+ * options: {
80
+ * minify: true,
81
+ * sourcemap: true,
82
+ * },
83
+ * });
84
+ * ```
85
+ */
86
+ declare const createTsupConfig: (config?: TsupConfigOptions) => Options;
87
+
88
+ export { BASE_DEFAULTS, type TsupConfigOptions, createTsupConfig };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/index.ts
2
+ var BASE_DEFAULTS = {
3
+ entry: ["src/index.ts"],
4
+ format: ["cjs", "esm"],
5
+ dts: true,
6
+ clean: true,
7
+ outDir: "dist"
8
+ };
9
+ var createTsupConfig = (config = {}) => {
10
+ const {
11
+ entry = BASE_DEFAULTS.entry,
12
+ format = BASE_DEFAULTS.format,
13
+ dts = BASE_DEFAULTS.dts,
14
+ clean = BASE_DEFAULTS.clean,
15
+ outDir = BASE_DEFAULTS.outDir,
16
+ external = [],
17
+ options = {}
18
+ } = config;
19
+ return {
20
+ entry,
21
+ format,
22
+ dts,
23
+ clean,
24
+ outDir,
25
+ ...external.length > 0 && { external },
26
+ ...options
27
+ };
28
+ };
29
+ export {
30
+ BASE_DEFAULTS,
31
+ createTsupConfig
32
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@jmlweb/tsup-config-base",
3
+ "version": "1.0.0",
4
+ "description": "Base tsup configuration for jmlweb projects with sensible defaults",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md",
24
+ "CHANGELOG.md"
25
+ ],
26
+ "keywords": [
27
+ "build",
28
+ "bundler",
29
+ "config",
30
+ "tsup",
31
+ "tsup-config",
32
+ "typescript"
33
+ ],
34
+ "author": "jmlweb",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/jmlweb/tooling.git"
39
+ },
40
+ "bugs": "https://github.com/jmlweb/tooling/issues",
41
+ "homepage": "https://github.com/jmlweb/tooling/tree/main/packages/tsup-config-base#readme",
42
+ "engines": {
43
+ "node": ">=18.0.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "tsup": ">=8.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "tsup": "^8.5.1",
53
+ "typescript": "^5.9.3",
54
+ "@jmlweb/tsconfig-internal": "0.0.1"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "clean": "rm -rf dist"
59
+ }
60
+ }