@rsbuild/plugin-styled-components 1.0.1-beta.9 → 1.1.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
3
+ Copyright (c) 2024 Rspack Contrib
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,95 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
1
+ # @rsbuild/plugin-styled-components
2
+
3
+ An Rsbuild plugin to provide compile-time support for styled-components. It improves debugging and adds server-side rendering support for styled-components.
4
+
5
+ > [styled-components](https://styled-components.com/) is a popular CSS-in-JS implementation library, which uses the new JavaScript feature [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write component CSS styles.
6
+
7
+ <p>
8
+ <a href="https://npmjs.com/package/@rsbuild/plugin-styled-components">
9
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-styled-components?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
10
+ </a>
11
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
3
12
  </p>
4
13
 
5
- # Rsbuild
14
+ ## Usage
15
+
16
+ Install:
17
+
18
+ ```bash
19
+ npm add @rsbuild/plugin-styled-components -D
20
+ ```
21
+
22
+ Add plugin to your `rsbuild.config.ts`:
23
+
24
+ ```ts
25
+ // rsbuild.config.ts
26
+ import { pluginStyledComponents } from "@rsbuild/plugin-styled-components";
27
+
28
+ export default {
29
+ plugins: [pluginStyledComponents()],
30
+ };
31
+ ```
32
+
33
+ ## Example
34
+
35
+ After registering the plugin, you can use styled-components to write styles:
36
+
37
+ ```ts
38
+ import styled from "styled-components";
39
+
40
+ const div = styled.div`
41
+ color: red;
42
+ `;
43
+
44
+ console.log("div", div);
45
+ ```
46
+
47
+ ## Options
48
+
49
+ If you need to customize the compilation behavior of `styled-components`, you can use the following configs.
50
+
51
+ You can check the [styled-components documentation](https://styled-components.com/) to learn how to use it.
52
+
53
+ - **Type:**
54
+
55
+ ```ts
56
+ type StyledComponentsOptions = {
57
+ displayName?: boolean;
58
+ ssr?: boolean;
59
+ fileName?: boolean;
60
+ meaninglessFileNames?: string[];
61
+ namespace?: string;
62
+ topLevelImportPaths?: string[];
63
+ transpileTemplateLiterals?: boolean;
64
+ minify?: boolean;
65
+ pure?: boolean;
66
+ cssProps?: boolean;
67
+ };
68
+ ```
6
69
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
70
+ - **Default:**
8
71
 
9
- ## Documentation
72
+ ```ts
73
+ {
74
+ displayName: true,
75
+ // `isSSR` is true in SSR build
76
+ ssr: isSSR,
77
+ // `pure` is enabled in production to reduce bundle size
78
+ pure: isProd,
79
+ transpileTemplateLiterals: true,
80
+ }
81
+ ```
10
82
 
11
- https://rsbuild.dev/
83
+ - **Example:**
12
84
 
13
- ## Contributing
85
+ When the value is an Object, use the `Object.assign` function to merge with the default config.
14
86
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
87
+ ```ts title="rsbuild.config.ts"
88
+ pluginStyledComponents({
89
+ pure: true,
90
+ });
91
+ ```
16
92
 
17
93
  ## License
18
94
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
95
+ [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -1,99 +1,103 @@
1
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
2
+ // The require scope
3
+ var __webpack_require__ = {};
4
+ /************************************************************************/ // webpack/runtime/define_property_getters
5
+ (()=>{
6
+ __webpack_require__.d = function(exports1, definition) {
7
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
8
+ enumerable: true,
9
+ get: definition[key]
10
+ });
11
+ };
12
+ })();
13
+ // webpack/runtime/has_own_property
14
+ (()=>{
15
+ __webpack_require__.o = function(obj, prop) {
16
+ return Object.prototype.hasOwnProperty.call(obj, prop);
17
+ };
18
+ })();
19
+ // webpack/runtime/make_namespace_object
20
+ (()=>{
21
+ // define __esModule on exports
22
+ __webpack_require__.r = function(exports1) {
23
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
24
+ value: 'Module'
25
+ });
26
+ Object.defineProperty(exports1, '__esModule', {
27
+ value: true
28
+ });
29
+ };
30
+ })();
31
+ /************************************************************************/ var __webpack_exports__ = {};
32
+ // ESM COMPAT FLAG
33
+ __webpack_require__.r(__webpack_exports__);
34
+ // EXPORTS
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ PLUGIN_STYLED_COMPONENTS_NAME: ()=>/* binding */ PLUGIN_STYLED_COMPONENTS_NAME,
37
+ pluginStyledComponents: ()=>/* binding */ pluginStyledComponents
35
38
  });
