@rspack/core 1.0.12 → 1.0.13

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.
@@ -1,4 +1,4 @@
1
- import type { JsAssetInfo } from "@rspack/binding";
1
+ import type { JsAssetInfo, RawFuncUseCtx } from "@rspack/binding";
2
2
  import type { PathData } from "../Compilation";
3
3
  import type { Compiler } from "../Compiler";
4
4
  import type { Module } from "../Module";
@@ -548,6 +548,314 @@ export type ResolveOptions = {
548
548
  };
549
549
  /** Used to configure the Rspack module resolution */
550
550
  export type Resolve = ResolveOptions;
551
+ export type RuleSetCondition = string | RegExp | ((value: string) => boolean) | RuleSetConditions | RuleSetLogicalConditions;
552
+ export type RuleSetConditions = RuleSetCondition[];
553
+ export type RuleSetLogicalConditions = {
554
+ and?: RuleSetConditions;
555
+ or?: RuleSetConditions;
556
+ not?: RuleSetCondition;
557
+ };
558
+ export type RuleSetLoader = string;
559
+ export type RuleSetLoaderOptions = string | Record<string, any>;
560
+ export type RuleSetLoaderWithOptions = {
561
+ ident?: string;
562
+ loader: RuleSetLoader;
563
+ options?: RuleSetLoaderOptions;
564
+ };
565
+ export type RuleSetUseItem = RuleSetLoader | RuleSetLoaderWithOptions;
566
+ export type RuleSetUse = RuleSetUseItem | RuleSetUseItem[] | ((data: RawFuncUseCtx) => RuleSetUseItem[]);
567
+ /** Rule defines the conditions for matching a module and the behavior of handling those modules. */
568
+ export type RuleSetRule = {
569
+ /** Matches all modules that match this resource, and will match against Resource. */
570
+ test?: RuleSetCondition;
571
+ /** Excludes all modules that match this condition and will match against the absolute path of the resource */
572
+ exclude?: RuleSetCondition;
573
+ /** Matches all modules that match this condition against the absolute path of the resource */
574
+ include?: RuleSetCondition;
575
+ /** Matches all modules that match this resource, and will match against Resource */
576
+ issuer?: RuleSetCondition;
577
+ /** Matches all modules that match this resource, and will match against layer of the module that issued the current module. */
578
+ issuerLayer?: RuleSetCondition;
579
+ /** Matches all modules that match this resource, and will match against the category of the dependency that introduced the current module */
580
+ dependency?: RuleSetCondition;
581
+ /** Matches all modules that match this resource, and will match against Resource */
582
+ resource?: RuleSetCondition;
583
+ /** Matches all modules that match this resource against the Resource's fragment. */
584
+ resourceFragment?: RuleSetCondition;
585
+ /** Matches all modules that match this resource against the Resource's query. */
586
+ resourceQuery?: RuleSetCondition;
587
+ /** Matches all modules that match this resource, and will match against the Resource's mimetype. */
588
+ mimetype?: RuleSetCondition;
589
+ /** Matches all modules that match this resource, and will match against the Resource's scheme. */
590
+ scheme?: RuleSetCondition;
591
+ /** Allows you to match values of properties in the description file, typically package.json, to determine which modules a rule should apply to. */
592
+ descriptionData?: Record<string, RuleSetCondition>;
593
+ /** Used in conjunction with [import attributes](https://github.com/tc39/proposal-import-attributes). */
594
+ with?: Record<string, RuleSetCondition>;
595
+ /** Used to mark the type of the matching module, which affects how the module is handled by Rspack's built-in processing. */
596
+ type?: string;
597
+ /** Used to mark the layer of the matching module. */
598
+ layer?: string;
599
+ /** A loader name */
600
+ loader?: RuleSetLoader;
601
+ /** A loader options */
602
+ options?: RuleSetLoaderOptions;
603
+ /** An array to pass the Loader package name and its options. */
604
+ use?: RuleSetUse;
605
+ /**
606
+ * Parser options for the specific modules that matched by the rule conditions
607
+ * It will override the parser options in module.parser.
608
+ * @default {}
609
+ * */
610
+ parser?: Record<string, any>;
611
+ /**
612
+ * Generator options for the specific modules that matched by the rule conditions
613
+ * It will override the parser options in module.generator.
614
+ * @default {}
615
+ */
616
+ generator?: Record<string, any>;
617
+ /** Matches all modules that match this resource, and will match against Resource. */
618
+ resolve?: ResolveOptions;
619
+ /** Flag the module for side effects */
620
+ sideEffects?: boolean;
621
+ /** Specify loader category. */
622
+ enforce?: "pre" | "post";
623
+ /** A kind of Nested Rule, an array of Rules from which only the first matching Rule is used when the parent Rule matches. */
624
+ oneOf?: RuleSetRule[];
625
+ /** A kind of Nested Rule, an array of Rules that is also used when the parent Rule matches. */
626
+ rules?: RuleSetRule[];
627
+ };
628
+ /** A list of rules. */
629
+ export type RuleSetRules = ("..." | RuleSetRule | Falsy)[];
630
+ /**
631
+ * Options object for DataUrl condition.
632
+ * */
633
+ export type AssetParserDataUrlOptions = {
634
+ maxSize?: number | undefined;
635
+ };
636
+ /**
637
+ * Options object for DataUrl condition.
638
+ * */
639
+ export type AssetParserDataUrl = AssetParserDataUrlOptions;
640
+ /** Options object for `asset` modules. */
641
+ export type AssetParserOptions = {
642
+ /**
643
+ * It be used only for Asset Module scenarios.
644
+ * @default { maxSize: 8096 }
645
+ * */
646
+ dataUrlCondition?: AssetParserDataUrlOptions;
647
+ };
648
+ export type CssParserNamedExports = boolean;
649
+ /** Options object for `css` modules. */
650
+ export type CssParserOptions = {
651
+ /**
652
+ * Use ES modules named export for CSS exports.
653
+ * @default true
654
+ * */
655
+ namedExports?: CssParserNamedExports;
656
+ };
657
+ /** Options object for `css/auto` modules. */
658
+ export type CssAutoParserOptions = {
659
+ /**
660
+ * Use ES modules named export for CSS exports.
661
+ * @default true
662
+ * */
663
+ namedExports?: CssParserNamedExports;
664
+ };
665
+ /** Options object for `css/module` modules. */
666
+ export type CssModuleParserOptions = {
667
+ /**
668
+ * Use ES modules named export for CSS exports.
669
+ * @default true
670
+ * */
671
+ namedExports?: CssParserNamedExports;
672
+ };
673
+ type ExportsPresence = "error" | "warn" | "auto" | false;
674
+ export type JavascriptParserOptions = {
675
+ /**
676
+ * Specifies global mode for dynamic import.
677
+ * @default 'lazy'
678
+ * */
679
+ dynamicImportMode?: "eager" | "lazy" | "weak" | "lazy-once";
680
+ /**
681
+ * Specifies global preload for dynamic import.
682
+ * @default false
683
+ * */
684
+ dynamicImportPreload?: boolean | number;
685
+ /**
686
+ * Specifies global prefetch for dynamic import
687
+ * @default false
688
+ * */
689
+ dynamicImportPrefetch?: boolean | number;
690
+ /**
691
+ * Specifies global fetchPriority for dynamic import
692
+ * @default 'auto'
693
+ */
694
+ dynamicImportFetchPriority?: "low" | "high" | "auto";
695
+ /**
696
+ * Enable or disable evaluating import.meta.
697
+ * @default true
698
+ */
699
+ importMeta?: boolean;
700
+ /**
701
+ * Enable parsing of new URL() syntax.
702
+ * @default true
703
+ * */
704
+ url?: "relative" | boolean;
705
+ /**
706
+ * Enable warnings for full dynamic dependencies
707
+ * @default true
708
+ * */
709
+ exprContextCritical?: boolean;
710
+ /**
711
+ * Enable warnings for partial dynamic dependencies
712
+ * @default false
713
+ * */
714
+ wrappedContextCritical?: boolean;
715
+ /**
716
+ * Warn or error for using non-existent exports and conflicting re-exports.
717
+ * @default 'auto'
718
+ */
719
+ exportsPresence?: ExportsPresence;
720
+ /** Warn or error for using non-existent exports */
721
+ importExportsPresence?: ExportsPresence;
722
+ /** Warn or error for conflicting re-exports */
723
+ reexportExportsPresence?: ExportsPresence;
724
+ /** Emit errors instead of warnings when imported names don't exist in imported module. */
725
+ strictExportPresence?: boolean;
726
+ /** Provide custom syntax for Worker parsing, commonly used to support Worklet */
727
+ worker?: string[] | boolean;
728
+ /** Override the module to strict or non-strict. */
729
+ overrideStrict?: "strict" | "non-strict";
730
+ requireAsExpression?: boolean;
731
+ requireDynamic?: boolean;
732
+ requireResolve?: boolean;
733
+ importDynamic?: boolean;
734
+ };
735
+ /** Configure all parsers' options in one place with module.parser. */
736
+ export type ParserOptionsByModuleTypeKnown = {
737
+ /** Parser options for `asset` modules. */
738
+ asset?: AssetParserOptions;
739
+ /** Parser options for `css` modules. */
740
+ css?: CssParserOptions;
741
+ /** Parser options for `css/auto` modules. */
742
+ "css/auto"?: CssAutoParserOptions;
743
+ /** Parser options for `css/module` modules. */
744
+ "css/module"?: CssModuleParserOptions;
745
+ /** Parser options for `javascript` modules. */
746
+ javascript?: JavascriptParserOptions;
747
+ /** Parser options for `javascript/auto` modules. */
748
+ "javascript/auto"?: JavascriptParserOptions;
749
+ /** Parser options for `javascript/dynamic` modules. */
750
+ "javascript/dynamic"?: JavascriptParserOptions;
751
+ /** Parser options for `javascript/esm` modules. */
752
+ "javascript/esm"?: JavascriptParserOptions;
753
+ };
754
+ /** Configure all parsers' options in one place with module.parser. */
755
+ export type ParserOptionsByModuleTypeUnknown = {
756
+ [x: string]: Record<string, any>;
757
+ };
758
+ /** Configure all parsers' options in one place with module.parser. */
759
+ export type ParserOptionsByModuleType = ParserOptionsByModuleTypeKnown | ParserOptionsByModuleTypeUnknown;
760
+ export type AssetGeneratorDataUrlOptions = {
761
+ encoding?: false | "base64";
762
+ mimetype?: string;
763
+ };
764
+ export type AssetGeneratorDataUrlFunction = (options: {
765
+ filename: string;
766
+ content: string;
767
+ }) => string;
768
+ export type AssetGeneratorDataUrl = AssetGeneratorDataUrlOptions | AssetGeneratorDataUrlFunction;
769
+ /** Options for asset inline modules. */
770
+ export type AssetInlineGeneratorOptions = {
771
+ /** Only for modules with module type 'asset' or 'asset/inline'. */
772
+ dataUrl?: AssetGeneratorDataUrl;
773
+ };
774
+ /** Options for asset modules. */
775
+ export type AssetResourceGeneratorOptions = {
776
+ /**
777
+ * Whether to output assets to disk.
778
+ * @default true
779
+ * */
780
+ emit?: boolean;
781
+ /** This option determines the name of each asset resource output bundle.*/
782
+ filename?: Filename;
783
+ /** This option determines the URL prefix of the referenced 'asset' or 'asset/resource'*/
784
+ publicPath?: PublicPath;
785
+ };
786
+ /** Generator options for asset modules. */
787
+ export type AssetGeneratorOptions = AssetInlineGeneratorOptions & AssetResourceGeneratorOptions;
788
+ export type CssGeneratorExportsConvention = "as-is" | "camel-case" | "camel-case-only" | "dashes" | "dashes-only";
789
+ export type CssGeneratorExportsOnly = boolean;
790
+ export type CssGeneratorLocalIdentName = string;
791
+ export type CssGeneratorEsModule = boolean;
792
+ /** Generator options for css modules. */
793
+ export type CssGeneratorOptions = {
794
+ /**
795
+ * If true, only exports the identifier mappings from CSS into the output JavaScript files
796
+ * If false, generate stylesheets and embed them in the template.
797
+ */
798
+ exportsOnly?: CssGeneratorExportsOnly;
799
+ /** This configuration is available for improved ESM-CJS interoperability purposes. */
800
+ esModule?: CssGeneratorEsModule;
801
+ };
802
+ /** Generator options for css/auto modules. */
803
+ export type CssAutoGeneratorOptions = {
804
+ /**
805
+ * Customize how CSS export names are exported to javascript modules
806
+ * @default 'as-is'
807
+ * */
808
+ exportsConvention?: CssGeneratorExportsConvention;
809
+ /**
810
+ * If true, only exports the identifier mappings from CSS into the output JavaScript files
811
+ * If false, generate stylesheets and embed them in the template.
812
+ */
813
+ exportsOnly?: CssGeneratorExportsOnly;
814
+ /** Customize the format of the local class names generated for CSS modules */
815
+ localIdentName?: CssGeneratorLocalIdentName;
816
+ /** This configuration is available for improved ESM-CJS interoperability purposes. */
817
+ esModule?: CssGeneratorEsModule;
818
+ };
819
+ /** Generator options for css/module modules. */
820
+ export type CssModuleGeneratorOptions = CssAutoGeneratorOptions;
821
+ export type GeneratorOptionsByModuleTypeKnown = {
822
+ /** Generator options for asset modules. */
823
+ asset?: AssetGeneratorOptions;
824
+ /** Generator options for asset/inline modules. */
825
+ "asset/inline"?: AssetInlineGeneratorOptions;
826
+ /** Generator options for asset/resource modules. */
827
+ "asset/resource"?: AssetResourceGeneratorOptions;
828
+ /** Generator options for css modules. */
829
+ css?: CssGeneratorOptions;
830
+ /** Generator options for css/auto modules. */
831
+ "css/auto"?: CssAutoGeneratorOptions;
832
+ /** Generator options for css/module modules. */
833
+ "css/module"?: CssModuleGeneratorOptions;
834
+ };
835
+ export type GeneratorOptionsByModuleTypeUnknown = Record<string, Record<string, any>>;
836
+ /** Options for module.generator */
837
+ export type GeneratorOptionsByModuleType = GeneratorOptionsByModuleTypeKnown | GeneratorOptionsByModuleTypeUnknown;
838
+ type NoParseOptionSingle = string | RegExp | ((request: string) => boolean);
839
+ /** Options for module.noParse */
840
+ export type NoParseOption = NoParseOptionSingle | NoParseOptionSingle[];
841
+ export type ModuleOptions = {
842
+ /** Used to decide how to handle different types of modules in a project. */
843
+ defaultRules?: RuleSetRules;
844
+ /**
845
+ * An array of rules that match the module's requests when it is created.
846
+ * @default []
847
+ * */
848
+ rules?: RuleSetRules;
849
+ /**
850
+ * Configure all parsers' options in one place with module.parser.
851
+ * @default {}
852
+ * */
853
+ parser?: ParserOptionsByModuleType;
854
+ /** Configure all generators' options in one place with module.generator. */
855
+ generator?: GeneratorOptionsByModuleType;
856
+ /** Keep module mechanism of the matched modules as-is, such as module.exports, require, import. */
857
+ noParse?: NoParseOption;
858
+ };
551
859
  /**
552
860
  * Specify the default type of externals.
553
861
  * `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.