@rsbuild/plugin-styled-components 0.0.17 → 0.0.18

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
@@ -1,18 +1,20 @@
1
- import { type ChainedConfig, type DefaultRsbuildPlugin } from '@rsbuild/shared';
1
+ import { ChainedConfig, DefaultRsbuildPlugin } from '@rsbuild/shared';
2
+
2
3
  /**
3
4
  * the options of [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) or [rspackExperiments.styledComponents](https://www.rspack.dev/guide/loader.html#optionsrspackexperimentsstyledcomponents).
4
5
  */
5
6
  type StyledComponentsOptions = {
6
- displayName?: boolean;
7
- ssr?: boolean;
8
- fileName?: boolean;
9
- meaninglessFileNames?: string[];
10
- namespace?: string;
11
- topLevelImportPaths?: string[];
12
- transpileTemplateLiterals?: boolean;
13
- minify?: boolean;
14
- pure?: boolean;
15
- cssProps?: boolean;
7
+ displayName?: boolean;
8
+ ssr?: boolean;
9
+ fileName?: boolean;
10
+ meaninglessFileNames?: string[];
11
+ namespace?: string;
12
+ topLevelImportPaths?: string[];
13
+ transpileTemplateLiterals?: boolean;
14
+ minify?: boolean;
15
+ pure?: boolean;
16
+ cssProps?: boolean;
16
17
  };
17
- export declare const pluginStyledComponents: (userConfig?: ChainedConfig<StyledComponentsOptions>) => DefaultRsbuildPlugin;
18
- export {};
18
+ declare const pluginStyledComponents: (userConfig?: ChainedConfig<StyledComponentsOptions>) => DefaultRsbuildPlugin;
19
+
20
+ export { pluginStyledComponents };
package/dist/index.js CHANGED
@@ -26,18 +26,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
29
31
  var src_exports = {};
30
32
  __export(src_exports, {
31
33
  pluginStyledComponents: () => pluginStyledComponents
32
34
  });
33
35
  module.exports = __toCommonJS(src_exports);
34
36
  var import_shared = require("@rsbuild/shared");
35
- const pluginStyledComponents = (userConfig = {}) => ({
37
+ var pluginStyledComponents = (userConfig = {}) => ({
36
38
  name: "plugin-styled-components",
37
39
  setup(api) {
38
40
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
39
41
  const { bundlerType } = api.context;
40
- const isSSR = (0, import_shared.useSSR)(api.context.target);
42
+ const isSSR = (0, import_shared.isServerTarget)(api.context.target);
41
43
  const styledComponentsOptions = (0, import_shared.mergeChainedOptions)({
42
44
  defaults: (0, import_shared.getDefaultStyledComponentsConfig)(isProd, isSSR),
43
45
  options: userConfig
package/dist/index.mjs ADDED
@@ -0,0 +1,69 @@
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.39.2_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
10
+ import { fileURLToPath } from "url";
11
+ import path from "path";
12
+
13
+ // ../../scripts/require_shims.js
14
+ import { createRequire } from "module";
15
+ global.require = createRequire(import.meta.url);
16
+
17
+ // src/index.ts
18
+ import {
19
+ isServerTarget,
20
+ mergeChainedOptions,
21
+ getDefaultStyledComponentsConfig
22
+ } from "@rsbuild/shared";
23
+ var pluginStyledComponents = (userConfig = {}) => ({
24
+ name: "plugin-styled-components",
25
+ setup(api) {
26
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
27
+ const { bundlerType } = api.context;
28
+ const isSSR = isServerTarget(api.context.target);
29
+ const styledComponentsOptions = mergeChainedOptions({
30
+ defaults: getDefaultStyledComponentsConfig(isProd, isSSR),
31
+ options: userConfig
32
+ });
33
+ if (!styledComponentsOptions) {
34
+ return;
35
+ }
36
+ [CHAIN_ID.RULE.JS, CHAIN_ID.RULE.JS_DATA_URI].forEach((ruleId) => {
37
+ if (chain.module.rules.has(ruleId)) {
38
+ const rule = chain.module.rule(ruleId);
39
+ 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;
60
+ });
61
+ }
62
+ }
63
+ });
64
+ });
65
+ }
66
+ });
67
+ export {
68
+ pluginStyledComponents
69
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-styled-components",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "styled-components plugin for Rsbuild",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,7 @@
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
14
15
  "default": "./dist/index.js"
15
16
  }
16
17
  },
@@ -21,15 +22,15 @@
21
22
  ],
22
23
  "dependencies": {
23
24
  "babel-plugin-styled-components": "1.13.3",
24
- "@rsbuild/shared": "0.0.17"
25
+ "@rsbuild/shared": "0.0.18"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@types/node": "^16",
28
29
  "typescript": "^5.2.2",
29
- "@rsbuild/core": "0.0.17",
30
- "@rsbuild/plugin-swc": "0.0.17",
31
- "@rsbuild/test-helper": "0.0.17",
32
- "@rsbuild/webpack": "0.0.17"
30
+ "@rsbuild/core": "0.0.18",
31
+ "@rsbuild/plugin-swc": "0.0.18",
32
+ "@rsbuild/test-helper": "0.0.18",
33
+ "@rsbuild/webpack": "0.0.18"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public",