@rsbuild/plugin-styled-components 0.4.11 → 0.4.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.
package/dist/index.d.ts CHANGED
@@ -16,6 +16,6 @@ type PluginStyledComponentsOptions = {
16
16
  pure?: boolean;
17
17
  cssProps?: boolean;
18
18
  };
19
- declare const pluginStyledComponents: (userConfig?: ChainedConfig<PluginStyledComponentsOptions>) => RsbuildPlugin;
19
+ declare const pluginStyledComponents: (pluginOptions?: ChainedConfig<PluginStyledComponentsOptions>) => RsbuildPlugin;
20
20
 
21
21
  export { type PluginStyledComponentsOptions, pluginStyledComponents };
package/dist/index.js CHANGED
@@ -24,30 +24,35 @@ __export(src_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
  var import_shared = require("@rsbuild/shared");
27
- var pluginStyledComponents = (userConfig = {}) => ({
27
+ var pluginStyledComponents = (pluginOptions = {}) => ({
28
28
  name: "rsbuild:styled-components",
29
29
  setup(api) {
30
- api.modifyBundlerChain(async (chain, { isProd }) => {
31
- const { bundlerType } = api.context;
32
- if (bundlerType === "webpack") {
33
- return;
34
- }
35
- const isSSR = (0, import_shared.isServerTarget)(api.context.targets);
36
- const styledComponentsOptions = (0, import_shared.mergeChainedOptions)({
37
- defaults: (0, import_shared.getDefaultStyledComponentsConfig)(isProd, isSSR),
38
- options: userConfig
30
+ if (api.context.bundlerType === "webpack") {
31
+ return;
32
+ }
33
+ const getMergedOptions = () => {
34
+ const useSSR = (0, import_shared.isServerTarget)(api.context.targets);
35
+ const isProd = (0, import_shared.getNodeEnv)() === "production";
36
+ return (0, import_shared.mergeChainedOptions)({
37
+ defaults: (0, import_shared.getDefaultStyledComponentsConfig)(isProd, useSSR),
38
+ options: pluginOptions
39
39
  });
40
- if (!styledComponentsOptions) {
41
- return;
42
- }
43
- (0, import_shared.modifySwcLoaderOptions)({
44
- chain,
45
- modifier: (options) => {
46
- options.rspackExperiments ?? (options.rspackExperiments = {});
47
- options.rspackExperiments.styledComponents = styledComponentsOptions;
48
- return options;
40
+ };
41
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
42
+ const extraConfig = {
43
+ tools: {
44
+ swc(opts) {
45
+ const mergedOptions = getMergedOptions();
46
+ if (!mergedOptions) {
47
+ return opts;
48
+ }
49
+ opts.rspackExperiments ?? (opts.rspackExperiments = {});
50
+ opts.rspackExperiments.styledComponents = mergedOptions;
51
+ return opts;
52
+ }
49
53
  }
50
- });
54
+ };
55
+ return mergeRsbuildConfig(extraConfig, userConfig);
51
56
  });
52
57
  }
53
58
  });
package/dist/index.mjs CHANGED
@@ -8,35 +8,40 @@ import path from "path";
8
8
 
9
9
  // src/index.ts
10
10
  import {
11
+ getNodeEnv,
11
12
  isServerTarget,
12
13
  mergeChainedOptions,
13
- modifySwcLoaderOptions,
14
14
  getDefaultStyledComponentsConfig
15
15
  } from "@rsbuild/shared";
16
- var pluginStyledComponents = (userConfig = {}) => ({
16
+ var pluginStyledComponents = (pluginOptions = {}) => ({
17
17
  name: "rsbuild:styled-components",
18
18
  setup(api) {
19
- api.modifyBundlerChain(async (chain, { isProd }) => {
20
- const { bundlerType } = api.context;
21
- if (bundlerType === "webpack") {
22
- return;
23
- }
24
- const isSSR = isServerTarget(api.context.targets);
25
- const styledComponentsOptions = mergeChainedOptions({
26
- defaults: getDefaultStyledComponentsConfig(isProd, isSSR),
27
- options: userConfig
19
+ if (api.context.bundlerType === "webpack") {
20
+ return;
21
+ }
22
+ const getMergedOptions = () => {
23
+ const useSSR = isServerTarget(api.context.targets);
24
+ const isProd = getNodeEnv() === "production";
25
+ return mergeChainedOptions({
26
+ defaults: getDefaultStyledComponentsConfig(isProd, useSSR),
27
+ options: pluginOptions
28
28
  });
29
- if (!styledComponentsOptions) {
30
- return;
31
- }
32
- modifySwcLoaderOptions({
33
- chain,
34
- modifier: (options) => {
35
- options.rspackExperiments ?? (options.rspackExperiments = {});
36
- options.rspackExperiments.styledComponents = styledComponentsOptions;
37
- return options;
29
+ };
30
+ api.modifyRsbuildConfig((userConfig, { mergeRsbuildConfig }) => {
31
+ const extraConfig = {
32
+ tools: {
33
+ swc(opts) {
34
+ const mergedOptions = getMergedOptions();
35
+ if (!mergedOptions) {
36
+ return opts;
37
+ }
38
+ opts.rspackExperiments ?? (opts.rspackExperiments = {});
39
+ opts.rspackExperiments.styledComponents = mergedOptions;
40
+ return opts;
41
+ }
38
42
  }
39
- });
43
+ };
44
+ return mergeRsbuildConfig(extraConfig, userConfig);
40
45
  });
41
46
  }
42
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-styled-components",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "description": "styled-components plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,16 +22,15 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@rsbuild/shared": "0.4.11"
25
+ "@rsbuild/shared": "0.4.13"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "16.x",
29
- "typescript": "^5.3.0",
30
- "@rsbuild/core": "0.4.11",
31
- "@scripts/test-helper": "0.4.11"
29
+ "typescript": "^5.4.2",
30
+ "@rsbuild/core": "0.4.13"
32
31
  },
33
32
  "peerDependencies": {
34
- "@rsbuild/core": "^0.4.11"
33
+ "@rsbuild/core": "^0.4.13"
35
34
  },
36
35
  "publishConfig": {
37
36
  "access": "public",