@rspack/core 0.5.9-canary-8778e17-20240403045016 → 0.5.9-canary-6952f10-20240405010847

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.
@@ -90,6 +90,7 @@ export declare class Compilation {
90
90
  ExecuteModuleContext
91
91
  ]>;
92
92
  runtimeModule: liteTapable.SyncHook<[JsRuntimeModule, Chunk], void>;
93
+ afterSeal: liteTapable.AsyncSeriesHook<[], void>;
93
94
  };
94
95
  options: RspackOptionsNormalized;
95
96
  outputOptions: OutputNormalized;
@@ -154,7 +154,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
154
154
  statsPrinter: new tapable.SyncHook(["statsPrinter", "options"]),
155
155
  buildModule: new liteTapable.SyncHook(["module"]),
156
156
  executeModule: new liteTapable.SyncHook(["options", "context"]),
157
- runtimeModule: new liteTapable.SyncHook(["module", "chunk"])
157
+ runtimeModule: new liteTapable.SyncHook(["module", "chunk"]),
158
+ afterSeal: new liteTapable.AsyncSeriesHook([])
158
159
  };
159
160
  this.compiler = compiler;
160
161
  this.resolverFactory = compiler.resolverFactory;
@@ -42,7 +42,6 @@ declare class Compiler {
42
42
  };
43
43
  compilation?: Compilation;
44
44
  compilationParams?: CompilationParams;
45
- first: boolean;
46
45
  builtinPlugins: binding.BuiltinPlugin[];
47
46
  root: Compiler;
48
47
  running: boolean;
