@rspack/core 0.5.9-canary-89c5dce-20240402093536 → 0.5.9-canary-5be4c34-20240403005129

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,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");
@@ -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
  };
@@ -131,8 +132,9 @@ const applySnapshotDefaults = (snapshot, { production }) => {
131
132
  const applyJavascriptParserOptionsDefaults = (parserOptions) => {
132
133
  D(parserOptions, "dynamicImportMode", "lazy");
133
134
  };
134
- const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
135
+ const applyModuleDefaults = (module, { asyncWebAssembly, css, targetProperties }) => {
135
136
  (0, assertNotNil_1.assertNotNill)(module.parser);
137
+ (0, assertNotNil_1.assertNotNill)(module.generator);
136
138
  F(module.parser, ModuleTypeConstants_1.ASSET_MODULE_TYPE, () => ({}));
137
139
  (0, assertNotNil_1.assertNotNill)(module.parser.asset);
138
140
  F(module.parser.asset, "dataUrlCondition", () => ({}));
@@ -142,6 +144,31 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
142
144
  F(module.parser, "javascript", () => ({}));
143
145
  (0, assertNotNil_1.assertNotNill)(module.parser.javascript);
144
146
  applyJavascriptParserOptionsDefaults(module.parser.javascript);
147
+ if (css) {
148
+ F(module.parser, "css", () => ({}));
149
+ (0, assertNotNil_1.assertNotNill)(module.parser.css);
150
+ D(module.parser.css, "namedExports", true);
151
+ F(module.parser, "css/auto", () => ({}));
152
+ (0, assertNotNil_1.assertNotNill)(module.parser["css/auto"]);
153
+ D(module.parser["css/auto"], "namedExports", true);
154
+ F(module.parser, "css/module", () => ({}));
155
+ (0, assertNotNil_1.assertNotNill)(module.parser["css/module"]);
156
+ D(module.parser["css/module"], "namedExports", true);
157
+ F(module.generator, "css", () => ({}));
158
+ (0, assertNotNil_1.assertNotNill)(module.generator.css);
159
+ D(module.generator["css"], "exportsOnly", !targetProperties || !targetProperties.document);
160
+ D(module.generator["css"], "exportsConvention", "as-is");
161
+ F(module.generator, "css/auto", () => ({}));
162
+ (0, assertNotNil_1.assertNotNill)(module.generator["css/auto"]);
163
+ D(module.generator["css/auto"], "exportsOnly", !targetProperties || !targetProperties.document);
164
+ D(module.generator["css/auto"], "exportsConvention", "as-is");
165
+ D(module.generator["css/auto"], "localIdentName", "[uniqueName]-[id]-[local]");
166
+ F(module.generator, "css/module", () => ({}));
167
+ (0, assertNotNil_1.assertNotNill)(module.generator["css/module"]);
168
+ D(module.generator["css/module"], "exportsOnly", !targetProperties || !targetProperties.document);
169
+ D(module.generator["css/module"], "exportsConvention", "as-is");
170
+ D(module.generator["css/module"], "localIdentName", "[uniqueName]-[id]-[local]");
171
+ }
145
172
  A(module, "defaultRules", () => {
146
173
  const esm = {
147
174
  type: "javascript/esm",
@@ -222,38 +249,24 @@ const applyModuleDefaults = (module, { asyncWebAssembly, css }) => {
222
249
  });
223
250
  }
224
251
  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
- }
252
+ const resolve = {
253
+ fullySpecified: true,
254
+ preferRelative: true
237
255
  };
238
256
  rules.push({
239
257
  test: /\.css$/i,
240
- oneOf: [
241
- {
242
- test: /\.module\.css$/i,
243
- ...cssModulesRule
244
- },
245
- {
246
- ...cssRule
247
- }
248
- ]
258
+ type: "css/auto",
259
+ resolve
249
260
  });
250
261
  rules.push({
251
262
  mimetype: "text/css+module",
252
- ...cssModulesRule
263
+ type: "css/module",
264
+ resolve
253
265
  });
254
266
  rules.push({
255
267
  mimetype: "text/css",
256
- ...cssRule
268
+ type: "css",
269
+ resolve
257
270
  });
258
271
  }
259
272
  rules.push({
@@ -646,7 +659,7 @@ const getResolveLoaderDefaults = () => {
646
659
  };
647
660
  // The values are aligned with webpack
648
661
  // https://github.com/webpack/webpack/blob/b9fb99c63ca433b24233e0bbc9ce336b47872c08/lib/config/defaults.js#L1431
649
- const getResolveDefaults = ({ targetProperties, mode }) => {
662
+ const getResolveDefaults = ({ targetProperties, mode, css }) => {
650
663
  const conditions = ["webpack"];
651
664
  conditions.push(mode === "development" ? "development" : "production");
652
665
  if (targetProperties) {
@@ -706,6 +719,22 @@ const getResolveDefaults = ({ targetProperties, mode }) => {
706
719
  unknown: cjsDeps()
707
720
  }
708
721
  };
722
+ if (css) {
723
+ const styleConditions = [];
724
+ styleConditions.push("webpack");
725
+ styleConditions.push(mode === "development" ? "development" : "production");
726
+ styleConditions.push("style");
727
+ resolveOptions.byDependency["css-import"] = {
728
+ // We avoid using any main files because we have to be consistent with CSS `@import`
729
+ // and CSS `@import` does not handle `main` files in directories,
730
+ // you should always specify the full URL for styles
731
+ mainFiles: [],
732
+ mainFields: ["style", "..."],
733
+ conditionNames: styleConditions,
734
+ extensions: [".css"],
735
+ preferRelative: true
736
+ };
737
+ }
709
738
  return resolveOptions;
710
739
  };
711
740
  const D = (obj, prop, value) => {