@rspack/core 1.0.8 → 1.0.10

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.
@@ -0,0 +1,529 @@
1
+ import type { JsAssetInfo } from "@rspack/binding";
2
+ import type { PathData } from "../Compilation";
3
+ import type { Compiler } from "../Compiler";
4
+ import type { Module } from "../Module";
5
+ import type { Chunk } from "../exports";
6
+ export type FilenameTemplate = string;
7
+ export type Filename = FilenameTemplate | ((pathData: PathData, assetInfo?: JsAssetInfo) => string);
8
+ /** Name of the configuration. Used when loading multiple configurations. */
9
+ export type Name = string;
10
+ /** A list of name defining all sibling configurations it depends on. Dependent configurations need to be compiled first. */
11
+ export type Dependencies = Name[];
12
+ /**
13
+ * The context configuration is used to set the base directory for Rspack builds.
14
+ * @default process.cwd()
15
+ * */
16
+ export type Context = string;
17
+ /**
18
+ * The mode configuration is used to set the build mode of Rspack to enable the default optimization strategy.
19
+ * @default 'production'
20
+ * */
21
+ export type Mode = "development" | "production" | "none";
22
+ export type Falsy = false | "" | 0 | null | undefined;
23
+ /** The publicPath of the resource referenced by this entry. */
24
+ export type PublicPath = "auto" | Filename;
25
+ /** The baseURI of the resource referenced by this entry. */
26
+ export type BaseUri = string;
27
+ /** How this entry load other chunks. */
28
+ export type ChunkLoadingType = string | "jsonp" | "import-scripts" | "require" | "async-node" | "import";
29
+ /** How this entry load other chunks. */
30
+ export type ChunkLoading = false | ChunkLoadingType;
31
+ /** Whether to create a load-on-demand asynchronous chunk for entry. */
32
+ export type AsyncChunks = boolean;
33
+ /** Option to set the method of loading WebAssembly Modules. */
34
+ export type WasmLoadingType = string | "fetch-streaming" | "fetch" | "async-node";
35
+ /** Option to set the method of loading WebAssembly Modules. */
36
+ export type WasmLoading = false | WasmLoadingType;
37
+ export type ScriptType = false | "text/javascript" | "module";
38
+ export type LibraryCustomUmdObject = {
39
+ amd?: string;
40
+ commonjs?: string;
41
+ root?: string | string[];
42
+ };
43
+ /** Specify a name for the library. */
44
+ export type LibraryName = string | string[] | LibraryCustomUmdObject;
45
+ export type LibraryCustomUmdCommentObject = {
46
+ amd?: string;
47
+ commonjs?: string;
48
+ commonjs2?: string;
49
+ root?: string;
50
+ };
51
+ /** Use a container(defined in global space) for calling define/require functions in an AMD module. */
52
+ export type AmdContainer = string;
53
+ /** Add a comment in the UMD wrapper. */
54
+ export type AuxiliaryComment = string | LibraryCustomUmdCommentObject;
55
+ /** Specify which export should be exposed as a library. */
56
+ export type LibraryExport = string | string[];
57
+ /** Configure how the library will be exposed. */
58
+ export type LibraryType = string | "var" | "module" | "assign" | "assign-properties" | "this" | "window" | "self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "commonjs-static" | "amd" | "amd-require" | "umd" | "umd2" | "jsonp" | "system";
59
+ /** When using output.library.type: "umd", setting output.library.umdNamedDefine to true will name the AMD module of the UMD build. */
60
+ export type UmdNamedDefine = boolean;
61
+ /** Options for library. */
62
+ export type LibraryOptions = {
63
+ /** Use a container(defined in global space) for calling define/require functions in an AMD module. */
64
+ amdContainer?: AmdContainer;
65
+ /** Add a comment in the UMD wrapper. */
66
+ auxiliaryComment?: AuxiliaryComment;
67
+ /** Specify which export should be exposed as a library. */
68
+ export?: LibraryExport;
69
+ /** Specify a name for the library. */
70
+ name?: LibraryName;
71
+ /** Configure how the library will be exposed. */
72
+ type: LibraryType;
73
+ /**
74
+ * When using output.library.type: "umd", setting output.library.umdNamedDefine to true will name the AMD module of the UMD build.
75
+ * Otherwise, an anonymous define is used.
76
+ * */
77
+ umdNamedDefine?: UmdNamedDefine;
78
+ };
79
+ /** Options for library. */
80
+ export type Library = LibraryName | LibraryOptions | undefined;
81
+ /** The layer of this entry. */
82
+ export type Layer = string | null;
83
+ /** The filename of the entry chunk. */
84
+ export type EntryFilename = Filename;
85
+ /** The name of the runtime chunk. */
86
+ export type EntryRuntime = false | string;
87
+ /** The path to the entry module. */
88
+ export type EntryItem = string | string[];
89
+ /** The entry that the current entry depends on. With dependOn option you can share the modules from one entry chunk to another. */
90
+ export type EntryDependOn = string | string[];
91
+ export type EntryDescription = {
92
+ /**
93
+ * The path to the entry module.
94
+ * @default './src/index.js'
95
+ * */
96
+ import: EntryItem;
97
+ /**
98
+ * The name of the runtime chunk.
99
+ * When runtime is set, a new runtime chunk will be created.
100
+ * You can also set it to false to avoid a new runtime chunk.
101
+ * */
102
+ runtime?: EntryRuntime;
103
+ /** The publicPath of the resource referenced by this entry. */
104
+ publicPath?: PublicPath;
105
+ /** The baseURI of the resource referenced by this entry. */
106
+ baseUri?: BaseUri;
107
+ /** How this entry load other chunks. */
108
+ chunkLoading?: ChunkLoading;
109
+ /** Whether to create a load-on-demand asynchronous chunk for this entry. */
110
+ asyncChunks?: AsyncChunks;
111
+ /** Option to set the method of loading WebAssembly Modules. */
112
+ wasmLoading?: WasmLoading;
113
+ /** The filename of the entry chunk. */
114
+ filename?: EntryFilename;
115
+ /** The format of the chunk generated by this entry as a library. */
116
+ library?: LibraryOptions;
117
+ /** The entry that the current entry depends on. With dependOn option you can share the modules from one entry chunk to another. */
118
+ dependOn?: EntryDependOn;
119
+ /** The layer of this entry, make the corresponding configuration take effect through layer matching in SplitChunks, Rules, Stats, and Externals. */
120
+ layer?: Layer;
121
+ };
122
+ export type EntryUnnamed = EntryItem;
123
+ export type EntryObject = Record<string, EntryItem | EntryDescription>;
124
+ /** A static entry. */
125
+ export type EntryStatic = EntryObject | EntryUnnamed;
126
+ /** A Function returning entry options. */
127
+ export type EntryDynamic = () => EntryStatic | Promise<EntryStatic>;
128
+ /** The entry options for building */
129
+ export type Entry = EntryStatic | EntryDynamic;
130
+ /**
131
+ * Path alias
132
+ * @example
133
+ * ```js
134
+ * {
135
+ * "@": path.resolve(__dirname, './src'),
136
+ * "abc$": path.resolve(__dirname, './node_modules/abc/index.js'),
137
+ * }
138
+ * // - require("@/a") will attempt to resolve <root>/src/a.
139
+ * // - require("abc") will attempt to resolve <root>/src/abc.
140
+ * // - require("abc/file.js") will not match, and it will attempt to resolve node_modules/abc/file.js.
141
+ * ```
142
+ * */
143
+ export type ResolveAlias = {
144
+ [x: string]: string | false | (string | false)[];
145
+ };
146
+ /** The replacement of [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin) in Rspack. */
147
+ export type ResolveTsConfig = string | {
148
+ configFile: string;
149
+ references?: string[] | "auto" | undefined;
150
+ };
151
+ /** Used to configure the Rspack module resolution */
152
+ export type ResolveOptions = {
153
+ /** Path alias */
154
+ alias?: ResolveAlias;
155
+ /** Same as node's [conditionNames](https://nodejs.org/api/packages.html#conditional-exports) for the exports and imports fields in package.json. */
156
+ conditionNames?: string[];
157
+ /**
158
+ * Parse modules in order.
159
+ * @default [".js", ".json", ".wasm"]
160
+ * */
161
+ extensions?: string[];
162
+ /** Redirect module requests when normal resolving fails. */
163
+ fallback?: ResolveAlias;
164
+ /** Try to parse the fields in package.json */
165
+ mainFields?: string[];
166
+ /**
167
+ * The filename suffix when resolving directories, e.g. require('. /dir/') will try to resolve '. /dir/index'.
168
+ * @default ['index']
169
+ */
170
+ mainFiles?: string[];
171
+ /**
172
+ * The name of the directory to use when resolving dependencies.
173
+ * @default ["node_modules"]
174
+ */
175
+ modules?: string[];
176
+ /**
177
+ * When enabled, require('file') will first look for the . /file file in the current directory, not <modules>/file.
178
+ * @default false
179
+ */
180
+ preferRelative?: boolean;
181
+ /**
182
+ * Opt for absolute paths when resolving, in relation to resolve.roots.
183
+ * @default false
184
+ */
185
+ preferAbsolute?: boolean;
186
+ /**
187
+ * Whether to resolve symlinks to their symlinked location.
188
+ * @default true
189
+ */
190
+ symlinks?: boolean;
191
+ /**
192
+ * By default, It changes to true if resolve.extensions contains an empty string;
193
+ * otherwise, this value changes to false.
194
+ */
195
+ enforceExtension?: boolean;
196
+ /**
197
+ * Customize the imports field in package.json which are used to provide the internal requests of a package (requests starting with # are considered internal).
198
+ * @default ["imports"]
199
+ */
200
+ importsFields?: string[];
201
+ /**
202
+ * The JSON files to use for descriptions.
203
+ * @default ['package.json']
204
+ */
205
+ descriptionFiles?: string[];
206
+ /** The replacement of [tsconfig-paths-webpack-plugin](https://www.npmjs.com/package/tsconfig-paths-webpack-plugin) in Rspack. */
207
+ tsConfig?: ResolveTsConfig;
208
+ /**
209
+ * No longer resolve extensions, no longer resolve mainFiles in package.json (but does not affect requests from mainFiles, browser, alias).
210
+ * @default false
211
+ * */
212
+ fullySpecified?: boolean;
213
+ /**
214
+ * Customize the exports field in package.json.
215
+ * @default ["exports"]
216
+ * */
217
+ exportsFields?: string[];
218
+ /** Define alias for the extension. */
219
+ extensionAlias?: Record<string, string | string[]>;
220
+ /**
221
+ * Define a field, such as browser, that should be parsed in accordance with this [specification](https://github.com/defunctzombie/package-browser-field-spec).
222
+ * @default ['browser']
223
+ * */
224
+ aliasFields?: string[];
225
+ /**
226
+ * A list of resolve restrictions to restrict the paths that a request can be resolved on.
227
+ * @default []
228
+ * */
229
+ restrictions?: string[];
230
+ /**
231
+ * A list of directories where server-relative URLs (beginning with '/') are resolved.
232
+ * It defaults to the context configuration option.
233
+ * On systems other than Windows, these requests are initially resolved as an absolute path.
234
+ * @default []
235
+ */
236
+ roots?: string[];
237
+ /** Customize the Resolve configuration based on the module type. */
238
+ byDependency?: Record<string, ResolveOptions>;
239
+ };
240
+ /** Used to configure the Rspack module resolution */
241
+ export type Resolve = ResolveOptions;
242
+ /**
243
+ * Specify the default type of externals.
244
+ * `amd`, `umd`, `system` and `jsonp` externals depend on the `output.libraryTarget` being set to the same value e.g. you can only consume amd externals within an amd library.
245
+ * @default 'var'
246
+ */
247
+ export type ExternalsType = "var" | "module" | "assign" | "this" | "window" | "self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "commonjs-static" | "amd" | "amd-require" | "umd" | "umd2" | "jsonp" | "system" | "promise" | "import" | "module-import" | "script" | "node-commonjs";
248
+ /**
249
+ * The dependency used for the external.
250
+ */
251
+ export type ExternalItemValue = string | boolean | string[] | Record<string, string | string[]>;
252
+ /**
253
+ * If an dependency matches exactly a property of the object, the property value is used as dependency.
254
+ */
255
+ export type ExternalItemObjectUnknown = {
256
+ [x: string]: ExternalItemValue;
257
+ };
258
+ /**
259
+ * Data object passed as argument when a function is set for 'externals'.
260
+ */
261
+ export type ExternalItemFunctionData = {
262
+ context?: string;
263
+ dependencyType?: string;
264
+ request?: string;
265
+ contextInfo?: {
266
+ issuer: string;
267
+ };
268
+ };
269
+ /**
270
+ * Prevent bundling of certain imported package and instead retrieve these external dependencies at runtime.
271
+ *
272
+ * @example
273
+ * ```js
274
+ * // jquery lib will be excluded from bundling.
275
+ * module.exports = {
276
+ * externals: {
277
+ * jquery: 'jQuery',
278
+ * }
279
+ * }
280
+ * ```
281
+ * */
282
+ export type ExternalItem = string | RegExp | ExternalItemObjectUnknown | ((data: ExternalItemFunctionData, callback: (err?: Error, result?: ExternalItemValue, type?: ExternalsType) => void) => void) | ((data: ExternalItemFunctionData) => Promise<ExternalItemValue>);
283
+ /**
284
+ * Prevent bundling of certain imported packages and instead retrieve these external dependencies at runtime.
285
+ *
286
+ * @example
287
+ * ```js
288
+ * // jquery lib will be excluded from bundling.
289
+ * module.exports = {
290
+ * externals: {
291
+ * jquery: 'jQuery',
292
+ * }
293
+ * }
294
+ * ```
295
+ * */
296
+ export type Externals = ExternalItem | ExternalItem[];
297
+ export interface RspackPluginInstance {
298
+ apply: (compiler: Compiler) => void;
299
+ [k: string]: any;
300
+ }
301
+ export type RspackPluginFunction = (this: Compiler, compiler: Compiler) => void;
302
+ export type WebpackCompiler = any;
303
+ export interface WebpackPluginInstance {
304
+ apply: (compiler: WebpackCompiler) => void;
305
+ [k: string]: any;
306
+ }
307
+ export type WebpackPluginFunction = (this: WebpackCompiler, compiler: WebpackCompiler) => void;
308
+ export type Plugin = RspackPluginInstance | RspackPluginFunction | WebpackPluginInstance | WebpackPluginFunction | Falsy;
309
+ export type Plugins = Plugin[];
310
+ /** Used to control how the runtime chunk is generated. */
311
+ export type OptimizationRuntimeChunk = boolean | "single" | "multiple" | {
312
+ name?: string | ((value: {
313
+ name: string;
314
+ }) => string);
315
+ };
316
+ export type OptimizationSplitChunksNameFunction = (module?: Module) => unknown;
317
+ type OptimizationSplitChunksName = string | false | OptimizationSplitChunksNameFunction;
318
+ type OptimizationSplitChunksSizes = number | Record<string, number>;
319
+ type OptimizationSplitChunksChunks = "initial" | "async" | "all" | RegExp | ((chunk: Chunk) => boolean);
320
+ type SharedOptimizationSplitChunksCacheGroup = {
321
+ /**
322
+ * This indicates which chunks will be selected for optimization.
323
+ * @default 'async''
324
+ * */
325
+ chunks?: OptimizationSplitChunksChunks;
326
+ /** Sets the size types which are used when a number is used for sizes. */
327
+ defaultSizeTypes?: string[];
328
+ /**
329
+ * The minimum times must a module be shared among chunks before splitting.
330
+ * @default 1
331
+ */
332
+ minChunks?: number;
333
+ /**
334
+ * Enabling this, the splitting of chunks will be grouped based on the usage of modules exports in different runtimes,
335
+ * ensuring the optimal loading size in each runtime.
336
+ */
337
+ usedExports?: boolean;
338
+ /**
339
+ * The name of the split chunk.
340
+ * @default false
341
+ * */
342
+ name?: false | OptimizationSplitChunksName;
343
+ /**
344
+ * Minimum size, in bytes, for a chunk to be generated.
345
+ *
346
+ * The value is `20000` in production mode.
347
+ * The value is `10000` in others mode.
348
+ */
349
+ minSize?: OptimizationSplitChunksSizes;
350
+ /** Maximum size, in bytes, for a chunk to be generated. */
351
+ maxSize?: OptimizationSplitChunksSizes;
352
+ /** Maximum size, in bytes, for a async chunk to be generated. */
353
+ maxAsyncSize?: OptimizationSplitChunksSizes;
354
+ /** Maximum size, in bytes, for a initial chunk to be generated. */
355
+ maxInitialSize?: OptimizationSplitChunksSizes;
356
+ /**
357
+ * Maximum number of parallel requests when on-demand loading.
358
+ * @default 30
359
+ * */
360
+ maxAsyncRequests?: number;
361
+ /**
362
+ * Maximum number of parallel requests at an entry point.
363
+ * @default 30
364
+ */
365
+ maxInitialRequests?: number;
366
+ /**
367
+ * Tell Rspack what delimiter to use for the generated names.
368
+ *
369
+ * @default '-''
370
+ */
371
+ automaticNameDelimiter?: string;
372
+ };
373
+ /** How to splitting chunks. */
374
+ export type OptimizationSplitChunksCacheGroup = {
375
+ /** Controls which modules are selected by this cache group. */
376
+ test?: string | RegExp | ((module: Module) => unknown);
377
+ /**
378
+ * A module can belong to multiple cache groups.
379
+ * @default -20
380
+ */
381
+ priority?: number;
382
+ /**
383
+ * Tells Rspack to ignore `splitChunks.minSize`, `splitChunks.minChunks`, `splitChunks.maxAsyncRequests` and `splitChunks.maxInitialRequests` options and always create chunks for this cache group.
384
+ */
385
+ enforce?: boolean;
386
+ /** Allows to override the filename when and only when it's an initial chunk. */
387
+ filename?: string;
388
+ /**
389
+ * Whether to reuse existing chunks when possible.
390
+ * @default false
391
+ * */
392
+ reuseExistingChunk?: boolean;
393
+ /** Allows to assign modules to a cache group by module type. */
394
+ type?: string | RegExp;
395
+ /** Sets the hint for chunk id. It will be added to chunk's filename. */
396
+ idHint?: string;
397
+ } & SharedOptimizationSplitChunksCacheGroup;
398
+ /** Tell Rspack how to splitting chunks. */
399
+ export type OptimizationSplitChunksOptions = {
400
+ /**
401
+ * Options for module cache group
402
+ * */
403
+ cacheGroups?: Record<string, false | OptimizationSplitChunksCacheGroup>;
404
+ /**
405
+ * Options for modules not selected by any other group.
406
+ */
407
+ fallbackCacheGroup?: {
408
+ chunks?: OptimizationSplitChunksChunks;
409
+ minSize?: number;
410
+ maxSize?: number;
411
+ maxAsyncSize?: number;
412
+ maxInitialSize?: number;
413
+ automaticNameDelimiter?: string;
414
+ };
415
+ /**
416
+ * Prevents exposing path info when creating names for parts splitted by maxSize.
417
+ *
418
+ * The value is `true` in production mode.
419
+ * The value is `false` in development mode.
420
+ * */
421
+ hidePathInfo?: boolean;
422
+ } & SharedOptimizationSplitChunksCacheGroup;
423
+ export type Optimization = {
424
+ /**
425
+ * Which algorithm to use when choosing module ids.
426
+ */
427
+ moduleIds?: "named" | "natural" | "deterministic";
428
+ /**
429
+ * Which algorithm to use when choosing chunk ids.
430
+ */
431
+ chunkIds?: "natural" | "named" | "deterministic";
432
+ /**
433
+ * Whether to minimize the bundle.
434
+ * The value is `true` in production mode.
435
+ * The value is `false` in development mode.
436
+ */
437
+ minimize?: boolean;
438
+ /**
439
+ * Customize the minimizer.
440
+ * By default, `rspack.SwcJsMinimizerRspackPlugin` and `rspack.LightningCssMinimizerRspackPlugin` are used.
441
+ */
442
+ minimizer?: Array<"..." | Plugin>;
443
+ /**
444
+ * Whether to merge chunks which contain the same modules.
445
+ * Setting optimization.mergeDuplicateChunks to false will disable this optimization.
446
+ * @default true
447
+ */
448
+ mergeDuplicateChunks?: boolean;
449
+ /**
450
+ * Support splitting chunks.
451
+ * It is enabled by default for dynamically imported modules.
452
+ * To turn it off, set it to false.
453
+ * */
454
+ splitChunks?: false | OptimizationSplitChunksOptions;
455
+ /**
456
+ * Used to control how the runtime chunk is generated.
457
+ * Setting it to true or 'multiple' will add an additional chunk containing only the runtime for each entry point.
458
+ * Setting it to 'single' will extract the runtime code of all entry points into a single separate chunk.
459
+ * @default false
460
+ */
461
+ runtimeChunk?: OptimizationRuntimeChunk;
462
+ /** Detect and remove modules from chunks these modules are already included in all parents. */
463
+ removeAvailableModules?: boolean;
464
+ /**
465
+ * Remove empty chunks generated in the compilation.
466
+ * @default true
467
+ * */
468
+ removeEmptyChunks?: boolean;
469
+ /**
470
+ * Adds an additional hash compilation pass after the assets have been processed to get the correct asset content hashes.
471
+ *
472
+ * The value is `true` in production mode.
473
+ * The value is `false` in development mode.
474
+ */
475
+ realContentHash?: boolean;
476
+ /**
477
+ * Tells Rspack to recognise the sideEffects flag in package.json or rules to skip over modules which are flagged to contain no side effects when exports are not used.
478
+ *
479
+ * The value is `true` in production mode.
480
+ * The value is `false` in development mode.
481
+ * */
482
+ sideEffects?: "flag" | boolean;
483
+ /**
484
+ * After enabling, Rspack will analyze which exports the module provides, including re-exported modules.
485
+ * @default true
486
+ * */
487
+ providedExports?: boolean;
488
+ /**
489
+ * Tells Rspack to find segments of the module graph which can be safely concatenated into a single module.
490
+ *
491
+ * The value is `true` in production mode.
492
+ * The value is `false` in development mode.
493
+ */
494
+ concatenateModules?: boolean;
495
+ /**
496
+ * Tells Rspack whether to perform a more detailed analysis of variable assignments.
497
+ *
498
+ * The value is `true` in production mode.
499
+ * The value is `false` in development mode.
500
+ */
501
+ innerGraph?: boolean;
502
+ /**
503
+ * Tells Rspack to determine used exports for each module.
504
+ *
505
+ * The value is `true` in production mode.
506
+ * The value is `false` in development mode.
507
+ * */
508
+ usedExports?: "global" | boolean;
509
+ /**
510
+ * Allows to control export mangling.
511
+ *
512
+ * The value is `isdeterministic` in production mode.
513
+ * The value is `false` in development mode.
514
+ */
515
+ mangleExports?: "size" | "deterministic" | boolean;
516
+ /**
517
+ * Tells Rspack to set process.env.NODE_ENV to a given string value.
518
+ * @default false
519
+ */
520
+ nodeEnv?: string | false;
521
+ /**
522
+ * Emit assets whenever there are errors while compiling.
523
+ *
524
+ * The value is `false` in production mode.
525
+ * The value is `true` in development mode.
526
+ * */
527
+ emitOnErrors?: boolean;
528
+ };
529
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //#endregion