36
- module.exports = __toCommonJS(src_exports);
37
- var import_reduce_configs = require("reduce-configs");
39
+ const external_node_module_namespaceObject = require("node:module");
40
+ const external_reduce_configs_namespaceObject = require("reduce-configs");
41
+ const src_require = (0, external_node_module_namespaceObject.createRequire)(/*#__PURE__*/ function() {
42
+ return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
43
+ }());
38
44
  function isServerTarget(target) {
39
- return Array.isArray(target) ? target.includes("node") : target === "node";
45
+ return Array.isArray(target) ? target.includes('node') : 'node' === target;
40
46
  }
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.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
66
- const rsbuildConfig = api.getRsbuildConfig();
67
- const targets = rsbuildConfig.environments ? Object.values(rsbuildConfig.environments).map(
68
- (e) => e.output?.target || userConfig.output?.target || "web"
69
- ) : [userConfig.output?.target || "web"];
70
- const useSSR = isServerTarget(targets);
71
- const mergedOptions = getMergedOptions(useSSR);
72
- if (!mergedOptions) {
73
- return userConfig;
74
- }
75
- const extraConfig = {
76
- tools: {
77
- swc: {
78
- jsc: {
79
- experimental: {
80
- plugins: [
81
- [
82
- require.resolve("@swc/plugin-styled-components"),
83
- mergedOptions
84
- ]
85
- ]
86
- }
87
- }
88
- }
47
+ const getDefaultStyledComponentsConfig = (isProd, ssr)=>({
48
+ ssr,
49
+ // "pure" is used to improve dead code elimination in production.
50
+ // we don't need to enable it in development because it will slow down the build process.
51
+ pure: isProd,
52
+ displayName: true,
53
+ transpileTemplateLiterals: true
54
+ });
55
+ const PLUGIN_STYLED_COMPONENTS_NAME = 'rsbuild:styled-components';
56
+ const pluginStyledComponents = (pluginOptions = {})=>({
57
+ name: PLUGIN_STYLED_COMPONENTS_NAME,
58
+ setup (api) {
59
+ if ('webpack' === api.context.bundlerType) return;
60
+ const getMergedOptions = (useSSR, config)=>{
61
+ const isProd = 'production' === config.mode;
62
+ return (0, external_reduce_configs_namespaceObject.reduceConfigs)({
63
+ initial: getDefaultStyledComponentsConfig(isProd, useSSR),
64
+ config: pluginOptions
65
+ });
66
+ };
67
+ api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig })=>{
68
+ var _userConfig_output;
69
+ const rsbuildConfig = api.getRsbuildConfig();
70
+ const targets = rsbuildConfig.environments ? Object.values(rsbuildConfig.environments).map((e)=>{
71
+ var _e_output, _userConfig_output;
72
+ return (null === (_e_output = e.output) || void 0 === _e_output ? void 0 : _e_output.target) || (null === (_userConfig_output = userConfig.output) || void 0 === _userConfig_output ? void 0 : _userConfig_output.target) || 'web';
73
+ }) : [
74
+ (null === (_userConfig_output = userConfig.output) || void 0 === _userConfig_output ? void 0 : _userConfig_output.target) || 'web'
75
+ ];
76
+ const useSSR = isServerTarget(targets);
77
+ const mergedOptions = getMergedOptions(useSSR, userConfig);
78
+ if (!mergedOptions) return userConfig;
79
+ const extraConfig = {
80
+ tools: {
81
+ swc: {
82
+ jsc: {
83
+ experimental: {
84
+ plugins: [
85
+ [
86
+ src_require.resolve('@swc/plugin-styled-components'),
87
+ mergedOptions
88
+ ]
89
+ ]
90
+ }
91
+ }
92
+ }
93
+ }
94
+ };
95
+ return mergeEnvironmentConfig(extraConfig, userConfig);
96
+ });
89
97
  }
90
- };
91
- return mergeEnvironmentConfig(extraConfig, userConfig);
92
98
  });
