robuild 0.0.18 → 0.0.20

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/dist/config.d.mts CHANGED
@@ -1,2 +1,726 @@
1
- import { defineConfig } from "./_chunks/config-2CRkKJ3l.mjs";
2
- export { defineConfig };
1
+ import { ResolveOptions } from "exsolve";
2
+ import { InputOptions, MinifyOptions, ModuleFormat, ModuleType, OutputOptions, Plugin, RolldownBuild, RolldownPluginOption } from "rolldown";
3
+ import { Options } from "rolldown-plugin-dts";
4
+ import { MinifyOptions as MinifyOptions$1 } from "oxc-minify";
5
+ import { TransformOptions } from "oxc-transform";
6
+
7
+ //#region src/types.d.ts
8
+
9
+ /**
10
+ * Target platform
11
+ */
12
+ type Platform = 'browser' | 'node' | 'neutral';
13
+ /**
14
+ * Target ES version
15
+ */
16
+ type Target = 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext';
17
+ interface CopyEntry {
18
+ from: string;
19
+ to: string;
20
+ }
21
+ type CopyOptions = Array<string | CopyEntry>;
22
+ type ChunkAddon = string | Record<string, string>;
23
+ type OutExtensionFactory = (format: ModuleFormat) => {
24
+ js?: string;
25
+ dts?: string;
26
+ };
27
+ /**
28
+ * Loader types for robuild.
29
+ *
30
+ * Rolldown native types:
31
+ * - 'js', 'jsx', 'ts', 'tsx' - JavaScript/TypeScript files
32
+ * - 'json' - JSON files
33
+ * - 'text' - Text files (imported as string)
34
+ * - 'base64' - Files imported as base64 data URL
35
+ * - 'file' - Files imported as file path (copied to output)
36
+ * - 'empty' - Empty module
37
+ * - 'binary' - Binary files
38
+ * - 'css' - CSS files
39
+ * - 'asset' - Asset files (Rolldown decides between file/base64 based on size)
40
+ *
41
+ * Robuild extensions:
42
+ * - 'dataurl' - Alias for 'base64'
43
+ */
44
+ type LoaderType = ModuleType | 'dataurl';
45
+ interface LoaderConfig {
46
+ loader: LoaderType;
47
+ options?: Record<string, any>;
48
+ }
49
+ interface ShimsConfig {
50
+ /**
51
+ * Enable __dirname and __filename shims for ESM.
52
+ *
53
+ * @default true
54
+ */
55
+ dirname?: boolean;
56
+ /**
57
+ * Enable require() shim for ESM.
58
+ *
59
+ * @default true
60
+ */
61
+ require?: boolean;
62
+ /**
63
+ * Enable module.exports shim for ESM.
64
+ *
65
+ * @default true
66
+ */
67
+ exports?: boolean;
68
+ /**
69
+ * Enable process.env shim for browser.
70
+ *
71
+ * @default false
72
+ */
73
+ env?: boolean;
74
+ }
75
+ interface BuildContext {
76
+ pkgDir: string;
77
+ pkg: {
78
+ name: string;
79
+ } & Record<string, unknown>;
80
+ }
81
+ interface _BuildEntry {
82
+ /**
83
+ * Output directory relative to project root.
84
+ *
85
+ * Defaults to `dist/` if not provided.
86
+ */
87
+ outDir?: string;
88
+ /**
89
+ * Avoid actual build but instead link to the source files.
90
+ */
91
+ stub?: boolean;
92
+ /**
93
+ * Output format(s) for the build.
94
+ *
95
+ * Uses Rolldown's ModuleFormat:
96
+ * - 'es' / 'esm' / 'module': ES modules (default)
97
+ * - 'cjs' / 'commonjs': CommonJS
98
+ * - 'iife': Immediately Invoked Function Expression
99
+ * - 'umd': Universal Module Definition
100
+ *
101
+ * @default ['es']
102
+ */
103
+ format?: ModuleFormat | ModuleFormat[];
104
+ /**
105
+ * Target platform for the build.
106
+ *
107
+ * Defaults to `'node'` if not provided.
108
+ */
109
+ platform?: Platform;
110
+ /**
111
+ * Target ES version for the build.
112
+ *
113
+ * Defaults to `'es2022'` if not provided.
114
+ */
115
+ target?: Target;
116
+ /**
117
+ * Global variable name for IIFE/UMD formats.
118
+ */
119
+ globalName?: string;
120
+ /**
121
+ * Module path aliases.
122
+ *
123
+ * Allows defining path mappings for imports.
124
+ */
125
+ alias?: Record<string, string>;
126
+ /**
127
+ * Copy files to output directory.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * copy: ['src/assets', { from: 'src/assets', to: 'dist/assets' }]
132
+ * ```
133
+ */
134
+ copy?: CopyOptions;
135
+ /**
136
+ * Add banner/footer to output files.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * banner: '// Copyright 2024'
141
+ * footer: '// End of file'
142
+ * ```
143
+ */
144
+ banner?: string | ChunkAddon;
145
+ footer?: string | ChunkAddon;
146
+ /**
147
+ * Add content hash to output filenames.
148
+ *
149
+ * @default false
150
+ */
151
+ hash?: boolean;
152
+ /**
153
+ * Use fixed extensions (.cjs/.mjs) for output files.
154
+ *
155
+ * @default false
156
+ */
157
+ fixedExtension?: boolean;
158
+ /**
159
+ * Custom output file extensions.
160
+ */
161
+ outExtensions?: OutExtensionFactory;
162
+ /**
163
+ * Handle Node.js protocol imports.
164
+ *
165
+ * - `true`: Add `node:` prefix to built-in modules
166
+ * - `'strip'`: Remove `node:` prefix from imports
167
+ * - `false`: Keep imports unchanged
168
+ *
169
+ * @default false
170
+ */
171
+ nodeProtocol?: 'strip' | boolean;
172
+ /**
173
+ * Clean output directory before build.
174
+ *
175
+ * Defaults to `true` if not provided.
176
+ */
177
+ clean?: boolean | string[];
178
+ /**
179
+ * Environment variables to inject at compile time.
180
+ */
181
+ env?: Record<string, any>;
182
+ /**
183
+ * Define constants to replace at compile time.
184
+ */
185
+ define?: Record<string, string>;
186
+ /**
187
+ * Generate source maps for built files.
188
+ *
189
+ * - `true` - emit separate `.map` files
190
+ * - `'inline'` - embed source maps in generated files
191
+ * - `'hidden'` - emit map files but do not add sourceMappingURL comment
192
+ */
193
+ sourcemap?: boolean | 'inline' | 'hidden' | Record<string, any>;
194
+ /**
195
+ * External dependencies that should not be bundled.
196
+ */
197
+ external?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
198
+ /**
199
+ * Dependencies that should be bundled even if they're in node_modules.
200
+ */
201
+ noExternal?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
202
+ /**
203
+ * File type loaders configuration.
204
+ *
205
+ * Maps file extensions to loader types. Uses Rolldown's native moduleTypes.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * loaders: {
210
+ * '.png': { loader: 'asset' }, // Auto base64 for small files, file path for large
211
+ * '.jpg': { loader: 'file' }, // Always emit as file
212
+ * '.svg': { loader: 'text' }, // Import as string
213
+ * '.woff': { loader: 'base64' }, // Import as data URL
214
+ * }
215
+ * ```
216
+ */
217
+ loaders?: Record<string, LoaderConfig>;
218
+ /**
219
+ * CommonJS default export handling.
220
+ *
221
+ * - `true`: Preserve CommonJS default exports
222
+ * - `false`: Transform to ES module default exports
223
+ * - `'auto'`: Auto-detect based on file content
224
+ *
225
+ * @default 'auto'
226
+ */
227
+ cjsDefault?: boolean | 'auto';
228
+ /**
229
+ * Enable CJS/ESM compatibility shims.
230
+ *
231
+ * @default false
232
+ */
233
+ shims?: boolean | ShimsConfig;
234
+ /**
235
+ * Skip bundling node_modules dependencies.
236
+ *
237
+ * @default false
238
+ */
239
+ skipNodeModules?: boolean;
240
+ /**
241
+ * Unbundle mode - preserve file structure without bundling.
242
+ *
243
+ * @default false
244
+ */
245
+ unbundle?: boolean;
246
+ }
247
+ type BundleEntry = _BuildEntry & {
248
+ type: 'bundle';
249
+ /**
250
+ * Entry point(s) to bundle relative to the project root.
251
+ *
252
+ * Supports multiple formats:
253
+ * - Single file: `'src/index.ts'`
254
+ * - Multiple files: `['src/index.ts', 'src/cli.ts']`
255
+ * - Named entries: `{ index: 'src/index.ts', cli: 'src/cli.ts' }`
256
+ *
257
+ * @alias entry (tsup compatibility)
258
+ */
259
+ input?: string | string[] | Record<string, string>;
260
+ /**
261
+ * Entry point(s) to bundle (tsup-style alias for `input`)
262
+ *
263
+ * @alias input
264
+ */
265
+ entry?: string | string[] | Record<string, string>;
266
+ /**
267
+ * Minify the output using rolldown.
268
+ *
269
+ * Defaults to `false` if not provided.
270
+ */
271
+ minify?: boolean | 'dce-only' | MinifyOptions;
272
+ /**
273
+ * Enable code splitting.
274
+ *
275
+ * When enabled, shared code will be extracted into separate chunks.
276
+ *
277
+ * @default false
278
+ */
279
+ splitting?: boolean;
280
+ /**
281
+ * Tree shaking configuration.
282
+ *
283
+ * - `true`: Enable tree shaking (default)
284
+ * - `false`: Disable tree shaking
285
+ * - Object: Pass directly to Rolldown's treeshake option
286
+ *
287
+ * @default true
288
+ */
289
+ treeshake?: boolean | InputOptions['treeshake'];
290
+ /**
291
+ * Inject environment variables at build time.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * env: {
296
+ * NODE_ENV: 'production',
297
+ * API_URL: 'https://api.example.com'
298
+ * }
299
+ * ```
300
+ */
301
+ env?: Record<string, string>;
302
+ /**
303
+ * Advanced rolldown configuration.
304
+ *
305
+ * This allows passing any rolldown InputOptions and OutputOptions directly.
306
+ * These options have the highest priority and will override other robuild settings.
307
+ *
308
+ * Use with caution as it may conflict with robuild's built-in features.
309
+ *
310
+ * See [rolldown config options](https://rolldown.rs/reference/config-options) for more details.
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * {
315
+ * rolldown: {
316
+ * treeshake: false,
317
+ * logLevel: 'debug',
318
+ * plugins: [customPlugin()],
319
+ * output: {
320
+ * generatedCode: { arrowFunctions: true }
321
+ * }
322
+ * }
323
+ * }
324
+ * ```
325
+ */
326
+ rolldown?: Partial<InputOptions> & {
327
+ plugins?: RolldownPluginOption[];
328
+ output?: Partial<OutputOptions>;
329
+ };
330
+ /**
331
+ * Declaration generation options.
332
+ *
333
+ * See [rolldown-plugin-dts](https://github.com/sxzz/rolldown-plugin-dts) for more details.
334
+ *
335
+ * Options are inferred from the `tsconfig.json` file if available.
336
+ *
337
+ * Set to `false` to disable.
338
+ */
339
+ dts?: boolean | Options;
340
+ /**
341
+ * Only generate declaration files without JavaScript output.
342
+ *
343
+ * @default false
344
+ */
345
+ dtsOnly?: boolean;
346
+ };
347
+ type TransformEntry = _BuildEntry & {
348
+ type: 'transform';
349
+ /**
350
+ * Directory to transform relative to the project root.
351
+ */
352
+ input: string;
353
+ /**
354
+ * Minify the output using oxc-minify.
355
+ *
356
+ * Defaults to `false` if not provided.
357
+ */
358
+ minify?: boolean | MinifyOptions$1;
359
+ /**
360
+ * Options passed to oxc-transform.
361
+ *
362
+ * See [oxc-transform](https://www.npmjs.com/package/oxc-transform) for more details.
363
+ */
364
+ oxc?: TransformOptions;
365
+ /**
366
+ * Options passed to exsolve for module resolution.
367
+ *
368
+ * See [exsolve](https://github.com/unjs/exsolve) for more details.
369
+ */
370
+ resolve?: Omit<ResolveOptions, 'from'>;
371
+ };
372
+ type BuildEntry = BundleEntry | TransformEntry;
373
+ /**
374
+ * Robuild plugin extends rolldown plugin with additional hooks
375
+ */
376
+ interface RobuildPlugin extends Plugin {
377
+ robuildSetup?: (context: RobuildPluginContext) => void | Promise<void>;
378
+ robuildBuildStart?: (context: RobuildPluginContext) => void | Promise<void>;
379
+ robuildBuildEnd?: (context: RobuildPluginContext, result?: any) => void | Promise<void>;
380
+ meta?: {
381
+ framework?: 'rolldown' | 'rollup' | 'vite' | 'unplugin' | 'robuild';
382
+ robuild?: boolean;
383
+ rollup?: boolean;
384
+ vite?: boolean;
385
+ webpack?: boolean;
386
+ esbuild?: boolean;
387
+ unplugin?: boolean;
388
+ };
389
+ }
390
+ /**
391
+ * Context provided to robuild-specific plugin hooks
392
+ */
393
+ interface RobuildPluginContext {
394
+ config: BuildConfig;
395
+ entry: BuildEntry;
396
+ pkgDir: string;
397
+ outDir: string;
398
+ format: ModuleFormat | ModuleFormat[];
399
+ platform: Platform;
400
+ target: string;
401
+ }
402
+ /**
403
+ * Plugin factory function type
404
+ */
405
+ type RobuildPluginFactory<T = any> = (options?: T) => RobuildPlugin;
406
+ /**
407
+ * Union type for all supported plugin types
408
+ */
409
+ type RobuildPluginOption = RobuildPlugin | Plugin | RobuildPluginFactory | any;
410
+ interface GlobImportOptions {
411
+ /**
412
+ * Enable glob imports support
413
+ * @default false
414
+ */
415
+ enabled?: boolean;
416
+ /**
417
+ * Glob patterns to match
418
+ * @default ['**\/*']
419
+ */
420
+ patterns?: string[];
421
+ /**
422
+ * Whether to import as URLs
423
+ * @default false
424
+ */
425
+ asUrls?: boolean;
426
+ /**
427
+ * Whether to import eagerly
428
+ * @default false
429
+ */
430
+ eager?: boolean;
431
+ }
432
+ interface BuildHooks {
433
+ /**
434
+ * Called at the start of the build process
435
+ */
436
+ start?: (ctx: BuildContext) => void | Promise<void>;
437
+ /**
438
+ * Called at the end of the build process
439
+ */
440
+ end?: (ctx: BuildContext) => void | Promise<void>;
441
+ /**
442
+ * Called after entries are normalized
443
+ */
444
+ entries?: (entries: BuildEntry[], ctx: BuildContext) => void | Promise<void>;
445
+ /**
446
+ * Called before rolldown config is finalized
447
+ */
448
+ rolldownConfig?: (cfg: InputOptions, ctx: BuildContext) => void | Promise<void>;
449
+ /**
450
+ * Called before rolldown output config is finalized
451
+ */
452
+ rolldownOutput?: (cfg: OutputOptions, res: RolldownBuild, ctx: BuildContext) => void | Promise<void>;
453
+ }
454
+ interface WatchOptions {
455
+ /**
456
+ * Enable watch mode.
457
+ *
458
+ * Defaults to `false` if not provided.
459
+ */
460
+ enabled?: boolean;
461
+ /**
462
+ * Glob patterns for files to watch.
463
+ *
464
+ * Defaults to watching all source files if not provided.
465
+ */
466
+ include?: string[];
467
+ /**
468
+ * Glob patterns for files to ignore.
469
+ *
470
+ * Defaults to common ignore patterns if not provided.
471
+ */
472
+ exclude?: string[];
473
+ /**
474
+ * Delay in milliseconds before rebuilding after a file change.
475
+ *
476
+ * Defaults to `100` if not provided.
477
+ */
478
+ delay?: number;
479
+ /**
480
+ * Whether to ignore the initial build when starting watch mode.
481
+ *
482
+ * Defaults to `false` if not provided.
483
+ */
484
+ ignoreInitial?: boolean;
485
+ /**
486
+ * Whether to watch for new files being added.
487
+ *
488
+ * Defaults to `true` if not provided.
489
+ */
490
+ watchNewFiles?: boolean;
491
+ }
492
+ type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'verbose';
493
+ type OnSuccessCallback = string | ((result: BuildResult) => void | Promise<void>);
494
+ interface BuildResult {
495
+ entries: Array<{
496
+ format: ModuleFormat;
497
+ name: string;
498
+ exports: string[];
499
+ deps: string[];
500
+ size: number;
501
+ gzipSize: number;
502
+ sideEffectSize: number;
503
+ }>;
504
+ duration: number;
505
+ }
506
+ interface BuildConfig {
507
+ cwd?: string | URL;
508
+ /**
509
+ * Build entries configuration.
510
+ *
511
+ * Supports multiple formats:
512
+ * - Array of entries: `[{ type: 'bundle', input: 'src/index.ts' }]`
513
+ * - String shortcuts: `['src/index.ts']`
514
+ * - Single entry object (tsup-style): omit `entries` and use top-level config
515
+ */
516
+ entries?: (BuildEntry | string)[];
517
+ /**
518
+ * Entry point(s) for tsup-style configuration.
519
+ *
520
+ * When using this, you don't need to specify `entries`.
521
+ *
522
+ * @example
523
+ * ```ts
524
+ * {
525
+ * entry: ['src/index.ts', 'src/cli.ts'],
526
+ * format: ['es', 'cjs'],
527
+ * dts: true
528
+ * }
529
+ * ```
530
+ */
531
+ entry?: string | string[] | Record<string, string>;
532
+ /**
533
+ * Output format(s) for tsup-style configuration.
534
+ *
535
+ * @default ['es']
536
+ */
537
+ format?: ModuleFormat | ModuleFormat[];
538
+ /**
539
+ * Output directory for tsup-style configuration.
540
+ *
541
+ * @default 'dist'
542
+ */
543
+ outDir?: string;
544
+ /**
545
+ * Target platform for tsup-style configuration.
546
+ *
547
+ * @default 'node'
548
+ */
549
+ platform?: Platform;
550
+ /**
551
+ * Target ES version for tsup-style configuration.
552
+ *
553
+ * @default 'es2022'
554
+ */
555
+ target?: Target;
556
+ /**
557
+ * Global variable name for IIFE/UMD formats (tsup-style).
558
+ */
559
+ name?: string;
560
+ /**
561
+ * Minify output (tsup-style).
562
+ *
563
+ * @default false
564
+ */
565
+ minify?: boolean | 'dce-only' | MinifyOptions;
566
+ /**
567
+ * Generate declaration files (tsup-style).
568
+ *
569
+ * @default false
570
+ */
571
+ dts?: boolean | Options;
572
+ /**
573
+ * Only generate declaration files (tsup-style).
574
+ *
575
+ * @default false
576
+ */
577
+ dtsOnly?: boolean;
578
+ /**
579
+ * Enable code splitting (tsup-style).
580
+ *
581
+ * @default false
582
+ */
583
+ splitting?: boolean;
584
+ /**
585
+ * Tree shaking configuration (tsup-style).
586
+ *
587
+ * @default true
588
+ */
589
+ treeshake?: boolean | InputOptions['treeshake'];
590
+ /**
591
+ * Generate source maps (tsup-style).
592
+ *
593
+ * @default false
594
+ */
595
+ sourcemap?: boolean | 'inline' | 'hidden';
596
+ /**
597
+ * File type loaders configuration (tsup-style).
598
+ *
599
+ * @see _BuildEntry.loaders
600
+ */
601
+ loaders?: Record<string, LoaderConfig>;
602
+ /**
603
+ * External dependencies (tsup-style).
604
+ */
605
+ external?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
606
+ /**
607
+ * Dependencies to bundle (tsup-style).
608
+ */
609
+ noExternal?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
610
+ /**
611
+ * Inject environment variables (tsup-style).
612
+ */
613
+ env?: Record<string, string>;
614
+ /**
615
+ * Module path aliases (tsup-style).
616
+ */
617
+ alias?: Record<string, string>;
618
+ /**
619
+ * Add banner to output files (tsup-style).
620
+ */
621
+ banner?: string | ChunkAddon;
622
+ /**
623
+ * Add footer to output files (tsup-style).
624
+ */
625
+ footer?: string | ChunkAddon;
626
+ /**
627
+ * Enable shims for Node.js globals (tsup-style).
628
+ */
629
+ shims?: boolean | ShimsConfig;
630
+ /**
631
+ * Advanced rolldown configuration (tsup-style).
632
+ *
633
+ * This allows passing any rolldown InputOptions and OutputOptions directly.
634
+ * These options have the highest priority and will override other robuild settings.
635
+ *
636
+ * @see BundleEntry.rolldown
637
+ */
638
+ rolldown?: Partial<InputOptions> & {
639
+ plugins?: RolldownPluginOption[];
640
+ output?: Partial<OutputOptions>;
641
+ };
642
+ /**
643
+ * Clean output directory before build.
644
+ */
645
+ clean?: boolean | string[];
646
+ /**
647
+ * Build lifecycle hooks.
648
+ *
649
+ * For plugin-style hooks (buildStart, writeBundle, transform, etc.),
650
+ * use the `plugins` field instead.
651
+ */
652
+ hooks?: BuildHooks;
653
+ watch?: WatchOptions;
654
+ /**
655
+ * Plugins to use during build.
656
+ *
657
+ * Plugins support all Rolldown plugin hooks (buildStart, writeBundle, transform, etc.)
658
+ * and can be used for custom build logic.
659
+ */
660
+ plugins?: RobuildPluginOption[];
661
+ /**
662
+ * Glob import configuration
663
+ */
664
+ globImport?: GlobImportOptions;
665
+ /**
666
+ * Log level for build output.
667
+ *
668
+ * @default 'info'
669
+ */
670
+ logLevel?: LogLevel;
671
+ /**
672
+ * Callback to execute after successful build.
673
+ */
674
+ onSuccess?: OnSuccessCallback;
675
+ /**
676
+ * Fail build on warnings.
677
+ *
678
+ * @default false
679
+ */
680
+ failOnWarn?: boolean;
681
+ /**
682
+ * Additional paths to ignore in watch mode.
683
+ */
684
+ ignoreWatch?: string[];
685
+ /**
686
+ * Load configuration from Vite config file.
687
+ *
688
+ * @default false
689
+ */
690
+ fromVite?: boolean;
691
+ /**
692
+ * Package exports generation configuration.
693
+ */
694
+ exports?: ExportsConfig;
695
+ }
696
+ interface ExportsConfig {
697
+ /**
698
+ * Whether to generate package.json exports field.
699
+ */
700
+ enabled?: boolean;
701
+ /**
702
+ * Custom exports mapping.
703
+ */
704
+ custom?: Record<string, string | {
705
+ import?: string;
706
+ require?: string;
707
+ types?: string;
708
+ }>;
709
+ /**
710
+ * Whether to include types in exports.
711
+ */
712
+ includeTypes?: boolean;
713
+ /**
714
+ * Base directory for exports (relative to package root).
715
+ */
716
+ baseDir?: string;
717
+ /**
718
+ * Whether to update package.json automatically.
719
+ */
720
+ autoUpdate?: boolean;
721
+ }
722
+ //#endregion
723
+ //#region src/config.d.ts
724
+ declare function defineConfig(config: BuildConfig): BuildConfig;
725
+ //#endregion
726
+ export { RobuildPlugin as a, BundleEntry as i, BuildConfig as n, TransformEntry as o, BuildEntry as r, defineConfig as t };