@rspack/core 0.7.0 → 0.7.1-canary-72a523f-20240530161839

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.
@@ -27,6 +27,11 @@
27
27
  },
28
28
  "layer": {
29
29
  "type": "string"
30
+ },
31
+ "defaultExport": {
32
+ "type": "boolean",
33
+ "description": "Duplicate the named export with CSS modules locals to the default export (only when `esModules: true` for css-loader).",
34
+ "link": "https://github.com/webpack-contrib/mini-css-extract-plugin#defaultexports"
30
35
  }
31
36
  }
32
37
  }
@@ -9,6 +9,7 @@ export interface CssExtractRspackLoaderOptions {
9
9
  emit?: boolean;
10
10
  esModule?: boolean;
11
11
  layer?: boolean;
12
+ defaultExport?: boolean;
12
13
  }
13
14
  declare const loader: LoaderDefinition;
14
15
  export declare const pitch: LoaderDefinition["pitch"];
@@ -133,16 +133,39 @@ const pitch = function (request, _, data) {
133
133
  callback(e);
134
134
  return;
135
135
  }
136
- const result = locals
137
- ? namedExport
138
- ? Object.keys(locals)
139
- .map(key => `\nexport var ${key} = ${(0, utils_1.stringifyLocal)(
140
- /** @type {Locals} */ locals[key])};`)
141
- .join("")
142
- : `\n${esModule ? "export default" : "module.exports ="} ${JSON.stringify(locals)};`
143
- : esModule
144
- ? `\nexport {};`
145
- : "";
136
+ const result = (function makeResult() {
137
+ if (locals) {
138
+ if (namedExport) {
139
+ const identifiers = Array.from((function* generateIdentifiers() {
140
+ let identifierId = 0;
141
+ for (const key of Object.keys(locals)) {
142
+ identifierId += 1;
143
+ yield [`_${identifierId.toString(16)}`, key];
144
+ }
145
+ })());
146
+ const localsString = identifiers
147
+ .map(([id, key]) => `\nvar ${id} = ${(0, utils_1.stringifyLocal)(
148
+ /** @type {Locals} */ locals[key])};`)
149
+ .join("");
150
+ const exportsString = `export { ${identifiers
151
+ .map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
152
+ .join(", ")} }`;
153
+ const defaultExport = typeof options.defaultExport !== "undefined"
154
+ ? options.defaultExport
155
+ : false;
156
+ return defaultExport
157
+ ? `${localsString}\n${exportsString}\nexport default { ${identifiers
158
+ .map(([id, key]) => `${JSON.stringify(key)}: ${id}`)
159
+ .join(", ")} }\n`
160
+ : `${localsString}\n${exportsString}\n`;
161
+ }
162
+ return `\n${esModule ? "export default" : "module.exports = "} ${JSON.stringify(locals)};`;
163
+ }
164
+ else if (esModule) {
165
+ return "\nexport {};";
166
+ }
167
+ return "";
168
+ })();
146
169
  let resultSource = `// extracted by ${index_1.CssExtractRspackPlugin.pluginName}`;
147
170
  // only attempt hotreloading if the css is actually used for something other than hash values
148
171
  resultSource +=
@@ -457,7 +457,15 @@ function getRawJavascriptParserOptions(parser) {
457
457
  ? parser.url
458
458
  : "true",
459
459
  exprContextCritical: parser.exprContextCritical ?? true,
460
- wrappedContextCritical: parser.wrappedContextCritical ?? false
460
+ wrappedContextCritical: parser.wrappedContextCritical ?? false,
461
+ exportsPresence: parser.exportsPresence === false ? "false" : parser.exportsPresence,
462
+ importExportsPresence: parser.importExportsPresence === false
463
+ ? "false"
464
+ : parser.importExportsPresence,
465
+ reexportExportsPresence: parser.reexportExportsPresence === false
466
+ ? "false"
467
+ : parser.reexportExportsPresence,
468
+ strictExportPresence: parser.strictExportPresence ?? false
461
469
  };
462
470
  }
