@modern-js/module-tools-docs 2.30.0 → 2.31.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/CHANGELOG.md +7 -0
- package/docs/en/api/config/build-config.mdx +49 -49
- package/docs/en/api/config/build-preset.mdx +15 -33
- package/docs/en/api/config/design-system.md +42 -34
- package/docs/en/api/config/plugins.md +3 -3
- package/docs/en/api/config/testing.md +2 -2
- package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
- package/docs/en/components/register-esbuild-plugin.mdx +2 -2
- package/docs/en/guide/advance/asset.mdx +8 -27
- package/docs/en/guide/advance/build-umd.mdx +18 -66
- package/docs/en/guide/advance/external-dependency.mdx +7 -27
- package/docs/en/guide/advance/in-depth-about-build.md +4 -4
- package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
- package/docs/en/guide/advance/theme-config.mdx +4 -8
- package/docs/en/guide/basic/before-getting-started.md +1 -1
- package/docs/en/guide/basic/publish-your-project.md +8 -7
- package/docs/en/guide/basic/test-your-project.mdx +10 -47
- package/docs/en/guide/basic/use-micro-generator.md +4 -4
- package/docs/en/guide/basic/using-storybook.mdx +12 -44
- package/docs/en/guide/best-practices/components.mdx +44 -402
- package/docs/en/guide/faq/build.mdx +16 -0
- package/docs/en/guide/intro/getting-started.md +2 -2
- package/docs/en/plugins/guide/getting-started.mdx +8 -24
- package/docs/en/plugins/guide/plugin-object.mdx +2 -8
- package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
- package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
- package/docs/zh/api/config/build-config.mdx +52 -52
- package/docs/zh/api/config/build-preset.mdx +12 -30
- package/docs/zh/api/config/design-system.md +6 -6
- package/docs/zh/api/config/plugins.md +3 -3
- package/docs/zh/api/config/testing.md +2 -2
- package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
- package/docs/zh/guide/advance/asset.mdx +9 -30
- package/docs/zh/guide/advance/build-umd.mdx +19 -67
- package/docs/zh/guide/advance/external-dependency.mdx +8 -28
- package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
- package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
- package/docs/zh/guide/advance/theme-config.mdx +4 -8
- package/docs/zh/guide/basic/publish-your-project.md +2 -2
- package/docs/zh/guide/basic/test-your-project.mdx +11 -49
- package/docs/zh/guide/basic/use-micro-generator.md +4 -4
- package/docs/zh/guide/basic/using-storybook.mdx +13 -45
- package/docs/zh/guide/best-practices/components.mdx +50 -410
- package/docs/zh/guide/faq/build.mdx +16 -0
- package/docs/zh/guide/intro/getting-started.md +1 -1
- package/docs/zh/plugins/guide/getting-started.mdx +8 -24
- package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
- package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
- package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
- package/modern.config.ts +1 -12
- package/package.json +3 -5
- package/theme/index.ts +0 -2
- package/theme/index.css +0 -9
|
@@ -4,9 +4,9 @@ This chapter will describe how to develop component projects using the Module To
|
|
|
4
4
|
|
|
5
5
|
## Initialize the project
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
1. It is recommended to use the `@modern-js/create` command to initialize an npm project.
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```text title="Interactive questions"
|
|
10
10
|
npx @modern-js/create@latest components-project
|
|
11
11
|
|
|
12
12
|
? Please select the type of project you want to create: Npm Module
|
|
@@ -15,24 +15,9 @@ npx @modern-js/create@latest components-project
|
|
|
15
15
|
? Please select the package manager: pnpm
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
2. The initialized directory structure:
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
```bash Interactive questions
|
|
23
|
-
npx @modern-js/create@latest components-project
|
|
24
|
-
|
|
25
|
-
? Please select the type of project you want to create: Npm Module
|
|
26
|
-
? Please fill in the project name: components-demo
|
|
27
|
-
? Please select the programming language: TS
|
|
28
|
-
? Please select the package manager: pnpm
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
The initialized directory structure.
|
|
34
|
-
|
|
35
|
-
```bash The initialized directory structure
|
|
20
|
+
```bash
|
|
36
21
|
.
|
|
37
22
|
├── README.md
|
|
38
23
|
├── node_modules/
|
|
@@ -46,149 +31,17 @@ The initialized directory structure.
|
|
|
46
31
|
└── tsconfig.json
|
|
47
32
|
```
|
|
48
33
|
|
|
49
|
-
|
|
34
|
+
3. Finally, modify the file suffix and content of `./src/index.ts` as follows, and the initialization of the component project is completed.
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
At this point, a component project is initialized.
|
|
54
|
-
|
|
55
|
-
```tsx ./src/index.tsx
|
|
36
|
+
```tsx title="./src/index.tsx"
|
|
56
37
|
export default () => {
|
|
57
38
|
return <div>hello world</div>;
|
|
58
39
|
};
|
|
59
40
|
```
|
|
60
41
|
|
|
61
|
-
</CH.Spotlight>
|
|
62
|
-
|
|
63
42
|
## Debugging code with Storybook
|
|
64
43
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```bash Terminal
|
|
68
|
-
pnpm run new
|
|
69
|
-
|
|
70
|
-
? Please select the operation you want: Enable features
|
|
71
|
-
? Please select the feature name: Enable Visual Testing (Storybook)
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
Execute the `new` command in the project root directory to enable the Storybook feature.
|
|
77
|
-
|
|
78
|
-
```bash Terminal
|
|
79
|
-
pnpm run new
|
|
80
|
-
|
|
81
|
-
? Please select the operation you want: Enable features
|
|
82
|
-
? Please select the feature name: Enable Visual Testing (Storybook)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
Once successfully opened, you will see that a new dependency has been added to `package.json`. The `stories` directory and related initialization files are also created.
|
|
88
|
-
|
|
89
|
-
<CH.Code>
|
|
90
|
-
|
|
91
|
-
```json ./package.json focus=4:7
|
|
92
|
-
{
|
|
93
|
-
"name": "components-demo",
|
|
94
|
-
"devDependencies": {
|
|
95
|
-
"@modern-js/plugin-storybook": "x.y.z",
|
|
96
|
-
"@modern-js/runtime": "x.y.z",
|
|
97
|
-
"react": "^17",
|
|
98
|
-
"react-dom": "^17"
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
```bash Directory Structure
|
|
104
|
-
.
|
|
105
|
-
├── src
|
|
106
|
-
│ ├── index.ts
|
|
107
|
-
│ └── modern-app-env.d.ts
|
|
108
|
-
├── stories
|
|
109
|
-
│ ├── .eslintrc.js
|
|
110
|
-
│ ├── index.stories.tsx
|
|
111
|
-
│ └── tsconfig.json
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
</CH.Code>
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
After initialization, the `tsconfig.json` file in the `. /stories` directory, the `tsconfig.json` file is set by default with the `paths` configuration of the same name as the project.
|
|
119
|
-
|
|
120
|
-
```json ./stories/tsconfig.json focus=5:7
|
|
121
|
-
{
|
|
122
|
-
"extends": "../tsconfig.json",
|
|
123
|
-
"compilerOptions": {
|
|
124
|
-
"baseUrl": "../",
|
|
125
|
-
"paths": {
|
|
126
|
-
"components-demo": ["./"],
|
|
127
|
-
"components-demo/*": ["./*"]
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
"include": ["**/*"]
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
Such a configuration allows you to introduce code in Story code directly using the name of the project.
|
|
137
|
-
|
|
138
|
-
<CH.Code>
|
|
139
|
-
|
|
140
|
-
```tsx ./stories/index.stories.tsx
|
|
141
|
-
import Component from 'components-demo';
|
|
142
|
-
|
|
143
|
-
export const YourStory = () => <Component />;
|
|
144
|
-
|
|
145
|
-
export default {
|
|
146
|
-
title: 'Your Stories',
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
```tsx ./src/index.tsx
|
|
153
|
-
export default () => {
|
|
154
|
-
return <div>hello world</div>;
|
|
155
|
-
};
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
</CH.Code>
|
|
159
|
-
|
|
160
|
-
---
|
|
161
|
-
|
|
162
|
-
At this point Storybook identifies the entry point for the imported code based on fields like `main`, `exports` in the project's `package.json` file.
|
|
163
|
-
The location of the type file is determined by the `types` field.
|
|
164
|
-
|
|
165
|
-
```json package.json
|
|
166
|
-
{
|
|
167
|
-
"name": "components-demo",
|
|
168
|
-
"main": "./dist/esm/index.js",
|
|
169
|
-
"types": "./dist/types/index.d.ts"
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
While importing source code for debugging is also supported, debugging using project artifacts is more reliable.
|
|
176
|
-
|
|
177
|
-
Debugging with source code has a limitation: some configurations are not equivalent in Storybook and in the original build support.
|
|
178
|
-
|
|
179
|
-
**This is why debugging with the output code is recommended**.
|
|
180
|
-
|
|
181
|
-
```tsx ./stories/index.stories.tsx
|
|
182
|
-
import Component from '../src';
|
|
183
|
-
|
|
184
|
-
export const YourStory = () => <Component />;
|
|
185
|
-
|
|
186
|
-
export default {
|
|
187
|
-
title: 'Your Stories',
|
|
188
|
-
};
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
</CH.Spotlight>
|
|
44
|
+
Please refer to ["Using Storybook"](/guide/basic/using-storybook.html) to debug code using Storybook.
|
|
192
45
|
|
|
193
46
|
## Developing Styles
|
|
194
47
|
|
|
@@ -216,9 +69,9 @@ The module project supports PostCSS and has the following built-in PostCSS plugi
|
|
|
216
69
|
|
|
217
70
|
So we can create `.css` files in our projects and use the syntax support and capabilities provided by these plugins directly in our css files.
|
|
218
71
|
|
|
219
|
-
|
|
72
|
+
- Source Code:
|
|
220
73
|
|
|
221
|
-
```
|
|
74
|
+
```less title="./src/index.css"
|
|
222
75
|
a,
|
|
223
76
|
b {
|
|
224
77
|
color: red;
|
|
@@ -236,19 +89,9 @@ b {
|
|
|
236
89
|
}
|
|
237
90
|
```
|
|
238
91
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
Source Code.
|
|
242
|
-
|
|
243
|
-
```css ./src/index.css
|
|
244
|
-
|
|
245
|
-
```
|
|
92
|
+
- CSS artifact:
|
|
246
93
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
css product.
|
|
250
|
-
|
|
251
|
-
```css ./dist/es/index.css
|
|
94
|
+
```css title="./dist/es/index.css"
|
|
252
95
|
a,
|
|
253
96
|
b {
|
|
254
97
|
color: red;
|
|
@@ -265,17 +108,15 @@ e b {
|
|
|
265
108
|
}
|
|
266
109
|
```
|
|
267
110
|
|
|
268
|
-
</CH.Spotlight>
|
|
269
|
-
|
|
270
111
|
### Less
|
|
271
112
|
|
|
272
113
|
Module projects support development styles using Less.
|
|
273
114
|
|
|
274
115
|
> The current built-in Less version is v4.1.3
|
|
275
116
|
|
|
276
|
-
|
|
117
|
+
- Source Code:
|
|
277
118
|
|
|
278
|
-
```less ./src/common.less
|
|
119
|
+
```less title="./src/common.less"
|
|
279
120
|
@bg: black;
|
|
280
121
|
@bg-light: boolean(luma(@bg) > 50%);
|
|
281
122
|
|
|
@@ -285,36 +126,24 @@ div {
|
|
|
285
126
|
}
|
|
286
127
|
```
|
|
287
128
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
Source Code.
|
|
291
|
-
|
|
292
|
-
```less ./src/common.less
|
|
129
|
+
- Less artifact:
|
|
293
130
|
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
---
|
|
297
|
-
|
|
298
|
-
Less product.
|
|
299
|
-
|
|
300
|
-
```css ./dist/es/common.css
|
|
131
|
+
```css title="./dist/es/common.css"
|
|
301
132
|
div {
|
|
302
133
|
background: black;
|
|
303
134
|
color: white;
|
|
304
135
|
}
|
|
305
136
|
```
|
|
306
137
|
|
|
307
|
-
</CH.Spotlight>
|
|
308
|
-
|
|
309
138
|
### Sass/Scss
|
|
310
139
|
|
|
311
140
|
Module projects support developing styles using Scss/Sass.
|
|
312
141
|
|
|
313
142
|
> The current built-in Sass version is v1.54.4
|
|
314
143
|
|
|
315
|
-
|
|
144
|
+
- Source code:
|
|
316
145
|
|
|
317
|
-
```sass ./src/common.sass
|
|
146
|
+
```sass title="./src/common.sass"
|
|
318
147
|
$font-stack: Helvetica, sans-serif;
|
|
319
148
|
$primary-color: #333;
|
|
320
149
|
|
|
@@ -324,58 +153,33 @@ body {
|
|
|
324
153
|
}
|
|
325
154
|
```
|
|
326
155
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
源代码。
|
|
330
|
-
|
|
331
|
-
```sass ./src/common.sass
|
|
332
|
-
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
---
|
|
336
|
-
|
|
337
|
-
Less product.
|
|
156
|
+
- Less artifact:
|
|
338
157
|
|
|
339
|
-
```css ./dist/es/common.css
|
|
158
|
+
```css title="./dist/es/common.css"
|
|
340
159
|
body {
|
|
341
160
|
font: 100% Helvetica, sans-serif;
|
|
342
161
|
color: #333;
|
|
343
162
|
}
|
|
344
163
|
```
|
|
345
164
|
|
|
346
|
-
</CH.Spotlight>
|
|
347
|
-
|
|
348
165
|
### Tailwind CSS
|
|
349
166
|
|
|
350
167
|
The module project supports the development of component styles using Tailwind CSS.
|
|
351
168
|
|
|
352
169
|
By default, this feature is not enabled in the module project, you need to enable it as follows.
|
|
353
170
|
|
|
354
|
-
|
|
171
|
+
1. The Tailwind CSS feature can be enabled by executing the `new` command in the project root directory.
|
|
355
172
|
|
|
356
|
-
```
|
|
357
|
-
pnpm run new
|
|
358
|
-
|
|
359
|
-
? Please select the operation you want: Enable features
|
|
360
|
-
? Please select the feature name: Enable Visual Testing (Storybook)
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
---
|
|
364
|
-
|
|
365
|
-
The Tailwind CSS feature can be enabled by executing the `new` command in the project root directory.
|
|
366
|
-
|
|
367
|
-
```bash Terminal
|
|
173
|
+
```text title="Terminal"
|
|
368
174
|
pnpm run new
|
|
369
175
|
|
|
370
176
|
? Please select the operation you want: Enable features
|
|
371
177
|
? Please select the feature name: Enable Tailwind CSS
|
|
372
178
|
```
|
|
373
179
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
Once successfully opened, you will see that a new dependency has been added to `package.json`.
|
|
180
|
+
2. Once successfully enabled, you will see that a new dependency has been added to `package.json`.
|
|
377
181
|
|
|
378
|
-
```json ./package.json
|
|
182
|
+
```json title="./package.json"
|
|
379
183
|
{
|
|
380
184
|
"devDependencies": {
|
|
381
185
|
"@modern-js/plugin-tailwindcss": "x.y.z"
|
|
@@ -383,15 +187,13 @@ Once successfully opened, you will see that a new dependency has been added to `
|
|
|
383
187
|
}
|
|
384
188
|
```
|
|
385
189
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
Tailwind CSS offers two ways to use it.
|
|
190
|
+
3. Tailwind CSS offers two ways to use it.
|
|
389
191
|
|
|
390
192
|
#### HTML class
|
|
391
193
|
|
|
392
|
-
|
|
194
|
+
Tailwind CSS supports adding styles to HTML tags by using class names. **When using HTML class names, be sure to import the Tailwind CSS equivalent css file. **
|
|
393
195
|
|
|
394
|
-
```tsx ./src/index.tsx
|
|
196
|
+
```tsx title="./src/index.tsx"
|
|
395
197
|
import 'tailwindcss/utilities.css';
|
|
396
198
|
|
|
397
199
|
export default () => {
|
|
@@ -399,61 +201,13 @@ export default () => {
|
|
|
399
201
|
};
|
|
400
202
|
```
|
|
401
203
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
Tailwind CSS supports adding styles to HTML tags by using class names.
|
|
405
|
-
|
|
406
|
-
```tsx ./src/index.tsx focus=5:5
|
|
407
|
-
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
---
|
|
411
|
-
|
|
412
|
-
**When using HTML class names, be sure to import the Tailwind CSS equivalent css file. **
|
|
413
|
-
|
|
414
|
-
```tsx ./src/index.tsx focus=1:1
|
|
415
|
-
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
---
|
|
419
|
-
|
|
420
|
-
Style product.
|
|
421
|
-
|
|
422
|
-
> This is a bundle build.
|
|
204
|
+
Style product (This is a bundle build):
|
|
423
205
|
|
|
424
|
-
```css ./dist/es/index.css
|
|
425
|
-
/*
|
|
206
|
+
```css title="./dist/es/index.css"
|
|
207
|
+
/* node_modules/tailwindcss/utilities.css */
|
|
426
208
|
.table {
|
|
427
209
|
display: table;
|
|
428
210
|
}
|
|
429
|
-
@keyframes spin {
|
|
430
|
-
to {
|
|
431
|
-
transform: rotate(360deg);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
@keyframes ping {
|
|
435
|
-
75%,
|
|
436
|
-
100% {
|
|
437
|
-
transform: scale(2);
|
|
438
|
-
opacity: 0;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
@keyframes pulse {
|
|
442
|
-
50% {
|
|
443
|
-
opacity: 0.5;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
@keyframes bounce {
|
|
447
|
-
0%,
|
|
448
|
-
100% {
|
|
449
|
-
transform: translateY(-25%);
|
|
450
|
-
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
|
|
451
|
-
}
|
|
452
|
-
50% {
|
|
453
|
-
transform: none;
|
|
454
|
-
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
211
|
.bg-black {
|
|
458
212
|
--tw-bg-opacity: 1;
|
|
459
213
|
background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
|
|
@@ -462,35 +216,9 @@ Style product.
|
|
|
462
216
|
--tw-text-opacity: 1;
|
|
463
217
|
color: rgba(255, 255, 255, var(--tw-text-opacity));
|
|
464
218
|
}
|
|
465
|
-
|
|
466
|
-
::before,
|
|
467
|
-
::after {
|
|
468
|
-
--tw-shadow: 0 0 #0000;
|
|
469
|
-
}
|
|
470
|
-
*,
|
|
471
|
-
::before,
|
|
472
|
-
::after {
|
|
473
|
-
--tw-ring-inset: var(--tw-empty);
|
|
474
|
-
--tw-ring-offset-width: 0px;
|
|
475
|
-
--tw-ring-offset-color: #fff;
|
|
476
|
-
--tw-ring-color: rgba(59, 130, 246, 0.5);
|
|
477
|
-
--tw-ring-offset-shadow: 0 0 #0000;
|
|
478
|
-
--tw-ring-shadow: 0 0 #0000;
|
|
479
|
-
}
|
|
480
|
-
@media (min-width: 640px) {
|
|
481
|
-
}
|
|
482
|
-
@media (min-width: 768px) {
|
|
483
|
-
}
|
|
484
|
-
@media (min-width: 1024px) {
|
|
485
|
-
}
|
|
486
|
-
@media (min-width: 1280px) {
|
|
487
|
-
}
|
|
488
|
-
@media (min-width: 1536px) {
|
|
489
|
-
}
|
|
219
|
+
/** some more... */
|
|
490
220
|
```
|
|
491
221
|
|
|
492
|
-
</CH.Spotlight>
|
|
493
|
-
|
|
494
222
|
#### `@apply`
|
|
495
223
|
|
|
496
224
|
Tailwind CSS provides the [`@apply`](https://v2.tailwindcss.com/docs/functions-and-directives#apply) directive, which allows us to inline the styles provided by Tailwind CSS into the styles we write.
|
|
@@ -509,7 +237,7 @@ However, there are some things to keep in mind when using Less and Sass.
|
|
|
509
237
|
|
|
510
238
|
When using Tailwind with Sass, the presence of `!important` after `@apply` requires interpolation to get Sass to compile correctly.
|
|
511
239
|
|
|
512
|
-
|
|
240
|
+
- It does not work properly:
|
|
513
241
|
|
|
514
242
|
```sass
|
|
515
243
|
.alert {
|
|
@@ -517,17 +245,7 @@ When using Tailwind with Sass, the presence of `!important` after `@apply` requi
|
|
|
517
245
|
}
|
|
518
246
|
```
|
|
519
247
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
It does not work properly.
|
|
523
|
-
|
|
524
|
-
```sass
|
|
525
|
-
|
|
526
|
-
```
|
|
527
|
-
|
|
528
|
-
---
|
|
529
|
-
|
|
530
|
-
Can work properly.
|
|
248
|
+
- Can work properly:
|
|
531
249
|
|
|
532
250
|
```sass
|
|
533
251
|
.alert {
|
|
@@ -535,13 +253,11 @@ Can work properly.
|
|
|
535
253
|
}
|
|
536
254
|
```
|
|
537
255
|
|
|
538
|
-
</CH.Spotlight>
|
|
539
|
-
|
|
540
256
|
##### Less
|
|
541
257
|
|
|
542
258
|
When using Tailwind with Less, you cannot nest Tailwind's `@screen` directive.
|
|
543
259
|
|
|
544
|
-
|
|
260
|
+
- It does not work properly:
|
|
545
261
|
|
|
546
262
|
```less
|
|
547
263
|
.card {
|
|
@@ -553,21 +269,9 @@ When using Tailwind with Less, you cannot nest Tailwind's `@screen` directive.
|
|
|
553
269
|
}
|
|
554
270
|
```
|
|
555
271
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
It does not work properly.
|
|
559
|
-
|
|
560
|
-
```less
|
|
561
|
-
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
---
|
|
565
|
-
|
|
566
|
-
Instead, use regular media queries and the `theme()` function to reference your screen size, or simply don't nest your `@screen` directive.
|
|
567
|
-
|
|
568
|
-
<CH.Code>
|
|
272
|
+
- Instead, use regular media queries and the `theme()` function to reference your screen size, or simply don't nest your `@screen` directive.
|
|
569
273
|
|
|
570
|
-
```less Method One
|
|
274
|
+
```less title="Method One"
|
|
571
275
|
// Use a regular media query and theme()
|
|
572
276
|
.card {
|
|
573
277
|
@apply rounded-none;
|
|
@@ -578,9 +282,7 @@ Instead, use regular media queries and the `theme()` function to reference your
|
|
|
578
282
|
}
|
|
579
283
|
```
|
|
580
284
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
```less Method Two
|
|
285
|
+
```less title="Method Two"
|
|
584
286
|
// Use the @screen directive at the top-level
|
|
585
287
|
.card {
|
|
586
288
|
@apply rounded-none;
|
|
@@ -591,10 +293,6 @@ Instead, use regular media queries and the `theme()` function to reference your
|
|
|
591
293
|
}
|
|
592
294
|
```
|
|
593
295
|
|
|
594
|
-
</CH.Code>
|
|
595
|
-
|
|
596
|
-
</CH.Spotlight>
|
|
597
|
-
|
|
598
296
|
#### Recommended method
|
|
599
297
|
|
|
600
298
|
**It is recommended to develop styles in the way specified by `@apply`, so that only styles inlined by directives are included in the style product. **
|
|
@@ -607,7 +305,7 @@ For the following code, there is a big difference between the bundle and bundlel
|
|
|
607
305
|
|
|
608
306
|
> The so-called bundle and bundleless can be found in ["Bundle and Bundleless"](/en/guide/advance/in-depth-about-build#bundle- and-bundleless)
|
|
609
307
|
|
|
610
|
-
```tsx ./src/index.tsx
|
|
308
|
+
```tsx title="./src/index.tsx"
|
|
611
309
|
import 'tailwindcss/utilities.css';
|
|
612
310
|
|
|
613
311
|
export default () => {
|
|
@@ -621,38 +319,11 @@ For styles, a separate output file is generated, and there is no code related to
|
|
|
621
319
|
|
|
622
320
|
If you need to inject styles into JS output files, you can enable the [`style.inject`](/en/api/config/build-config#styleinject) option.
|
|
623
321
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
/* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */
|
|
322
|
+
```css title="./dist/es/index.css"
|
|
323
|
+
/* node_modules/tailwindcss/utilities.css */
|
|
627
324
|
.table {
|
|
628
325
|
display: table;
|
|
629
326
|
}
|
|
630
|
-
@keyframes spin {
|
|
631
|
-
to {
|
|
632
|
-
transform: rotate(360deg);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
@keyframes ping {
|
|
636
|
-
75%, 100% {
|
|
637
|
-
transform: scale(2);
|
|
638
|
-
opacity: 0;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
@keyframes pulse {
|
|
642
|
-
50% {
|
|
643
|
-
opacity: .5;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
@keyframes bounce {
|
|
647
|
-
0%, 100% {
|
|
648
|
-
transform: translateY(-25%);
|
|
649
|
-
animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
|
|
650
|
-
}
|
|
651
|
-
50% {
|
|
652
|
-
transform: none;
|
|
653
|
-
animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
327
|
.bg-black {
|
|
657
328
|
--tw-bg-opacity: 1;
|
|
658
329
|
background-color: rgba(0, 0, 0, var(--tw-bg-opacity));
|
|
@@ -661,33 +332,9 @@ If you need to inject styles into JS output files, you can enable the [`style.in
|
|
|
661
332
|
--tw-text-opacity: 1;
|
|
662
333
|
color: rgba(255, 255, 255, var(--tw-text-opacity));
|
|
663
334
|
}
|
|
664
|
-
|
|
665
|
-
::before,
|
|
666
|
-
::after {
|
|
667
|
-
--tw-shadow: 0 0 #0000 ;
|
|
668
|
-
}
|
|
669
|
-
*,
|
|
670
|
-
::before,
|
|
671
|
-
::after {
|
|
672
|
-
--tw-ring-inset: var(--tw-empty, );
|
|
673
|
-
--tw-ring-offset-width: 0px;
|
|
674
|
-
--tw-ring-offset-color: #fff;
|
|
675
|
-
--tw-ring-color: rgba(59, 130, 246, 0.5);
|
|
676
|
-
--tw-ring-offset-shadow: 0 0 #0000;
|
|
677
|
-
--tw-ring-shadow: 0 0 #0000 ;
|
|
678
|
-
}
|
|
679
|
-
@media (min-width: 640px) {
|
|
680
|
-
}
|
|
681
|
-
@media (min-width: 768px) {
|
|
682
|
-
}
|
|
683
|
-
@media (min-width: 1024px) {
|
|
684
|
-
}
|
|
685
|
-
@media (min-width: 1280px) {
|
|
686
|
-
}
|
|
687
|
-
@media (min-width: 1536px) {
|
|
688
|
-
}
|
|
335
|
+
/** some more... */
|
|
689
336
|
```
|
|
690
|
-
|
|
337
|
+
|
|
691
338
|
``` js ./dist/es/index.js
|
|
692
339
|
// src/index.tsx
|
|
693
340
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -701,11 +348,10 @@ export {
|
|
|
701
348
|
src_default as default
|
|
702
349
|
};
|
|
703
350
|
```
|
|
704
|
-
</CH.Code>
|
|
705
351
|
|
|
706
352
|
In Bundleless mode, no third-party dependencies are bundled, and no style artifacts are generated at this time.
|
|
707
353
|
|
|
708
|
-
```js ./dist/es/index.js
|
|
354
|
+
```js title="./dist/es/index.js"
|
|
709
355
|
import { jsx } from 'react/jsx-runtime';
|
|
710
356
|
import 'tailwindcss/utilities.css';
|
|
711
357
|
var src_default = () => {
|
|
@@ -733,9 +379,7 @@ If you need to configure CSS Modules, you can check out the API at
|
|
|
733
379
|
|
|
734
380
|
The following is a code example.
|
|
735
381
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
```tsx ./src/index.tsx
|
|
382
|
+
```tsx title="./src/index.tsx"
|
|
739
383
|
import style from './index.module.css';
|
|
740
384
|
|
|
741
385
|
export default () => {
|
|
@@ -743,14 +387,12 @@ export default () => {
|
|
|
743
387
|
};
|
|
744
388
|
```
|
|
745
389
|
|
|
746
|
-
```css ./src/index.module.css
|
|
390
|
+
```css title="./src/index.module.css"
|
|
747
391
|
.btn {
|
|
748
392
|
color: blue;
|
|
749
393
|
}
|
|
750
394
|
```
|
|
751
395
|
|
|
752
|
-
</CH.Code>
|
|
753
|
-
|
|
754
396
|
## Configuring build products
|
|
755
397
|
|
|
756
398
|
Based on most scenarios of component project usage, **it is recommended to use the `npm-component` build preset**. This preset yields a output directory structure of
|
|
@@ -234,3 +234,19 @@ import RegisterEsbuildPlugin from '@site-docs-en/components/register-esbuild-plu
|
|
|
234
234
|
|
|
235
235
|
- First Solution: [typed-css-modules](https://github.com/Quramy/typed-css-modules)
|
|
236
236
|
- Second Solution: [postcss-modules-dts](https://www.npmjs.com/package/@guanghechen/postcss-modules-dts)
|
|
237
|
+
|
|
238
|
+
```ts title="modern.config.ts"
|
|
239
|
+
import { defineConfig } from '@modern-js/module-tools';
|
|
240
|
+
|
|
241
|
+
export default defineConfig(async () => {
|
|
242
|
+
const { dts } = await import("@guanghechen/postcss-modules-dts");
|
|
243
|
+
return {
|
|
244
|
+
buildConfig: {
|
|
245
|
+
style: {
|
|
246
|
+
modules: { ...dts },
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
// custom config
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
```
|
|
@@ -53,7 +53,7 @@ npm install -D @modern-js/module-tools typescript
|
|
|
53
53
|
|
|
54
54
|
Next, create the `modern.config.(t|j)s` file in the root of the project.
|
|
55
55
|
|
|
56
|
-
```
|
|
56
|
+
```ts
|
|
57
57
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
58
58
|
|
|
59
59
|
export default defineConfig({
|
|
@@ -84,7 +84,7 @@ If your project has a `src/index.(js|jsx)` file or both `src/index.(ts|tsx)` and
|
|
|
84
84
|
|
|
85
85
|
`@modern-js/module-tools` is implemented based on the plugin system of Modern.js. Essentially, it is a plugin. Therefore, you need to register `moduleTools` in the `plugins` field of the configuration file:
|
|
86
86
|
|
|
87
|
-
```ts modern.config.ts
|
|
87
|
+
```ts title="modern.config.ts"
|
|
88
88
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
89
89
|
|
|
90
90
|
export default defineConfig({
|