93
- }
94
- });
95
- // Annotate the CommonJS export names for ESM import in node:
96
- 0 && (module.exports = {
97
- PLUGIN_STYLED_COMPONENTS_NAME,
98
- pluginStyledComponents
99
+ var __webpack_export_target__ = exports;
100
+ for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
101
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
102
+ value: true
99
103
  });
package/dist/index.js CHANGED
@@ -1,78 +1,59 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
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
- });
11
-
12
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.56.2_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";
1
+ import * as __WEBPACK_EXTERNAL_MODULE_node_module__ from "node:module";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_reduce_configs__ from "reduce-configs";
3
+ const src_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module__.createRequire)(import.meta.url);
18
4
  function isServerTarget(target) {
19
- return Array.isArray(target) ? target.includes("node") : target === "node";
5
+ return Array.isArray(target) ? target.includes('node') : 'node' === target;
20
6
  }
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,
34
- setup(api) {
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
43
- });
44
- };
45
- api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig }) => {
46
- const rsbuildConfig = api.getRsbuildConfig();
47
- const targets = rsbuildConfig.environments ? Object.values(rsbuildConfig.environments).map(
48
- (e) => e.output?.target || userConfig.output?.target || "web"
49
- ) : [userConfig.output?.target || "web"];
50
- const useSSR = isServerTarget(targets);
51
- const mergedOptions = getMergedOptions(useSSR);
52
- if (!mergedOptions) {
53
- return userConfig;
54
- }
55
- const extraConfig = {
56
- tools: {
57
- swc: {
58
- jsc: {
59
- experimental: {
60
- plugins: [
61
- [
62
- __require.resolve("@swc/plugin-styled-components"),
63
- mergedOptions
64
- ]
65
- ]
66
- }
67
- }
68
- }
7
+ const getDefaultStyledComponentsConfig = (isProd, ssr)=>({
8
+ ssr,
9
+ // "pure" is used to improve dead code elimination in production.
10
+ // we don't need to enable it in development because it will slow down the build process.
11
+ pure: isProd,
12
+ displayName: true,
13
+ transpileTemplateLiterals: true
14
+ });
15
+ const PLUGIN_STYLED_COMPONENTS_NAME = 'rsbuild:styled-components';
16
+ const pluginStyledComponents = (pluginOptions = {})=>({
17
+ name: PLUGIN_STYLED_COMPONENTS_NAME,
18
+ setup (api) {
19
+ if ('webpack' === api.context.bundlerType) return;
20
+ const getMergedOptions = (useSSR, config)=>{
21
+ const isProd = 'production' === config.mode;
22
+ return (0, __WEBPACK_EXTERNAL_MODULE_reduce_configs__.reduceConfigs)({
23
+ initial: getDefaultStyledComponentsConfig(isProd, useSSR),
24
+ config: pluginOptions
25
+ });
26
+ };
27
+ api.modifyEnvironmentConfig((userConfig, { mergeEnvironmentConfig })=>{
28
+ var _userConfig_output;
29
+ const rsbuildConfig = api.getRsbuildConfig();
30
+ const targets = rsbuildConfig.environments ? Object.values(rsbuildConfig.environments).map((e)=>{
31
+ var _e_output, _userConfig_output;
32
+ return (null === (_e_output = e.output) || void 0 === _e_output ? void 0 : _e_output.target) || (null === (_userConfig_output = userConfig.output) || void 0 === _userConfig_output ? void 0 : _userConfig_output.target) || 'web';
33
+ }) : [
34
+ (null === (_userConfig_output = userConfig.output) || void 0 === _userConfig_output ? void 0 : _userConfig_output.target) || 'web'
35
+ ];
36
+ const useSSR = isServerTarget(targets);
37
+ const mergedOptions = getMergedOptions(useSSR, userConfig);
38
+ if (!mergedOptions) return userConfig;
39
+ const extraConfig = {
40
+ tools: {
41
+ swc: {
42
+ jsc: {
43
+ experimental: {
44
+ plugins: [
45
+ [
46
+ src_require.resolve('@swc/plugin-styled-components'),
47
+ mergedOptions
48
+ ]
49
+ ]
50
+ }
51
+ }
52
+ }
53
+ }
54
+ };
55
+ return mergeEnvironmentConfig(extraConfig, userConfig);
56
+ });
69
57
  }
70
- };
71
- return mergeEnvironmentConfig(extraConfig, userConfig);
72
58
  });
73
- }
74
- });
75
- export {
76
- PLUGIN_STYLED_COMPONENTS_NAME,
77
- pluginStyledComponents
78
- };
59
+ export { PLUGIN_STYLED_COMPONENTS_NAME, pluginStyledComponents };
package/package.json CHANGED
@@ -1,46 +1,65 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-styled-components",
3
- "version": "1.0.1-beta.9",
4
- "description": "styled-components plugin for Rsbuild",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/web-infra-dev/rsbuild",
8
- "directory": "packages/plugin-styled-components"
9
- },
3
+ "version": "1.1.0",
4
+ "repository": "https://github.com/rspack-contrib/rsbuild-plugin-styled-components",
10
5
  "license": "MIT",
