@rsbuild/plugin-styled-components 0.1.0 → 0.1.2

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
@@ -4,7 +4,7 @@ import { ChainedConfig } from '@rsbuild/shared';
4
4
  /**
5
5
  * the options of [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) or [rspackExperiments.styledComponents](https://rspack.dev/guide/loader#optionsrspackexperimentsstyledcomponents).
6
6
  */
7
- type StyledComponentsOptions = {
7
+ type PluginStyledComponentsOptions = {
8
8
  displayName?: boolean;
9
9
  ssr?: boolean;
10
10
  fileName?: boolean;
@@ -16,6 +16,6 @@ type StyledComponentsOptions = {
16
16
  pure?: boolean;
17
17
  cssProps?: boolean;
18
18
  };
19
- declare const pluginStyledComponents: (userConfig?: ChainedConfig<StyledComponentsOptions>) => RsbuildPlugin;
19
+ declare const pluginStyledComponents: (userConfig?: ChainedConfig<PluginStyledComponentsOptions>) => RsbuildPlugin;
20
20
 
21
- export { pluginStyledComponents };
21
+ export { PluginStyledComponentsOptions, pluginStyledComponents };
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -39,6 +29,9 @@ var pluginStyledComponents = (userConfig = {}) => ({
39
29
  setup(api) {
40
30
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
41
31
  const { bundlerType } = api.context;
32
+ if (bundlerType === "webpack") {
33
+ return;
34
+ }
42
35
  const isSSR = (0, import_shared.isServerTarget)(api.context.target);
43
36
  const styledComponentsOptions = (0, import_shared.mergeChainedOptions)({
44
37
  defaults: (0, import_shared.getDefaultStyledComponentsConfig)(isProd, isSSR),
@@ -51,28 +44,11 @@ var pluginStyledComponents = (userConfig = {}) => ({
51
44
  if (chain.module.rules.has(ruleId)) {
52
45
  const rule = chain.module.rule(ruleId);
53
46
  if (rule.uses.has(CHAIN_ID.USE.SWC)) {
54
- if (bundlerType === "rspack") {
55
- rule.use(CHAIN_ID.USE.SWC).tap((options) => {
56
- var _a;
57
- (_a = options.rspackExperiments) != null ? _a : options.rspackExperiments = {};
58
- options.rspackExperiments.styledComponents = styledComponentsOptions;
59
- return options;
60
- });
61
- } else {
62
- rule.use(CHAIN_ID.USE.SWC).tap((swc) => {
63
- swc.extensions.styledComponents = styledComponentsOptions;
64
- return swc;
65
- });
66
- }
67
- } else if (rule.uses.has(CHAIN_ID.USE.BABEL)) {
68
- rule.use(CHAIN_ID.USE.BABEL).tap((babelConfig) => {
47
+ rule.use(CHAIN_ID.USE.SWC).tap((options) => {
69
48
  var _a;
70
- (_a = babelConfig.plugins) != null ? _a : babelConfig.plugins = [];
71
- babelConfig.plugins.push([
72
- require.resolve("babel-plugin-styled-components"),
73
- styledComponentsOptions
74
- ]);
75
- return babelConfig;
49
+ (_a = options.rspackExperiments) != null ? _a : options.rspackExperiments = {};
50
+ options.rspackExperiments.styledComponents = styledComponentsOptions;
51
+ return options;
76
52
  });
77
53
  }
78
54
  }
package/dist/index.mjs CHANGED
@@ -1,16 +1,8 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.40.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
1
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.41.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
10
2
  import { fileURLToPath } from "url";
11
3
  import path from "path";
12
4
 
13
- // ../../scripts/require_shims.js
5
+ // ../../scripts/requireShims.js
14
6
  import { createRequire } from "module";
15
7
  global.require = createRequire(import.meta.url);
16
8
 
@@ -25,6 +17,9 @@ var pluginStyledComponents = (userConfig = {}) => ({
25
17
  setup(api) {
26
18
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
27
19
  const { bundlerType } = api.context;
20
+ if (bundlerType === "webpack") {
21
+ return;
22
+ }
28
23
  const isSSR = isServerTarget(api.context.target);
29
24
  const styledComponentsOptions = mergeChainedOptions({
30
25
  defaults: getDefaultStyledComponentsConfig(isProd, isSSR),
@@ -37,26 +32,10 @@ var pluginStyledComponents = (userConfig = {}) => ({
37
32
  if (chain.module.rules.has(ruleId)) {
38
33
  const rule = chain.module.rule(ruleId);
39
34
  if (rule.uses.has(CHAIN_ID.USE.SWC)) {
40
- if (bundlerType === "rspack") {
41
- rule.use(CHAIN_ID.USE.SWC).tap((options) => {
42
- options.rspackExperiments ?? (options.rspackExperiments = {});
43
- options.rspackExperiments.styledComponents = styledComponentsOptions;
44
- return options;
45
- });
46
- } else {
47
- rule.use(CHAIN_ID.USE.SWC).tap((swc) => {
48
- swc.extensions.styledComponents = styledComponentsOptions;
49
- return swc;
50
- });
51
- }
52
- } else if (rule.uses.has(CHAIN_ID.USE.BABEL)) {
53
- rule.use(CHAIN_ID.USE.BABEL).tap((babelConfig) => {
54
- babelConfig.plugins ?? (babelConfig.plugins = []);
55
- babelConfig.plugins.push([
56
- __require.resolve("babel-plugin-styled-components"),
57
- styledComponentsOptions
58
- ]);
59
- return babelConfig;
35
+ rule.use(CHAIN_ID.USE.SWC).tap((options) => {
36
+ options.rspackExperiments ?? (options.rspackExperiments = {});
37
+ options.rspackExperiments.styledComponents = styledComponentsOptions;
38
+ return options;
60
39
  });
61
40
  }
62
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-styled-components",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "styled-components plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,16 +21,13 @@
21
21
  "dist"
22
22
  ],
23
23
  "dependencies": {
24
- "babel-plugin-styled-components": "1.13.3",
25
- "@rsbuild/shared": "0.1.0"
24
+ "@rsbuild/shared": "0.1.2"
26
25
  },
27
26
  "devDependencies": {
28
27
  "@types/node": "^16",
29
28
  "typescript": "^5.3.0",
30
- "@rsbuild/core": "0.1.0",
31
- "@rsbuild/plugin-swc": "0.1.0",
32
- "@rsbuild/test-helper": "0.1.0",
33
- "@rsbuild/webpack": "0.1.0"
29
+ "@rsbuild/core": "0.1.2",
30
+ "@rsbuild/test-helper": "0.1.2"
34
31
  },
35
32
  "publishConfig": {
36
33
  "access": "public",