463
471
  function getRawAssetParserOptions(parser) {
@@ -5,7 +5,7 @@ import { Compiler } from "../Compiler";
5
5
  import { Logger } from "../logging/Logger";
6
6
  import Hash = require("../util/hash");
7
7
  import { Compilation } from "../Compilation";
8
- import { Mode, Resolve, RuleSetUseItem } from "./zod";
8
+ import { Mode, Resolve, RuleSetUseItem, Target } from "./zod";
9
9
  export interface ComposeJsUseOptions {
10
10
  devtool: RawOptions["devtool"];
11
11
  context: RawOptions["context"];
@@ -76,6 +76,7 @@ export interface LoaderContext<OptionsType = {}> {
76
76
  */
77
77
  loaders: LoaderObject[];
78
78
  mode?: Mode;
79
+ target?: Target;
79
80
  hot?: boolean;
80
81
  /**
81
82
  * @param schema To provide the best performance, Rspack does not perform the schema validation. If your loader requires schema validation, please call scheme-utils or zod on your own.
@@ -82,6 +82,10 @@ const applyRspackOptionsDefaults = (options) => {
82
82
  : "var";
83
83
  });
84
84
  applyNodeDefaults(options.node, { targetProperties });
85
+ applyLoaderDefaults(options.loader, {
86
+ targetProperties,
87
+ environment: options.output.environment
88
+ });
85
89
  F(options, "performance", () => production &&
86
90
  targetProperties &&
87
91
  (targetProperties.browser || targetProperties.browser === null)
@@ -139,6 +143,10 @@ const applyJavascriptParserOptionsDefaults = (parserOptions, fallback) => {
139
143
  D(parserOptions, "url", fallback?.url ?? true);
140
144
  D(parserOptions, "exprContextCritical", fallback?.exprContextCritical ?? true);
141
145
  D(parserOptions, "wrappedContextCritical", fallback?.wrappedContextCritical ?? false);
146
+ D(parserOptions, "exportsPresence", fallback?.exportsPresence);
147
+ D(parserOptions, "importExportsPresence", fallback?.importExportsPresence);
148
+ D(parserOptions, "reexportExportsPresence", fallback?.reexportExportsPresence);
149
+ D(parserOptions, "strictExportPresence", fallback?.strictExportPresence ?? false);
142
150
  };
143
151
  const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
144
152
  (0, assertNotNil_1.assertNotNill)(module.parser);
@@ -600,6 +608,28 @@ const applyExternalsPresetsDefaults = (externalsPresets, { targetProperties }) =
600
608
  targetProperties.electron &&
601
609
  targetProperties.electronRenderer);
602
610
  };
611
+ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
612
+ F(loader, "target", () => {
613
+ if (targetProperties) {
614
+ if (targetProperties.electron) {
615
+ if (targetProperties.electronMain)
616
+ return "electron-main";
617
+ if (targetProperties.electronPreload)
618
+ return "electron-preload";
619
+ if (targetProperties.electronRenderer)
620
+ return "electron-renderer";
621
+ return "electron";
622
+ }
623
+ if (targetProperties.nwjs)
624
+ return "nwjs";
625
+ if (targetProperties.node)
626
+ return "node";
627
+ if (targetProperties.web)
628
+ return "web";
629
+ }
630
+ });
631
+ D(loader, "environment", environment);
632
+ };
603
633
  const applyNodeDefaults = (node, { targetProperties }) => {
604
634
  if (node === false)
605
635
  return;
@@ -8,7 +8,7 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type { Compilation } from "../Compilation";
11
- import type { AssetModuleFilename, Bail, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LazyCompilationOptions, LibraryOptions, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
11
+ import type { AssetModuleFilename, Bail, CacheOptions, ChunkFilename, ChunkLoading, ChunkLoadingGlobal, Clean, Context, CrossOriginLoading, CssChunkFilename, CssFilename, Dependencies, DevServer, DevTool, DevtoolFallbackModuleFilenameTemplate, DevtoolModuleFilenameTemplate, DevtoolNamespace, EnabledLibraryTypes, EnabledWasmLoadingTypes, EntryFilename, EntryRuntime, Environment, Externals, ExternalsPresets, ExternalsType, Filename, GeneratorOptionsByModuleType, GlobalObject, HashDigest, HashDigestLength, HashFunction, HashSalt, HotUpdateChunkFilename, HotUpdateGlobal, HotUpdateMainFilename, Iife, ImportFunctionName, InfrastructureLogging, LazyCompilationOptions, LibraryOptions, Loader, Mode, Name, Node, NoParseOption, Optimization, OutputModule, ParserOptionsByModuleType, Path, Performance, Plugins, Profile, PublicPath, Resolve, RspackFutureOptions, RspackOptions, RuleSetRules, ScriptType, SnapshotOptions, SourceMapFilename, StatsValue, StrictModuleErrorHandling, Target, TrustedTypes, UniqueName, WasmLoading, Watch, WatchOptions, WebassemblyModuleFilename, WorkerPublicPath } from "./zod";
12
12
  export declare const getNormalizedRspackOptions: (config: RspackOptions) => RspackOptionsNormalized;
13
13
  export type EntryDynamicNormalized = () => Promise<EntryStaticNormalized>;
14
14
  export type EntryNormalized = EntryDynamicNormalized | EntryStaticNormalized;
@@ -110,6 +110,7 @@ export interface RspackOptionsNormalized {
110
110
  infrastructureLogging: InfrastructureLogging;
111
111
  devtool?: DevTool;
112
112
  node: Node;
113
+ loader: Loader;
113
114
  snapshot: SnapshotOptions;
114
115
  cache?: CacheOptions;
115
116
  stats: StatsValue;
@@ -144,6 +144,7 @@ const getNormalizedRspackOptions = (config) => {
144
144
  node: nestedConfig(config.node, node => node && {
145
145
  ...node
146
146
  }),
147
+ loader: cloneObject(config.loader),
147
148
  snapshot: nestedConfig(config.snapshot, _snapshot => ({})),
148
149
  cache: optionalNestedConfig(config.cache, cache => cache),
149
150
  stats: nestedConfig(config.stats, stats => {