You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/document/docs/en/configure/app/tools/ts-loader.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: tsLoader
6
6
7
7
import { Badge } from'@theme';
8
8
9
-
<Badgetype="danger">Webpack Only</Badge>
9
+
<Badgetype="danger">Webpack Only</Badge>
10
10
11
11
-**Type:**`Object | Function | undefined`
12
12
-**Default:**`undefined`
@@ -15,7 +15,7 @@ import { Badge } from '@theme';
15
15
16
16
ts-loader is not recommended for use in the project, because:
17
17
18
-
- ts-loader cannot be used with certain features such as [source.transformImport](/configure/app/source/transform-import) and [tools.styledComponents](/configure/app/tools/styled-components)provided by Babel & SWC.
18
+
- ts-loader cannot be used with certain features such as [source.transformImport](/configure/app/source/transform-import)provided by Babel & SWC.
CSS-in-JS is a technique that allows you to write CSS styles in JS files.
3
+
CSS-in-JS is a technique that allows you to write CSS styles within JS files.
4
4
5
-
Modern.js supports the popular CSS-in-JS implementation library [styled-components](https://styled-components.com/), 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. You can directly import the API of [styled-components](https://styled-components.com/) from `@modern-js/runtime/styled` for use.
5
+
Modern.js supports the commonly used community CSS-in-JS library [styled-components](https://styled-components.com/), which uses JavaScript's new feature [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write component CSS styles.
6
+
7
+
The Modern.js plugin `@modern-js/plugin-styled-components` provides support for styled-components and adds server-side rendering capability for styled-components. You can use styled-components by installing the `@modern-js/plugin-styled-components` plugin.
6
8
7
9
## Using styled-components in Modern.js
8
-
First, you need to install the `styled-components` dependency:
9
10
10
-
```bash
11
-
# npm
12
-
npm add @rsbuild/plugin-styled-components -D
11
+
First, you need to install the `styled-components` plugin dependency:
13
12
14
-
# yarn
15
-
yarn add @rsbuild/plugin-styled-components -D
13
+
import { PackageManagerTabs } from'@theme';
16
14
17
-
# pnpm
18
-
pnpm add @rsbuild/plugin-styled-components -D
19
-
```
20
-
Then, configure the `styled-components` plugin in `modern.config.ts`:
The configuration options of the styledComponentsPlugin plugin are the same as those of the [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) plugin. You can refer to the documentation of [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) for configuration.
38
41
39
-
When you need to write a `div` component with an internal font color of red, you can implement it as follows:
42
+
## Writing styles with styled-components
43
+
44
+
When you need to write a `div` component with red text inside, you can implement it as follows:
If you need to dynamically set component styles based on the component's `props`, for example, the `primary`property of `props` is `true`, the button color is white, otherwise it is red, you can implement the code as follows:
54
+
When you need to dynamically set component styles based on the component's `props`, for example, when the `primary`attribute of `props` is `true`, the button's color is white, otherwise red, the implementation is as follows:
For more usage of styled-components, please refer to [styled-components official website](https://styled-components.com/).
61
-
62
-
Modern.js integrates Babel's [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) plugin internally, and you can configure the plugin through [tools.styledComponents](/configure/app/tools/styled-components).
65
+
For more usage of styled-components, please refer to the [styled-components official website](https://styled-components.com/).
63
66
64
-
:::tip
65
-
If you need to use other CSS-in-JS libraries such as [styled-jsx](https://www.npmjs.com/package/styled-jsx) and [Emotion](https://emotion.sh/), you need to install the corresponding dependencies first. For specific usage, please refer to the library's official website.
67
+
:::tip Tip
68
+
If you want to use other CSS-in-JS libraries such as [styled-jsx](https://www.npmjs.com/package/styled-jsx), [Emotion](https://emotion.sh/), etc., you need to install the corresponding dependencies first. Please refer to the official websites of the respective libraries for specific usage.
Copy file name to clipboardExpand all lines: packages/document/docs/en/guides/troubleshooting/builder.mdx
-14Lines changed: 0 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -188,20 +188,6 @@ export default {
188
188
};
189
189
```
190
190
191
-
In addition to the reasons mentioned above, there is another possibility that can cause Babel compilation to hang, which is when Babel compiles a large JS file exceeding 10,000 lines (usually a large file in the node_modules directory that is compiled using `source.include`).
192
-
193
-
When Babel compiles large files, the built-in babel-plugin-styled-components in Modern.js can cause the compilation to hang. There is already a [relevant issue](https://github.com/styled-components/babel-plugin-styled-components/issues/374) in the community .
194
-
195
-
In the future, Modern.js will consider removing the built-in babel-plugin-styled-components. In the current version, you can set [tools.styledComponents](/configure/app/tools/styled-components.html) to `false` to remove this plugin.
0 commit comments