@rsbuild/plugin-styled-components 1.0.0 → 1.0.1-beta.1
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/README.md +1 -1
- package/dist/index.cjs +101 -0
- package/dist/index.d.ts +6 -8
- package/dist/index.js +70 -76
- package/package.json +13 -12
- package/dist/index.mjs +0 -69
package/README.md
CHANGED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
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
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
PLUGIN_STYLED_COMPONENTS_NAME: () => PLUGIN_STYLED_COMPONENTS_NAME,
|
|
34
|
+
pluginStyledComponents: () => pluginStyledComponents
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var import_reduce_configs = require("reduce-configs");
|
|
38
|
+
function isServerTarget(target) {
|
|
39
|
+
return Array.isArray(target) ? target.includes("node") : target === "node";
|
|
40
|
+
}
|
|
41
|
+
var getDefaultStyledComponentsConfig = (isProd, ssr) => {
|
|
42
|
+
return {
|
|
43
|
+
ssr,
|
|
44
|
+
// "pure" is used to improve dead code elimination in production.
|
|
45
|
+
// we don't need to enable it in development because it will slow down the build process.
|
|
46
|
+
pure: isProd,
|
|
47
|
+
displayName: true,
|
|
48
|
+
transpileTemplateLiterals: true
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
var PLUGIN_STYLED_COMPONENTS_NAME = "rsbuild:styled-components";
|
|
52
|
+
var pluginStyledComponents = (pluginOptions = {}) => ({
|
|
53
|
+
name: PLUGIN_STYLED_COMPONENTS_NAME,
|
|
54
|
+
setup(api) {
|
|
55
|
+
if (api.context.bundlerType === "webpack") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const getMergedOptions = (useSSR) => {
|
|
59
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
60
|
+
return (0, import_reduce_configs.reduceConfigs)({
|
|
61
|
+
initial: getDefaultStyledComponentsConfig(isProd, useSSR),
|
|
62
|
+
config: pluginOptions
|
|
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
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return mergeRsbuildConfig(extraConfig, userConfig);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
PLUGIN_STYLED_COMPONENTS_NAME,
|
|
100
|
+
pluginStyledComponents
|
|
101
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import { type ConfigChain } from 'reduce-configs';
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
4
|
+
* The options of [@swc/plugin-styled-components](https://www.npmjs.com/package/@swc/plugin-styled-components).
|
|
6
5
|
*/
|
|
7
|
-
type
|
|
6
|
+
export type PluginStyledComponentsOptions = {
|
|
8
7
|
displayName?: boolean;
|
|
9
8
|
ssr?: boolean;
|
|
10
9
|
fileName?: boolean;
|
|
@@ -16,6 +15,5 @@ type StyledComponentsOptions = {
|
|
|
16
15
|
pure?: boolean;
|
|
17
16
|
cssProps?: boolean;
|
|
18
17
|
};
|
|
19
|
-
declare const
|
|
20
|
-
|
|
21
|
-
export { pluginStyledComponents };
|
|
18
|
+
export declare const PLUGIN_STYLED_COMPONENTS_NAME = "rsbuild:styled-components";
|
|
19
|
+
export declare const pluginStyledComponents: (pluginOptions?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
package/dist/index.js
CHANGED
|
@@ -1,86 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
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
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
var require = createRequire(import.meta['url']);
|
|
29
3
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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');
|
|
34
10
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.55.0_eslint@9.6.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
import path from "path";
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
import { reduceConfigs } from "reduce-configs";
|
|
18
|
+
function isServerTarget(target) {
|
|
19
|
+
return Array.isArray(target) ? target.includes("node") : target === "node";
|
|
20
|
+
}
|
|
21
|
+
var getDefaultStyledComponentsConfig = (isProd, ssr) => {
|
|
22
|
+
return {
|
|
23
|
+
ssr,
|
|
24
|
+
// "pure" is used to improve dead code elimination in production.
|
|
25
|
+
// we don't need to enable it in development because it will slow down the build process.
|
|
26
|
+
pure: isProd,
|
|
27
|
+
displayName: true,
|
|
28
|
+
transpileTemplateLiterals: true
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var PLUGIN_STYLED_COMPONENTS_NAME = "rsbuild:styled-components";
|
|
32
|
+
var pluginStyledComponents = (pluginOptions = {}) => ({
|
|
33
|
+
name: PLUGIN_STYLED_COMPONENTS_NAME,
|
|
39
34
|
setup(api) {
|
|
40
|
-
api.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
if (api.context.bundlerType === "webpack") {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const getMergedOptions = (useSSR) => {
|
|
39
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
40
|
+
return reduceConfigs({
|
|
41
|
+
initial: getDefaultStyledComponentsConfig(isProd, useSSR),
|
|
42
|
+
config: pluginOptions
|
|
46
43
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
44
|
+
};
|
|
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
|
+
}
|
|
66
69
|
}
|
|
67
|
-
} else if (rule.uses.has(CHAIN_ID.USE.BABEL)) {
|
|
68
|
-
rule.use(CHAIN_ID.USE.BABEL).tap((babelConfig) => {
|
|
69
|
-
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;
|
|
76
|
-
});
|
|
77
70
|
}
|
|
78
|
-
}
|
|
79
|
-
|
|
71
|
+
};
|
|
72
|
+
return mergeRsbuildConfig(extraConfig, userConfig);
|
|
73
|
+
}
|
|
80
74
|
});
|
|
81
75
|
}
|
|
82
76
|
});
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
export {
|
|
78
|
+
PLUGIN_STYLED_COMPONENTS_NAME,
|
|
85
79
|
pluginStyledComponents
|
|
86
|
-
}
|
|
80
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-styled-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-beta.1",
|
|
4
4
|
"description": "styled-components plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,29 +8,30 @@
|
|
|
8
8
|
"directory": "packages/plugin-styled-components"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"import": "./dist/index.
|
|
15
|
-
"
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
|
-
"main": "./dist/index.
|
|
19
|
+
"main": "./dist/index.cjs",
|
|
19
20
|
"types": "./dist/index.d.ts",
|
|
20
21
|
"files": [
|
|
21
22
|
"dist"
|
|
22
23
|
],
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
25
|
+
"@swc/plugin-styled-components": "2.0.9",
|
|
26
|
+
"reduce-configs": "^1.0.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@types/node": "
|
|
29
|
-
"typescript": "^5.
|
|
30
|
-
"@rsbuild/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"@rsbuild/
|
|
29
|
+
"@types/node": "18.x",
|
|
30
|
+
"typescript": "^5.5.2",
|
|
31
|
+
"@rsbuild/core": "1.0.1-beta.1"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@rsbuild/core": "^1.0.1-beta.0"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public",
|
package/dist/index.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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
|
|
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: "rsbuild: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
|
-
};
|