11
6
  "type": "module",
12
7
  "exports": {
13
8
  ".": {
14
- "types": "./dist-types/index.d.ts",
9
+ "types": "./dist/index.d.ts",
15
10
  "import": "./dist/index.js",
16
11
  "require": "./dist/index.cjs"
17
12
  }
18
13
  },
19
- "main": "./dist/index.cjs",
20
- "types": "./dist-types/index.d.ts",
21
- "files": [
22
- "dist",
23
- "dist-types"
24
- ],
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
16
+ "types": "./dist/index.d.ts",
17
+ "files": ["dist"],
18
+ "scripts": {
19
+ "build": "rslib build",
20
+ "dev": "rslib build --watch",
21
+ "lint": "biome check .",
22
+ "lint:write": "biome check . --write",
23
+ "prepare": "simple-git-hooks && npm run build",
24
+ "test": "playwright test",
25
+ "bump": "npx bumpp"
26
+ },
27
+ "simple-git-hooks": {
28
+ "pre-commit": "npx nano-staged"
29
+ },
30
+ "nano-staged": {
31
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
32
+ "biome check --write --no-errors-on-unmatched"
33
+ ]
34
+ },
25
35
  "dependencies": {
26
- "@swc/plugin-styled-components": "2.0.10",
36
+ "@swc/plugin-styled-components": "5.0.0",
27
37
  "reduce-configs": "^1.0.0"
28
38
  },
29
39
  "devDependencies": {
30
- "@types/node": "18.x",
31
- "typescript": "^5.5.2",
32
- "@rsbuild/core": "1.0.1-beta.9"
40
+ "@biomejs/biome": "^1.9.4",
41
+ "@playwright/test": "^1.48.2",
42
+ "@rsbuild/core": "^1.1.0",
43
+ "@rslib/core": "^0.0.16",
44
+ "@types/node": "^20.17.6",
45
+ "nano-staged": "^0.8.0",
46
+ "playwright": "^1.48.2",
47
+ "simple-git-hooks": "^2.11.1",
48
+ "styled-components": "^6.1.13",
49
+ "typescript": "^5.6.3"
33
50
  },
34
51
  "peerDependencies": {
35
- "@rsbuild/core": "^1.0.1-beta.9"
52
+ "@rsbuild/core": "1.x"
36
53
  },
54
+ "peerDependenciesMeta": {
55
+ "@rsbuild/core": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "packageManager": "pnpm@9.12.3",
37
60
  "publishConfig": {
38
61
  "access": "public",
39
- "provenance": true,
40
- "registry": "https://registry.npmjs.org/"
41
- },
42
- "scripts": {
43
- "build": "modern build",
44
- "dev": "modern build --watch"
62
+ "registry": "https://registry.npmjs.org/",
63
+ "provenance": true
45
64
  }
46
- }
65
+ }
@@ -1 +0,0 @@
1
- {"//":"This file is for making TypeScript work with moduleResolution node16+.","version":"1.0.0"}
File without changes