@@ -110,14 +109,10 @@ declare class Compiler {
110
109
  getInfrastructureLogger(name: string | Function): Logger;
111
110
  run(callback: Callback<Error, Stats>): void;
112
111
  /**
113
- * Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
112
+ * * Note: This is not a webpack public API, maybe removed in future.
113
+ * @internal
114
114
  */
115
- build(callback?: (error: Error | null) => void): void;
116
- /**
117
- * Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
118
- * @deprecated This is a low-level incremental rebuild API, which shouldn't be used intentionally. Use `compiler.build` instead.
119
- */
120
- rebuild(modifiedFiles?: ReadonlySet<string>, removedFiles?: ReadonlySet<string>, callback?: (error: Error | null) => void): void;
115
+ __internal__rebuild(modifiedFiles?: ReadonlySet<string>, removedFiles?: ReadonlySet<string>, callback?: (error: Error | null) => void): void;
121
116
  compile(callback: Callback<Error, Compilation>): void;
122
117
  watch(watchOptions: WatchOptions, handler: Callback<Error, Stats>): Watching;
123
118
  purgeInputFileSystem(): void;
package/dist/Compiler.js CHANGED
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _Compiler_instances, _Compiler_instance, _Compiler_disabledHooks, _Compiler_nonSkippableRegisters, _Compiler_registers, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateNonSkippableRegisters, _Compiler_decorateJsTaps, _Compiler_createHookRegisterTaps, _Compiler_createHookMapRegisterTaps, _Compiler_createCompilation, _Compiler_resetThisCompilation, _Compiler_newCompilationParams;
39
+ var _Compiler_instances, _Compiler_instance, _Compiler_initial, _Compiler_disabledHooks, _Compiler_nonSkippableRegisters, _Compiler_registers, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateNonSkippableRegisters, _Compiler_decorateJsTaps, _Compiler_createHookRegisterTaps, _Compiler_createHookMapRegisterTaps, _Compiler_build, _Compiler_createCompilation, _Compiler_resetThisCompilation, _Compiler_newCompilationParams;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compiler = void 0;
42
42
  /**
@@ -69,7 +69,6 @@ const NormalModuleFactory_1 = require("./NormalModuleFactory");
69
69
  const bindingVersionCheck_1 = require("./util/bindingVersionCheck");
70
70
  const Watching_1 = require("./Watching");
71
71
  const builtin_plugin_1 = require("./builtin-plugin");
72
- const rspackOptionsApply_1 = require("./rspackOptionsApply");
73
72
  const defaults_1 = require("./config/defaults");
74
73
  const assertNotNil_1 = require("./util/assertNotNil");
75
74
  const RuntimeGlobals_1 = require("./RuntimeGlobals");
@@ -84,7 +83,7 @@ class Compiler {
84
83
  _Compiler_instance.set(this, void 0);
85
84
  this.webpack = index_1.rspack;
86
85
  // TODO: remove this after remove rebuild on the rust side.
87
- this.first = true;
86
+ _Compiler_initial.set(this, true);
88
87
  _Compiler_disabledHooks.set(this, void 0);
89
88
  _Compiler_nonSkippableRegisters.set(this, void 0);
90
89
  _Compiler_registers.set(this, void 0);
@@ -386,36 +385,10 @@ class Compiler {
386
385
  }
387
386
  }
388
387
  /**
389
- * Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
388
+ * * Note: This is not a webpack public API, maybe removed in future.
389
+ * @internal
390
390
  */
391
- build(callback) {
392
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_getInstance).call(this, (error, instance) => {
393
- if (error) {
394
- return callback === null || callback === void 0 ? void 0 : callback(error);
395
- }
396
- if (!this.first) {
397
- instance.rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
398
- if (error) {
399
- return callback === null || callback === void 0 ? void 0 : callback(error);
400
- }
401
- callback === null || callback === void 0 ? void 0 : callback(null);
402
- });
403
- return;
404
- }
405
- this.first = false;
406
- instance.build(error => {
407
- if (error) {
408
- return callback === null || callback === void 0 ? void 0 : callback(error);
409
- }
410
- callback === null || callback === void 0 ? void 0 : callback(null);
411
- });
412
- });
413
- }
414
- /**
415
- * Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
416
- * @deprecated This is a low-level incremental rebuild API, which shouldn't be used intentionally. Use `compiler.build` instead.
417
- */
418
- rebuild(modifiedFiles, removedFiles, callback) {
391
+ __internal__rebuild(modifiedFiles, removedFiles, callback) {
419
392
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_getInstance).call(this, (error, instance) => {
420
393
  if (error) {
421
394
  return callback === null || callback === void 0 ? void 0 : callback(error);
@@ -437,7 +410,7 @@ class Compiler {
437
410
  }
438
411
  this.hooks.compile.call(params);
439
412
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_resetThisCompilation).call(this);
440
- this.build(err => {
413
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_build).call(this, err => {
441
414
  if (err) {
442
415
  return callback(err);
443
416
  }
@@ -470,7 +443,7 @@ class Compiler {
470
443
  }
471
444
  close(callback) {
472
445
  if (this.watching) {
473
- // When there is still an active watching, close this first
446
+ // When there is still an active watching, close this #initial
474
447
  this.watching.close(() => {
475
448
  this.close(callback);
476
449
  });
@@ -497,7 +470,7 @@ class Compiler {
497
470
  }
498
471
  }
499
472
  exports.Compiler = Compiler;
500
- _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Compiler_nonSkippableRegisters = new WeakMap(), _Compiler_registers = new WeakMap(), _Compiler_moduleExecutionResultsMap = new WeakMap(), _Compiler_instances = new WeakSet(), _Compiler_getInstance = function _Compiler_getInstance(callback) {
473
+ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Compiler_nonSkippableRegisters = new WeakMap(), _Compiler_registers = new WeakMap(), _Compiler_moduleExecutionResultsMap = new WeakMap(), _Compiler_instances = new WeakSet(), _Compiler_getInstance = function _Compiler_getInstance(callback) {
501
474
  const error = (0, bindingVersionCheck_1.checkVersion)();
502
475
  if (error) {
503
476
  return callback(error);
@@ -506,10 +479,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
506
479
  return callback(null, __classPrivateFieldGet(this, _Compiler_instance, "f"));
507
480
  }
508
481
  const options = this.options;
509
- // TODO: remove this in v0.6
510
- if (!options.experiments.rspackFuture.disableApplyEntryLazily) {
511
- (0, rspackOptionsApply_1.applyEntryOptions)(this, options);
512
- }
513
482
  // TODO: remove this when drop support for builtins options
514
483
  options.builtins = (0, builtin_plugin_1.deprecated_resolveBuiltins)(options.builtins, options);
515
484
  const rawOptions = (0, config_1.getRawOptions)(options, this);
@@ -599,6 +568,7 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
599
568
  registerCompilationChunkAssetTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationChunkAsset, () => this.compilation.hooks.chunkAsset, queried => ({ chunk, filename }) => queried.call(Chunk_1.Chunk.__from_binding(chunk, this.compilation), filename)),
600
569
  registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationProcessAssets, () => this.compilation.hooks.processAssets, queried => async () => await queried.promise(this.compilation.assets)),
601
570
  registerCompilationAfterProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterProcessAssets, () => this.compilation.hooks.afterProcessAssets, queried => () => queried.call(this.compilation.assets)),
571
+ registerCompilationAfterSealTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationAfterSeal, () => this.compilation.hooks.afterSeal, queried => async () => await queried.promise()),
602
572
  registerNormalModuleFactoryBeforeResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.NormalModuleFactoryBeforeResolve, () => this.compilationParams.normalModuleFactory.hooks.beforeResolve, queried => async (resolveData) => {
603
573
  const normalizedResolveData = {
604
574
  request: resolveData.request,
@@ -751,6 +721,28 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
751
721
  getTaps.registerKind = registerKind;
752
722
  getTaps.getHookMap = getHookMap;
753
723
  return getTaps;
724
+ }, _Compiler_build = function _Compiler_build(callback) {
725
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_getInstance).call(this, (error, instance) => {
726
+ if (error) {
727
+ return callback === null || callback === void 0 ? void 0 : callback(error);
728
+ }
729
+ if (!__classPrivateFieldGet(this, _Compiler_initial, "f")) {
730
+ instance.rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
731
+ if (error) {
732
+ return callback === null || callback === void 0 ? void 0 : callback(error);
733
+ }
734
+ callback === null || callback === void 0 ? void 0 : callback(null);
735
+ });
736
+ return;
737
+ }
738
+ __classPrivateFieldSet(this, _Compiler_initial, false, "f");
739
+ instance.build(error => {
740
+ if (error) {
741
+ return callback === null || callback === void 0 ? void 0 : callback(error);
742
+ }
743
+ callback === null || callback === void 0 ? void 0 : callback(null);
744
+ });
745
+ });
754
746
  }, _Compiler_createCompilation = function _Compiler_createCompilation(native) {
755
747
  const compilation = new Compilation_1.Compilation(this, native);
756
748
  compilation.name = this.name;
package/dist/Stats.js CHANGED
@@ -103,8 +103,8 @@ function normalizeStatsPreset(options) {
103
103
  }
104
104
  exports.normalizeStatsPreset = normalizeStatsPreset;
105
105
  function presetToOptions(name) {
106
- const pn = (typeof name === "string" && name.toLowerCase()) || name;
107
- switch (pn) {
106
+ const preset = (typeof name === "string" && name.toLowerCase()) || name;
107
+ switch (preset) {
108
108
  case "none":
109
109
  return {
110
110
  all: false
@@ -0,0 +1,10 @@
1
+ import { BuiltinPluginName } from "@rspack/binding";
2
+ export declare const CssModulesPlugin: {
3
+ new (): {
4
+ name: BuiltinPluginName;
5
+ _options: void;
6
+ affectedHooks: "make" | "compile" | "emit" | "afterEmit" | "invalid" | "done" | "thisCompilation" | "afterDone" | "compilation" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "run" | "assetEmitted" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | undefined;
7
+ raw(): import("@rspack/binding").BuiltinPlugin;
8
+ apply(compiler: import("../Compiler").Compiler): void;
9
+ };
10
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CssModulesPlugin = void 0;
4
+ const binding_1 = require("@rspack/binding");
5
+ const base_1 = require("./base");
6
+ exports.CssModulesPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.CssModulesPlugin, () => { }, "compilation");
@@ -9,6 +9,7 @@ export type EntryOptions = {
9
9
  baseUri?: string;
10
10
  filename?: FilenameTemplate;
11
11
  library?: LibraryOptions;
12
+ dependOn?: string[];
12
13
  };
13
14
  export declare const EntryPlugin: {
14
15
  new (context: string, entry: string, options?: string | EntryOptions | undefined): {
@@ -12,7 +12,7 @@ exports.EntryPlugin = (0, base_1.create)(binding_1.BuiltinPluginName.EntryPlugin
12
12
  entry,
13
13
  options: getRawEntryOptions(entryOptions)
14
14
  };
15
- });
15
+ }, "make");
16
16
  function getRawEntryOptions(entry) {
17
17
  const runtime = entry.runtime;
18
18
  const chunkLoading = entry.chunkLoading;
@@ -26,6 +26,7 @@ function getRawEntryOptions(entry) {
26
26
  : undefined,
27
27
  asyncChunks: entry.asyncChunks,
28
28
  filename: entry.filename,
29
- library: entry.library && (0, config_1.getRawLibrary)(entry.library)
29
+ library: entry.library && (0, config_1.getRawLibrary)(entry.library),
30
+ dependOn: entry.dependOn
30
31
  };
31
32
  }
@@ -4,7 +4,7 @@ export declare const ExternalsPlugin: {
4
4
  context?: string | undefined;
5
5
  dependencyType?: string | undefined;
6
6
  request?: string | undefined;
7
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "jsonp" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
7
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "global" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "jsonp" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
8
8
  context?: string | undefined;
9
9
  dependencyType?: string | undefined;
10
10
  request?: string | undefined;
@@ -12,7 +12,7 @@ export declare const ExternalsPlugin: {
12
12
  context?: string | undefined;
13
13
  dependencyType?: string | undefined;
14
14
  request?: string | undefined;
15
- }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "jsonp" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
15
+ }, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "script" | "commonjs" | "global" | "import" | "amd" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "jsonp" | "system" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
16
16
  context?: string | undefined;
17
17
  dependencyType?: string | undefined;
18
18
  request?: string | undefined;
@@ -46,19 +46,15 @@ export * from "./FlagDependencyUsagePlugin";
46
46
  export * from "./MangleExportsPlugin";
47
47
  export * from "./BundlerInfoRspackPlugin";
48
48
  export * from "./ModuleConcatenationPlugin";
49
+ export * from "./CssModulesPlugin";
49
50
  export * from "./HtmlRspackPlugin";
50
51
  export * from "./CopyRspackPlugin";
51
52
  export * from "./SwcJsMinimizerPlugin";
52
53
  export * from "./SwcCssMinimizerPlugin";
53
54
  export * from "./JsLoaderRspackPlugin";
54
- import { RawBuiltins, RawCssModulesConfig } from "@rspack/binding";
55
+ import { RawBuiltins } from "@rspack/binding";
55
56
  import { RspackOptionsNormalized } from "..";
56
- type BuiltinsCssConfig = {
57
- modules?: Partial<RawCssModulesConfig>;
58
- namedExports?: boolean;
59
- };
60
57
  export interface Builtins {
61
- css?: BuiltinsCssConfig;
62
58
  treeShaking?: boolean | "module";
63
59
  }
64
60
  export declare function deprecated_resolveBuiltins(builtins: Builtins, options: RspackOptionsNormalized): RawBuiltins;
@@ -64,6 +64,7 @@ __exportStar(require("./FlagDependencyUsagePlugin"), exports);
64
64
  __exportStar(require("./MangleExportsPlugin"), exports);
65
65
  __exportStar(require("./BundlerInfoRspackPlugin"), exports);
66
66
  __exportStar(require("./ModuleConcatenationPlugin"), exports);
67
+ __exportStar(require("./CssModulesPlugin"), exports);
67
68
  __exportStar(require("./HtmlRspackPlugin"), exports);
68
69
  __exportStar(require("./CopyRspackPlugin"), exports);
69
70
  __exportStar(require("./SwcJsMinimizerPlugin"), exports);
@@ -77,23 +78,8 @@ function resolveTreeShaking(treeShaking, production) {
77
78
  : "false";
78
79
  }
79
80
  function deprecated_resolveBuiltins(builtins, options) {
80
- var _a, _b;
81
81
  const production = options.mode === "production" || !options.mode;
82
82
  return {
83
- // TODO: discuss with webpack, this should move to css generator options
84
- css: options.experiments.css
85
- ? {
86
- modules: {
87
- localsConvention: "asIs",
88
- localIdentName: production
89
- ? "[hash]"
90
- : "[path][name][ext]__[local]",
91
- exportsOnly: false,
92
- ...(_a = builtins.css) === null || _a === void 0 ? void 0 : _a.modules
93
- },
94
- namedExports: (_b = builtins.css) === null || _b === void 0 ? void 0 : _b.namedExports
95
- }
96
- : undefined,
97
83
  treeShaking: resolveTreeShaking(builtins.treeShaking, production)
98
84
  };
99
85
  }
@@ -336,7 +336,8 @@ const getRawModuleRule = (rule, path, options) => {
336
336
  if (rule.resourceQuery && !tryMatch(query, rule.resourceQuery)) {
337
337
  return false;
338
338
  }
339
- if (rule.resourceFragment && !tryMatch(fragment, rule.resourceFragment)) {
339
+ if (rule.resourceFragment &&
340
+ !tryMatch(fragment, rule.resourceFragment)) {
340
341
  return false;
341
342
  }
342
343
  return true;
@@ -408,9 +409,26 @@ function getRawParserOptions(parser, type) {
408
409
  javascript: getRawJavascriptParserOptions(parser)
409
410
  };
410
411
  }
411
- return {
412
- type: "unknown"
413
- };
412
+ else if (type === "css") {
413
+ return {
414
+ type: "css",
415
+ css: getRawCssParserOptions(parser)
416
+ };
417
+ }
418
+ else if (type === "css/auto") {
419
+ return {
420
+ type: "css/auto",
421
+ cssAuto: getRawCssParserOptions(parser)
422
+ };
423
+ }
424
+ else if (type === "css/module") {
425
+ return {
426
+ type: "css/module",
427
+ cssModule: getRawCssParserOptions(parser)
428
+ };
429
+ }
430
+ // FIXME: shouldn't depend on module type, for example: `rules: [{ test: /\.css/, generator: {..} }]` will error
431
+ throw new Error(`unreachable: unknow module type: ${type}`);
414
432
  }
415
433
  function getRawJavascriptParserOptions(parser) {
416
434
  var _a, _b, _c, _d, _e;
@@ -443,6 +461,11 @@ function getRawAssetParserDataUrl(dataUrlCondition) {
443
461
  }
444
462
  throw new Error(`unreachable: AssetParserDataUrl type should be one of "options", but got ${dataUrlCondition}`);
445
463
  }
464
+ function getRawCssParserOptions(parser) {
465
+ return {
466
+ namedExports: parser.namedExports
467
+ };
468
+ }
446
469
  function getRawGeneratorOptions(generator, type) {
447
470
  if (type === "asset") {
448
471
  return {
@@ -466,9 +489,25 @@ function getRawGeneratorOptions(generator, type) {
466
489
  : undefined
467
490
  };
468
491
  }
469
- return {
470
- type: "unknown"
471
- };
492
+ if (type === "css") {
493
+ return {
494
+ type: "css",
495
+ css: getRawCssGeneratorOptions(generator)
496
+ };
497
+ }
498
+ if (type === "css/auto") {
499
+ return {
500
+ type: "css/auto",
501
+ cssAuto: getRawCssAutoOrModuleGeneratorOptions(generator)
502
+ };
503
+ }
504
+ if (type === "css/module") {
505
+ return {
506
+ type: "css/module",
507
+ cssModule: getRawCssAutoOrModuleGeneratorOptions(generator)
508
+ };
509
+ }
510
+ throw new Error(`unreachable: unknow module type: ${type}`);
472
511
  }
473
512
  function getRawAssetGeneratorOptions(options) {
474
513
  return {
@@ -502,6 +541,19 @@ function getRawAssetGeneratorDataUrl(dataUrl) {
502
541
  }
503
542
  throw new Error(`unreachable: AssetGeneratorDataUrl type should be one of "options", "function", but got ${dataUrl}`);
504
543
  }
544
+ function getRawCssGeneratorOptions(options) {
545
+ return {
546
+ exportsConvention: options.exportsConvention,
547
+ exportsOnly: options.exportsOnly
548
+ };
549
+ }
550
+ function getRawCssAutoOrModuleGeneratorOptions(options) {
551
+ return {
552
+ localIdentName: options.localIdentName,
553
+ exportsConvention: options.exportsConvention,
554
+ exportsOnly: options.exportsOnly
555
+ };
556
+ }
505
557
  function getRawOptimization(optimization) {
506
558
  (0, assert_1.default)(!(0, util_1.isNil)(optimization.removeAvailableModules) &&
507
559
  !(0, util_1.isNil)(optimization.sideEffects) &&
@@ -55,9 +55,9 @@ const applyRspackOptionsDefaults = (options) => {
55
55
  });
56
56
  applySnapshotDefaults(options.snapshot, { production });
57
57
  applyModuleDefaults(options.module, {
58
- // syncWebAssembly: options.experiments.syncWebAssembly,
59
58
  asyncWebAssembly: options.experiments.asyncWebAssembly,
60
- css: options.experiments.css
59
+ css: options.experiments.css,
60
+ targetProperties
61
61
  });
62
62
  applyOutputDefaults(options.output, {
63
63
  context: options.context,
@@ -85,7 +85,8 @@ const applyRspackOptionsDefaults = (options) => {
85
85
  applyOptimizationDefaults(options.optimization, { production, development });
86
86
  options.resolve = (0, cleverMerge_1.cleverMerge)(getResolveDefaults({
87
87
  targetProperties,
88
- mode: options.mode
88
+ mode: options.mode,
89
+ css: options.experiments.css
89
90
  }), options.resolve);
90
91
  options.resolveLoader = (0, cleverMerge_1.cleverMerge)(getResolveLoaderDefaults(), options.resolveLoader);
91
92
  };
@@ -112,7 +113,6 @@ const applyExperimentsDefaults = (experiments, { cache }) => {
112
113
  D(experiments, "rspackFuture", {});
113
114
  if (typeof experiments.rspackFuture === "object") {
114
115
  D(experiments.rspackFuture, "newTreeshaking", false);
115
- D(experiments.rspackFuture, "disableApplyEntryLazily", true);
116
116
  D(experiments.rspackFuture, "bundlerInfo", {});
117
117
  if (typeof experiments.rspackFuture.bundlerInfo === "object") {
118
118
  D(experiments.rspackFuture.bundlerInfo, "version", require("../../package.json").version);
@@ -131,8 +131,9 @@ const applySnapshotDefaults = (snapshot, { production }) => {
131
131
  const applyJavascriptParserOptionsDefaults = (parserOptions) => {
132
132
  D(parserOptions, "dynamicImportMode", "lazy");
133
133
  };
134
- const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
134
+ const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
135
135
  (0, assertNotNil_1.assertNotNill)(module.parser);
136
+ (0, assertNotNil_1.assertNotNill)(module.generator);
136
137
  F(module.parser, ModuleTypeConstants_1.ASSET_MODULE_TYPE, () => ({}));
137
138
  (0, assertNotNil_1.assertNotNill)(module.parser.asset);
138
139
  F(module.parser.asset, "dataUrlCondition", () => ({}));
@@ -142,6 +143,31 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
142
143
  F(module.parser, "javascript", () => ({}));
143
144
  (0, assertNotNil_1.assertNotNill)(module.parser.javascript);
144
145
  applyJavascriptParserOptionsDefaults(module.parser.javascript);
146
+ if (css) {
147
+ F(module.parser, "css", () => ({}));
148
+ (0, assertNotNil_1.assertNotNill)(module.parser.css);
149
+ D(module.parser.css, "namedExports", true);
150
+ F(module.parser, "css/auto", () => ({}));
151
+ (0, assertNotNil_1.assertNotNill)(module.parser["css/auto"]);
152
+ D(module.parser["css/auto"], "namedExports", true);
153
+ F(module.parser, "css/module", () => ({}));
154
+ (0, assertNotNil_1.assertNotNill)(module.parser["css/module"]);
155
+ D(module.parser["css/module"], "namedExports", true);
156
+ F(module.generator, "css", () => ({}));
157
+ (0, assertNotNil_1.assertNotNill)(module.generator.css);
158
+ D(module.generator["css"], "exportsOnly", !targetProperties || !targetProperties.document);
159
+ D(module.generator["css"], "exportsConvention", "as-is");
160
+ F(module.generator, "css/auto", () => ({}));
161
+ (0, assertNotNil_1.assertNotNill)(module.generator["css/auto"]);
162
+ D(module.generator["css/auto"], "exportsOnly", !targetProperties || !targetProperties.document);
163
+ D(module.generator["css/auto"], "exportsConvention", "as-is");
164
+ D(module.generator["css/auto"], "localIdentName", "[uniqueName]-[id]-[local]");
165
+ F(module.generator, "css/module", () => ({}));
166
+ (0, assertNotNil_1.assertNotNill)(module.generator["css/module"]);
167
+ D(module.generator["css/module"], "exportsOnly", !targetProperties || !targetProperties.document);
168
+ D(module.generator["css/module"], "exportsConvention", "as-is");
169
+ D(module.generator["css/module"], "localIdentName", "[uniqueName]-[id]-[local]");
170
+ }
145
171
  A(module, "defaultRules", () => {
146
172
  const esm = {
147
173
  type: "javascript/esm",
@@ -222,38 +248,24 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
222
248
  });
223
249
  }
224
250
  if (css) {
225
- const cssRule = {
226
- type: "css",
227
- resolve: {
228
- fullySpecified: true,
229
- preferRelative: true
230
- }
231
- };
232
- const cssModulesRule = {
233
- type: "css/module",
234
- resolve: {
235
- fullySpecified: true
236
- }
251
+ const resolve = {
252
+ fullySpecified: true,
253
+ preferRelative: true
237
254
  };
238
255
  rules.push({
239
256
  test: /\.css$/i,
240
- oneOf: [
241
- {
242
- test: /\.module\.css$/i,
243
- ...cssModulesRule
244
- },
245
- {
246
- ...cssRule
247
- }
248
- ]
257
+ type: "css/auto",
258
+ resolve
249
259
  });
250
260
  rules.push({
251
261
  mimetype: "text/css+module",
252
- ...cssModulesRule
262
+ type: "css/module",
263
+ resolve
253
264
  });
254
265
  rules.push({
255
266
  mimetype: "text/css",
256
- ...cssRule
267
+ type: "css",
268
+ resolve
257
269
  });
258
270
  }
259
271
  rules.push({
@@ -646,7 +658,7 @@ const getResolveLoaderDefaults = () => {
646
658
  };
647
659
  // The values are aligned with webpack
648
660
  // https://github.com/webpack/webpack/blob/b9fb99c63ca433b24233e0bbc9ce336b47872c08/lib/config/defaults.js#L1431
649
- const getResolveDefaults = ({ targetProperties, mode }) => {
661
+ const getResolveDefaults = ({ targetProperties, mode, css }) => {
650
662
  const conditions = ["webpack"];
651
663
  conditions.push(mode === "development" ? "development" : "production");
652
664
  if (targetProperties) {
@@ -706,6 +718,22 @@ const getResolveDefaults = ({ targetProperties, mode }) => {
706
718
  unknown: cjsDeps()
707
719
  }
708
720
  };
721
+ if (css) {
722
+ const styleConditions = [];
723
+ styleConditions.push("webpack");
724
+ styleConditions.push(mode === "development" ? "development" : "production");
725
+ styleConditions.push("style");
726
+ resolveOptions.byDependency["css-import"] = {
727
+ // We avoid using any main files because we have to be consistent with CSS `@import`
728
+ // and CSS `@import` does not handle `main` files in directories,
729
+ // you should always specify the full URL for styles
730
+ mainFiles: [],
731
+ mainFields: ["style", "..."],
732
+ conditionNames: styleConditions,
733
+ extensions: [".css"],
734
+ preferRelative: true
735
+ };
736
+ }
709
737
  return resolveOptions;
710
738
  };
711
739
  const D = (obj, prop, value) => {
@@ -23,6 +23,7 @@ export interface EntryDescriptionNormalized {
23
23
  baseUri?: string;
24
24
  filename?: EntryFilename;
25
25
  library?: LibraryOptions;
26
+ dependOn?: string[];
26
27
  }
27
28
  export interface OutputNormalized {
28
29
  path?: Path;
@@ -233,7 +233,12 @@ const getNormalizedEntryStatic = (entry) => {
233
233
  chunkLoading: value.chunkLoading,
234
234
  asyncChunks: value.asyncChunks,
235
235
  filename: value.filename,
236
- library: value.library
236
+ library: value.library,
237
+ dependOn: Array.isArray(value.dependOn)
238
+ ? value.dependOn
239
+ : value.dependOn
240
+ ? [value.dependOn]
241
+ : undefined
237
242
  };
238
243
  }
239
244
  }