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
fix(examples): bug in design system example (#9284)
### Description
- add `preview-storybook` task to turbo.json and it's script in the
root's package.json
- improvement on clean script
- changed the tsup config of `@acme/ui` package not to make source map
files in order to match the content of `ui/dist` directory stated in
README of root
- bug fix of README file. Replaced `acme-core` and other names that
meant to point to packages/ui with `@acme/ui`
### Testing Instructions
Running `npx create-turbo@latest -e design-system` and then `pnpm dev`
should work and start storybook in dev mode. README.md file in the root
should be fine too.
---------
Co-authored-by: Dimitri Mitropoulos <[email protected]>
Co-authored-by: Anthony Shew <[email protected]>
Copy file name to clipboardexpand all lines: examples/design-system/README.md
+38-24
Original file line number
Diff line number
Diff line change
@@ -45,7 +45,6 @@ This Turborepo includes the following packages and applications:
45
45
46
46
-`apps/docs`: Component documentation site with Storybook
47
47
-`packages/ui`: Core React components
48
-
-`packages/utils`: Shared React utilities
49
48
-`packages/typescript-config`: Shared `tsconfig.json`s used throughout the Turborepo
50
49
-`packages/eslint-config`: ESLint preset
51
50
@@ -55,44 +54,49 @@ This example sets up your `.gitignore` to exclude all generated files, other fol
55
54
56
55
### Compilation
57
56
58
-
To make the core library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with `tsup`, which uses `esbuild` to greatly improve performance.
57
+
To make the ui library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with `tsup`, which uses `esbuild` to greatly improve performance.
59
58
60
59
Running `pnpm build` from the root of the Turborepo will run the `build` command defined in each package's `package.json` file. Turborepo runs each `build` in parallel and caches & hashes the output to speed up future builds.
61
60
62
-
For `acme-core`, the `build` command is the following:
61
+
For `@acme/ui`, the `build` command is equivalent to the following:
`tsup` compiles `src/index.tsx`, which exports all of the components in the design system, into both ES Modules and CommonJS formats as well as their TypeScript types. The `package.json` for `acme-core` then instructs the consumer to select the correct format:
67
+
`tsup` compiles all of the components in the design system individually, into both ES Modules and CommonJS formats as well as their TypeScript types. The `package.json` for `@acme/ui` then instructs the consumer to select the correct format:
69
68
70
-
```json:acme-core/package.json
69
+
```json:ui/package.json
71
70
{
72
-
"name": "@acme/core",
71
+
"name": "@acme/ui",
73
72
"version": "0.0.0",
74
-
"main": "./dist/index.js",
75
-
"module": "./dist/index.mjs",
76
-
"types": "./dist/index.d.ts",
77
73
"sideEffects": false,
74
+
"exports":{
75
+
"./button": {
76
+
"types": "./src/button.tsx",
77
+
"import": "./dist/button.mjs",
78
+
"require": "./dist/button.js"
79
+
}
80
+
}
78
81
}
79
82
```
80
83
81
-
Run `pnpm build` to confirm compilation is working correctly. You should see a folder `acme-core/dist` which contains the compiled output.
84
+
Run `pnpm build` to confirm compilation is working correctly. You should see a folder `ui/dist` which contains the compiled output.
82
85
83
86
```bash
84
-
acme-core
87
+
ui
85
88
└── dist
86
-
├── index.d.ts <-- Types
87
-
├── index.js <-- CommonJS version
88
-
└── index.mjs <-- ES Modules version
89
+
├── button.d.ts <-- Types
90
+
├── button.js <-- CommonJS version
91
+
├── button.mjs <-- ES Modules version
92
+
└── button.d.mts <-- ES Modules version with Types
89
93
```
90
94
91
95
## Components
92
96
93
-
Each file inside of `acme-core/src` is a component inside our design system. For example:
97
+
Each file inside of `ui/src` is a component inside our design system. For example:
94
98
95
-
```tsx:acme-core/src/Button.tsx
99
+
```tsx:ui/src/Button.tsx
96
100
import*asReactfrom'react';
97
101
98
102
exportinterfaceButtonProps {
@@ -106,12 +110,22 @@ export function Button(props: ButtonProps) {
106
110
Button.displayName='Button';
107
111
```
108
112
109
-
When adding a new file, ensure the component is also exported from the entry `index.tsx` file:
113
+
When adding a new file, ensure that its specifier is defined in `package.json` file:
0 commit comments