-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
index.ts
2879 lines (2237 loc) · 62.7 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Assumptions } from "./assumptions";
export interface Plugin {
(module: Program): Program;
}
// TODO:
export type ParseOptions = ParserConfig & {
comments?: boolean;
script?: boolean;
/**
* Defaults to es3.
*/
target?: JscTarget;
};
export type TerserEcmaVersion = 5 | 2015 | 2016 | string | number;
export interface JsMinifyOptions {
compress?: TerserCompressOptions | boolean;
format?: JsFormatOptions & ToSnakeCaseProperties<JsFormatOptions>;
mangle?: TerserMangleOptions | boolean;
ecma?: TerserEcmaVersion;
keep_classnames?: boolean;
keep_fnames?: boolean;
module?: boolean | "unknown";
safari10?: boolean;
toplevel?: boolean;
sourceMap?: boolean;
outputPath?: string;
inlineSourcesContent?: boolean;
}
/**
* @example ToSnakeCase<'indentLevel'> == 'indent_level'
*/
type ToSnakeCase<T extends string> = T extends `${infer A}${infer B}`
? `${A extends Lowercase<A> ? A : `_${Lowercase<A>}`}${ToSnakeCase<B>}`
: T;
/**
* @example ToSnakeCaseProperties<{indentLevel: 3}> == {indent_level: 3}
*/
type ToSnakeCaseProperties<T> = {
[K in keyof T as K extends string ? ToSnakeCase<K> : K]: T[K];
};
/**
* These properties are mostly not implemented yet,
* but it exists to support passing terser config to swc minify
* without modification.
*/
export interface JsFormatOptions {
/**
* Currently noop.
* @default false
* @alias ascii_only
*/
asciiOnly?: boolean;
/**
* Currently noop.
* @default false
*/
beautify?: boolean;
/**
* Currently noop.
* @default false
*/
braces?: boolean;
/**
* - `false`: removes all comments
* - `'some'`: preserves some comments
* - `'all'`: preserves all comments
* @default false
*/
comments?: false | "some" | "all";
/**
* Currently noop.
* @default 5
*/
ecma?: TerserEcmaVersion;
/**
* Currently noop.
* @alias indent_level
*/
indentLevel?: number;
/**
* Currently noop.
* @alias indent_start
*/
indentStart?: number;
/**
* Currently noop.
* @alias inline_script
*/
inlineScript?: boolean;
/**
* Currently noop.
* @alias keep_numbers
*/
keepNumbers?: number;
/**
* Currently noop.
* @alias keep_quoted_props
*/
keepQuotedProps?: boolean;
/**
* Currently noop.
* @alias max_line_len
*/
maxLineLen?: number | false;
/**
* Currently noop.
*/
preamble?: string;
/**
* Currently noop.
* @alias quote_keys
*/
quoteKeys?: boolean;
/**
* Currently noop.
* @alias quote_style
*/
quoteStyle?: boolean;
/**
* Currently noop.
* @alias preserve_annotations
*/
preserveAnnotations?: boolean;
/**
* Currently noop.
*/
safari10?: boolean;
/**
* Currently noop.
*/
semicolons?: boolean;
/**
* Currently noop.
*/
shebang?: boolean;
/**
* Currently noop.
*/
webkit?: boolean;
/**
* Currently noop.
* @alias wrap_iife
*/
wrapIife?: boolean;
/**
* Currently noop.
* @alias wrap_func_args
*/
wrapFuncArgs?: boolean;
}
export interface TerserCompressOptions {
arguments?: boolean;
arrows?: boolean;
booleans?: boolean;
booleans_as_integers?: boolean;
collapse_vars?: boolean;
comparisons?: boolean;
computed_props?: boolean;
conditionals?: boolean;
dead_code?: boolean;
defaults?: boolean;
directives?: boolean;
drop_console?: boolean;
drop_debugger?: boolean;
ecma?: TerserEcmaVersion;
evaluate?: boolean;
expression?: boolean;
global_defs?: any;
hoist_funs?: boolean;
hoist_props?: boolean;
hoist_vars?: boolean;
ie8?: boolean;
if_return?: boolean;
inline?: 0 | 1 | 2 | 3;
join_vars?: boolean;
keep_classnames?: boolean;
keep_fargs?: boolean;
keep_fnames?: boolean;
keep_infinity?: boolean;
loops?: boolean;
// module : false,
negate_iife?: boolean;
passes?: number;
properties?: boolean;
pure_getters?: any;
pure_funcs?: string[];
reduce_funcs?: boolean;
reduce_vars?: boolean;
sequences?: any;
side_effects?: boolean;
switches?: boolean;
top_retain?: any;
toplevel?: any;
typeofs?: boolean;
unsafe?: boolean;
unsafe_passes?: boolean;
unsafe_arrows?: boolean;
unsafe_comps?: boolean;
unsafe_function?: boolean;
unsafe_math?: boolean;
unsafe_symbols?: boolean;
unsafe_methods?: boolean;
unsafe_proto?: boolean;
unsafe_regexp?: boolean;
unsafe_undefined?: boolean;
unused?: boolean;
const_to_let?: boolean;
module?: boolean;
}
export interface TerserMangleOptions {
props?: TerserManglePropertiesOptions;
/**
* Pass `true` to mangle names declared in the top level scope.
*/
topLevel?: boolean;
/**
* @deprecated An alias for compatibility with terser.
*/
toplevel?: boolean;
/**
* Pass `true` to not mangle class names.
*/
keepClassNames?: boolean;
/**
* @deprecated An alias for compatibility with terser.
*/
keep_classnames?: boolean;
/**
* Pass `true` to not mangle function names.
*/
keepFnNames?: boolean;
/**
* @deprecated An alias for compatibility with terser.
*/
keep_fnames?: boolean;
/**
* Pass `true` to not mangle private props.
*/
keepPrivateProps?: boolean;
/**
* @deprecated An alias for compatibility with terser.
*/
keep_private_props?: boolean;
ie8?: boolean;
safari10?: boolean;
reserved?: string[];
}
export interface TerserManglePropertiesOptions {}
/**
* Programmatic options.
*/
export interface Options extends Config {
/**
* If true, a file is parsed as a script instead of module.
*/
script?: boolean;
/**
* The working directory that all paths in the programmatic
* options will be resolved relative to.
*
* Defaults to `process.cwd()`.
*/
cwd?: string;
caller?: CallerOptions;
/** The filename associated with the code currently being compiled,
* if there is one. The filename is optional, but not all of Swc's
* functionality is available when the filename is unknown, because a
* subset of options rely on the filename for their functionality.
*
* The three primary cases users could run into are:
*
* - The filename is exposed to plugins. Some plugins may require the
* presence of the filename.
* - Options like "test", "exclude", and "ignore" require the filename
* for string/RegExp matching.
* - .swcrc files are loaded relative to the file being compiled.
* If this option is omitted, Swc will behave as if swcrc: false has been set.
*/
filename?: string;
/**
* The initial path that will be processed based on the "rootMode" to
* determine the conceptual root folder for the current Swc project.
* This is used in two primary cases:
*
* - The base directory when checking for the default "configFile" value
* - The default value for "swcrcRoots".
*
* Defaults to `opts.cwd`
*/
root?: string;
/**
* This option, combined with the "root" value, defines how Swc chooses
* its project root. The different modes define different ways that Swc
* can process the "root" value to get the final project root.
*
* "root" - Passes the "root" value through as unchanged.
* "upward" - Walks upward from the "root" directory, looking for a directory
* containing a swc.config.js file, and throws an error if a swc.config.js
* is not found.
* "upward-optional" - Walk upward from the "root" directory, looking for
* a directory containing a swc.config.js file, and falls back to "root"
* if a swc.config.js is not found.
*
*
* "root" is the default mode because it avoids the risk that Swc
* will accidentally load a swc.config.js that is entirely outside
* of the current project folder. If you use "upward-optional",
* be aware that it will walk up the directory structure all the
* way to the filesystem root, and it is always possible that someone
* will have a forgotten swc.config.js in their home directory,
* which could cause unexpected errors in your builds.
*
*
* Users with monorepo project structures that run builds/tests on a
* per-package basis may well want to use "upward" since monorepos
* often have a swc.config.js in the project root. Running Swc
* in a monorepo subdirectory without "upward", will cause Swc
* to skip loading any swc.config.js files in the project root,
* which can lead to unexpected errors and compilation failure.
*/
rootMode?: "root" | "upward" | "upward-optional";
/**
* The current active environment used during configuration loading.
* This value is used as the key when resolving "env" configs,
* and is also available inside configuration functions, plugins,
* and presets, via the api.env() function.
*
* Defaults to `process.env.SWC_ENV || process.env.NODE_ENV || "development"`
*/
envName?: string;
/**
* Defaults to searching for a default `.swcrc` file, but can
* be passed the path of any JS or JSON5 config file.
*
*
* NOTE: This option does not affect loading of .swcrc files,
* so while it may be tempting to do configFile: "./foo/.swcrc",
* it is not recommended. If the given .swcrc is loaded via the
* standard file-relative logic, you'll end up loading the same
* config file twice, merging it with itself. If you are linking
* a specific config file, it is recommended to stick with a
* naming scheme that is independent of the "swcrc" name.
*
* Defaults to `path.resolve(opts.root, ".swcrc")`
*/
configFile?: string | boolean;
/**
* true will enable searching for configuration files relative to the "filename" provided to Swc.
*
* A swcrc value passed in the programmatic options will override one set within a configuration file.
*
* Note: .swcrc files are only loaded if the current "filename" is inside of
* a package that matches one of the "swcrcRoots" packages.
*
*
* Defaults to true as long as the filename option has been specified
*/
swcrc?: boolean;
/**
* By default, Babel will only search for .babelrc files within the "root" package
* because otherwise Babel cannot know if a given .babelrc is meant to be loaded,
* or if it's "plugins" and "presets" have even been installed, since the file
* being compiled could be inside node_modules, or have been symlinked into the project.
*
*
* This option allows users to provide a list of other packages that should be
* considered "root" packages when considering whether to load .babelrc files.
*
*
* For example, a monorepo setup that wishes to allow individual packages
* to have their own configs might want to do
*
*
*
* Defaults to `opts.root`
*/
swcrcRoots?: boolean | MatchPattern | MatchPattern[];
/**
* `true` will attempt to load an input sourcemap from the file itself, if it
* contains a //# sourceMappingURL=... comment. If no map is found, or the
* map fails to load and parse, it will be silently discarded.
*
* If an object is provided, it will be treated as the source map object itself.
*
* Defaults to `true`.
*/
inputSourceMap?: boolean | string;
/**
* The name to use for the file inside the source map object.
*
* Defaults to `path.basename(opts.filenameRelative)` when available, or `"unknown"`.
*/
sourceFileName?: string;
/**
* The sourceRoot fields to set in the generated source map, if one is desired.
*/
sourceRoot?: string;
plugin?: Plugin;
isModule?: boolean | "unknown";
/**
* Destination path. Note that this value is used only to fix source path
* of source map files and swc does not write output to this path.
*/
outputPath?: string;
}
export interface CallerOptions {
name: string;
[key: string]: any;
}
export type Swcrc = Config | Config[];
/**
* .swcrc
*/
export interface Config {
/**
* Note: The type is string because it follows rust's regex syntax.
*/
test?: string | string[];
/**
* Note: The type is string because it follows rust's regex syntax.
*/
exclude?: string | string[];
env?: EnvConfig;
jsc?: JscConfig;
module?: ModuleConfig;
minify?: boolean;
/**
* - true to generate a sourcemap for the code and include it in the result object.
* - "inline" to generate a sourcemap and append it as a data URL to the end of the code, but not include it in the result object.
*
* `swc-cli` overloads some of these to also affect how maps are written to disk:
*
* - true will write the map to a .map file on disk
* - "inline" will write the file directly, so it will have a data: containing the map
* - Note: These options are bit weird, so it may make the most sense to just use true
* and handle the rest in your own code, depending on your use case.
*/
sourceMaps?: boolean | "inline";
inlineSourcesContent?: boolean;
}
/**
* Configuration ported from babel-preset-env
*/
export interface EnvConfig {
mode?: "usage" | "entry";
debug?: boolean;
dynamicImport?: boolean;
loose?: boolean;
/**
* Transpiles the broken syntax to the closest non-broken modern syntax
*
* Defaults to false.
*/
bugfixes?: boolean;
/// Skipped es features.
///
/// e.g.)
/// - `core-js/modules/foo`
skip?: string[];
include?: string[];
exclude?: string[];
/**
* The version of the used core js.
*
*/
coreJs?: string;
targets?: any;
path?: string;
shippedProposals?: boolean;
/**
* Enable all transforms
*/
forceAllTransforms?: boolean;
}
export interface JscConfig {
assumptions?: Assumptions;
loose?: boolean;
/**
* Defaults to EsParserConfig
*/
parser?: ParserConfig;
transform?: TransformConfig;
/**
* Use `@swc/helpers` instead of inline helpers.
*/
externalHelpers?: boolean;
/**
* Defaults to `es3` (which enabled **all** pass).
*/
target?: JscTarget;
/**
* Keep class names.
*/
keepClassNames?: boolean;
/**
* This is experimental, and can be removed without a major version bump.
*/
experimental?: {
optimizeHygiene?: boolean;
/**
* Preserve `with` in imports and exports.
*
* @deprecated Use `keepImportAssertions` instead.
*/
keepImportAttributes?: boolean;
/**
* Use `assert` instead of `with` for imports and exports.
* This option only works when `keepImportAttributes` is `true`.
*/
emitAssertForImportAttributes?: boolean;
/**
* Specify the location where SWC stores its intermediate cache files.
* Currently only transform plugin uses this. If not specified, SWC will
* create `.swc` directories.
*/
cacheRoot?: string;
/**
* List of custom transform plugins written in WebAssembly.
* First parameter of tuple indicates the name of the plugin - it can be either
* a name of the npm package can be resolved, or absolute path to .wasm binary.
*
* Second parameter of tuple is JSON based configuration for the plugin.
*/
plugins?: Array<[string, Record<string, any>]>;
/**
* Run Wasm plugins before stripping TypeScript or decorators.
*
* See https://github.com/swc-project/swc/issues/9132 for more details.
*/
runPluginFirst?: boolean;
/**
* Disable builtin transforms. If enabled, only Wasm plugins are used.
*/
disableBuiltinTransformsForInternalTesting?: boolean;
/**
* Emit isolated dts files for each module.
*/
emitIsolatedDts?: boolean;
/**
* Disable all lint rules.
*/
disableAllLints?: boolean;
/**
* Keep import assertions.
*/
keepImportAssertions?: boolean;
};
baseUrl?: string;
paths?: {
[from: string]: string[];
};
minify?: JsMinifyOptions;
preserveAllComments?: boolean;
}
export type JscTarget =
| "es3"
| "es5"
| "es2015"
| "es2016"
| "es2017"
| "es2018"
| "es2019"
| "es2020"
| "es2021"
| "es2022"
| "es2023"
| "es2024"
| "esnext";
export type ParserConfig = TsParserConfig | EsParserConfig;
export interface TsParserConfig {
syntax: "typescript";
/**
* Defaults to `false`.
*/
tsx?: boolean;
/**
* Defaults to `false`.
*/
decorators?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
dynamicImport?: boolean;
}
export interface EsParserConfig {
syntax: "ecmascript";
/**
* Defaults to false.
*/
jsx?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
numericSeparator?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
classPrivateProperty?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
privateMethod?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
classProperty?: boolean;
/**
* Defaults to `false`
*/
functionBind?: boolean;
/**
* Defaults to `false`
*/
decorators?: boolean;
/**
* Defaults to `false`
*/
decoratorsBeforeExport?: boolean;
/**
* Defaults to `false`
*/
exportDefaultFrom?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
exportNamespaceFrom?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
dynamicImport?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
nullishCoalescing?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
optionalChaining?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
importMeta?: boolean;
/**
* @deprecated Always true because it's in ecmascript spec.
*/
topLevelAwait?: boolean;
/**
* @deprecated An alias of `importAttributes`
*/
importAssertions?: boolean;
/**
* Defaults to `false`
*/
importAttributes?: boolean;
/**
* Defaults to `false`
*/
allowSuperOutsideMethod?: boolean;
/**
* Defaults to `false`
*/
allowReturnOutsideFunction?: boolean;
/**
* Defaults to `false`
*/
autoAccessors?: boolean;
/**
* Defaults to `false`
*/
explicitResourceManagement?: boolean;
}
/**
* Options for transform.
*/
export interface TransformConfig {
/**
* Effective only if `syntax` supports ƒ.
*/
react?: ReactConfig;
constModules?: ConstModulesConfig;
/**
* Defaults to null, which skips optimizer pass.
*/
optimizer?: OptimizerConfig;
/**
* https://swc.rs/docs/configuring-swc.html#jsctransformlegacydecorator
*/
legacyDecorator?: boolean;
/**
* https://swc.rs/docs/configuring-swc.html#jsctransformdecoratormetadata
*/
decoratorMetadata?: boolean;
/**
* https://swc.rs/docs/configuration/compilation#jsctransformdecoratorversion
*/
decoratorVersion?: "2021-12" | "2022-03";
treatConstEnumAsEnum?: boolean;
useDefineForClassFields?: boolean;
}
export interface ReactConfig {
/**
* Replace the function used when compiling JSX expressions.
*
* Defaults to `React.createElement`.
*/
pragma?: string;
/**
* Replace the component used when compiling JSX fragments.
*
* Defaults to `React.Fragment`
*/
pragmaFrag?: string;
/**
* Toggles whether or not to throw an error if a XML namespaced tag name is used. For example:
* `<f:image />`
*
* Though the JSX spec allows this, it is disabled by default since React's
* JSX does not currently have support for it.
*
*/
throwIfNamespace?: boolean;
/**
* Toggles plugins that aid in development, such as @swc/plugin-transform-react-jsx-self
* and @swc/plugin-transform-react-jsx-source.
*
* Defaults to `false`,
*
*/
development?: boolean;
/**
* Use `Object.assign()` instead of `_extends`. Defaults to false.
* @deprecated
*/
useBuiltins?: boolean;
/**
* Enable fast refresh feature for React app
*/
refresh?: boolean;
/**
* jsx runtime
*/
runtime?: "automatic" | "classic";
/**
* Declares the module specifier to be used for importing the `jsx` and `jsxs` factory functions when using `runtime` 'automatic'
*/
importSource?: string;
}
/**
* - `import { DEBUG } from '@ember/env-flags';`
* - `import { FEATURE_A, FEATURE_B } from '@ember/features';`
*
* See: https://github.com/swc-project/swc/issues/18#issuecomment-466272558
*/
export interface ConstModulesConfig {
globals?: {
[module: string]: {
[name: string]: string;
};
};
}
/// https://swc.rs/docs/configuring-swc.html#jsctransformoptimizerjsonify
export interface OptimizerConfig {
/// https://swc.rs/docs/configuration/compilation#jsctransformoptimizersimplify
simplify?: boolean;
/// https://swc.rs/docs/configuring-swc.html#jsctransformoptimizerglobals
globals?: GlobalPassOption;
/// https://swc.rs/docs/configuring-swc.html#jsctransformoptimizerjsonify
jsonify?: { minCost: number };
}
/**
* Options for inline-global pass.
*/
export interface GlobalPassOption {
/**
* Global variables that should be inlined with passed value.
*
* e.g. `{ __DEBUG__: true }`
*/
vars?: Record<string, string>;
/**
* Names of environment variables that should be inlined with the value of corresponding env during build.
*
* Defaults to `["NODE_ENV", "SWC_ENV"]`
*/
envs?: string[] | Record<string, string>;
/**
* Replaces typeof calls for passed variables with corresponding value
*
* e.g. `{ window: 'object' }`
*/
typeofs?: Record<string, string>;
}
export type ModuleConfig =
| Es6Config
| CommonJsConfig
| UmdConfig
| AmdConfig
| NodeNextConfig
| SystemjsConfig;
export interface BaseModuleConfig {
/**
* By default, when using exports with babel a non-enumerable `__esModule`
* property is exported. In some cases this property is used to determine
* if the import is the default export or if it contains the default export.
*
* In order to prevent the __esModule property from being exported, you
* can set the strict option to true.
*
* Defaults to `false`.
*/
strict?: boolean;
/**
* Emits 'use strict' directive.
*
* Defaults to `true`.
*/
strictMode?: boolean;
/**
* Changes Babel's compiled import statements to be lazily evaluated when their imported bindings are used for the first time.
*
* This can improve initial load time of your module because evaluating dependencies up
* front is sometimes entirely un-necessary. This is especially the case when implementing
* a library module.
*