@rsbuild/plugin-styled-components 0.7.9 → 1.0.0-alpha.0
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.cjs +42 -21
- package/dist/index.d.ts +5 -8
- package/dist/index.js +39 -21
- package/package.json +6 -5
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -24,11 +34,9 @@ __export(src_exports, {
|
|
|
24
34
|
pluginStyledComponents: () => pluginStyledComponents
|
|
25
35
|
});
|
|
26
36
|
module.exports = __toCommonJS(src_exports);
|
|
27
|
-
var
|
|
37
|
+
var import_core = require("@rsbuild/core");
|
|
28
38
|
function isServerTarget(target) {
|
|
29
|
-
return
|
|
30
|
-
(item) => ["node", "service-worker"].includes(item)
|
|
31
|
-
);
|
|
39
|
+
return Array.isArray(target) ? target.includes("node") : target === "node";
|
|
32
40
|
}
|
|
33
41
|
var getDefaultStyledComponentsConfig = (isProd, ssr) => {
|
|
34
42
|
return {
|
|
@@ -47,29 +55,42 @@ var pluginStyledComponents = (pluginOptions = {}) => ({
|
|
|
47
55
|
if (api.context.bundlerType === "webpack") {
|
|
48
56
|
return;
|
|
49
57
|
}
|
|
50
|
-
const getMergedOptions = () => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
return (0, import_shared.reduceConfigs)({
|
|
58
|
+
const getMergedOptions = (useSSR) => {
|
|
59
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
60
|
+
return (0, import_core.reduceConfigs)({
|
|
54
61
|
initial: getDefaultStyledComponentsConfig(isProd, useSSR),
|
|
55
62
|
config: pluginOptions
|
|
56
63
|
});
|
|
57
64
|
};
|
|
58
|
-
api.modifyRsbuildConfig(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
api.modifyRsbuildConfig({
|
|
66
|
+
order: "post",
|
|
67
|
+
handler: (userConfig, { mergeRsbuildConfig }) => {
|
|
68
|
+
const targets = userConfig.environments ? Object.values(userConfig.environments).map(
|
|
69
|
+
(e) => e.output?.target || userConfig.output?.target || "web"
|
|
70
|
+
) : [userConfig.output?.target || "web"];
|
|
71
|
+
const useSSR = isServerTarget(targets);
|
|
72
|
+
const mergedOptions = getMergedOptions(useSSR);
|
|
73
|
+
if (!mergedOptions) {
|
|
74
|
+
return userConfig;
|
|
75
|
+
}
|
|
76
|
+
const extraConfig = {
|
|
77
|
+
tools: {
|
|
78
|
+
swc: {
|
|
79
|
+
jsc: {
|
|
80
|
+
experimental: {
|
|
81
|
+
plugins: [
|
|
82
|
+
[
|
|
83
|
+
require.resolve("@swc/plugin-styled-components"),
|
|
84
|
+
mergedOptions
|
|
85
|
+
]
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
65
89
|
}
|
|
66
|
-
opts.rspackExperiments ??= {};
|
|
67
|
-
opts.rspackExperiments.styledComponents = mergedOptions;
|
|
68
|
-
return opts;
|
|
69
90
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
};
|
|
92
|
+
return mergeRsbuildConfig(extraConfig, userConfig);
|
|
93
|
+
}
|
|
73
94
|
});
|
|
74
95
|
}
|
|
75
96
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { ConfigChain, RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
1
|
+
import type { ConfigChain, RsbuildPlugin } from '@rsbuild/core';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* The options of [@swc/plugin-styled-components](https://www.npmjs.com/package/@swc/plugin-styled-components).
|
|
5
4
|
*/
|
|
6
|
-
type PluginStyledComponentsOptions = {
|
|
5
|
+
export type PluginStyledComponentsOptions = {
|
|
7
6
|
displayName?: boolean;
|
|
8
7
|
ssr?: boolean;
|
|
9
8
|
fileName?: boolean;
|
|
@@ -15,7 +14,5 @@ type PluginStyledComponentsOptions = {
|
|
|
15
14
|
pure?: boolean;
|
|
16
15
|
cssProps?: boolean;
|
|
17
16
|
};
|
|
18
|
-
declare const PLUGIN_STYLED_COMPONENTS_NAME = "rsbuild:styled-components";
|
|
19
|
-
declare const pluginStyledComponents: (pluginOptions?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
|
20
|
-
|
|
21
|
-
export { PLUGIN_STYLED_COMPONENTS_NAME, type PluginStyledComponentsOptions, pluginStyledComponents };
|
|
17
|
+
export declare const PLUGIN_STYLED_COMPONENTS_NAME = "rsbuild:styled-components";
|
|
18
|
+
export declare const pluginStyledComponents: (pluginOptions?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
var require = createRequire(import.meta['url']);
|
|
3
3
|
|
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
6
|
+
}) : x)(function(x) {
|
|
7
|
+
if (typeof require !== "undefined")
|
|
8
|
+
return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
4
11
|
|
|
5
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
12
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.54.5_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
6
13
|
import { fileURLToPath } from "url";
|
|
7
14
|
import path from "path";
|
|
8
15
|
|
|
9
16
|
// src/index.ts
|
|
10
|
-
import {
|
|
17
|
+
import { reduceConfigs } from "@rsbuild/core";
|
|
11
18
|
function isServerTarget(target) {
|
|
12
|
-
return
|
|
13
|
-
(item) => ["node", "service-worker"].includes(item)
|
|
14
|
-
);
|
|
19
|
+
return Array.isArray(target) ? target.includes("node") : target === "node";
|
|
15
20
|
}
|
|
16
21
|
var getDefaultStyledComponentsConfig = (isProd, ssr) => {
|
|
17
22
|
return {
|
|
@@ -30,29 +35,42 @@ var pluginStyledComponents = (pluginOptions = {}) => ({
|
|
|
30
35
|
if (api.context.bundlerType === "webpack") {
|
|
31
36
|
return;
|
|
32
37
|
}
|
|
33
|
-
const getMergedOptions = () => {
|
|
34
|
-
const
|
|
35
|
-
const isProd = getNodeEnv() === "production";
|
|
38
|
+
const getMergedOptions = (useSSR) => {
|
|
39
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
36
40
|
return reduceConfigs({
|
|
37
41
|
initial: getDefaultStyledComponentsConfig(isProd, useSSR),
|
|
38
42
|
config: pluginOptions
|
|
39
43
|
});
|
|
40
44
|
};
|
|
41
|
-
api.modifyRsbuildConfig(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
api.modifyRsbuildConfig({
|
|
46
|
+
order: "post",
|
|
47
|
+
handler: (userConfig, { mergeRsbuildConfig }) => {
|
|
48
|
+
const targets = userConfig.environments ? Object.values(userConfig.environments).map(
|
|
49
|
+
(e) => e.output?.target || userConfig.output?.target || "web"
|
|
50
|
+
) : [userConfig.output?.target || "web"];
|
|
51
|
+
const useSSR = isServerTarget(targets);
|
|
52
|
+
const mergedOptions = getMergedOptions(useSSR);
|
|
53
|
+
if (!mergedOptions) {
|
|
54
|
+
return userConfig;
|
|
55
|
+
}
|
|
56
|
+
const extraConfig = {
|
|
57
|
+
tools: {
|
|
58
|
+
swc: {
|
|
59
|
+
jsc: {
|
|
60
|
+
experimental: {
|
|
61
|
+
plugins: [
|
|
62
|
+
[
|
|
63
|
+
__require.resolve("@swc/plugin-styled-components"),
|
|
64
|
+
mergedOptions
|
|
65
|
+
]
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
48
69
|
}
|
|
49
|
-
opts.rspackExperiments ??= {};
|
|
50
|
-
opts.rspackExperiments.styledComponents = mergedOptions;
|
|
51
|
-
return opts;
|
|
52
70
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
};
|
|
72
|
+
return mergeRsbuildConfig(extraConfig, userConfig);
|
|
73
|
+
}
|
|
56
74
|
});
|
|
57
75
|
}
|
|
58
76
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-styled-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"description": "styled-components plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,15 +22,16 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
25
|
+
"@swc/plugin-styled-components": "2.0.8",
|
|
26
|
+
"@rsbuild/shared": "1.0.0-alpha.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "18.x",
|
|
29
|
-
"typescript": "^5.
|
|
30
|
-
"@rsbuild/core": "0.
|
|
30
|
+
"typescript": "^5.5.2",
|
|
31
|
+
"@rsbuild/core": "1.0.0-alpha.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@rsbuild/core": "^0.
|
|
34
|
+
"@rsbuild/core": "^1.0.0-alpha.0"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public",
|