Skip to content

Commit

Permalink
Remove barrel file from design-system-example (#7580)
Browse files Browse the repository at this point in the history
### Description

As @lorcan-codes pointed out in #7529, the `design-system` example could
quickly run into performance issues. This was because we were using a
barrel file.

I've swapped the `main` field `./packages/ui/package.json` for an
`exports` field that allows for creating individual entrypoints for the
package to remove this class of issue.

### Testing Instructions

I verified that `turbo build && cd apps/docs && pnpm preview-storybook`
runs correctly. Additionally, I made sure that `turbo dev` works and
that edits to both the `Button` component itself and the story for it
show hot-reloaded changes.

Happy to have someone else check me!


Closes TURBO-2505
  • Loading branch information
anthonyshew committed Mar 4, 2024
1 parent 42c4de5 commit 9e962f3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Button } from "@acme/ui";
import { Button } from "@acme/ui/button";

const meta: Meta<typeof Button> = {
component: Button,
Expand Down
3 changes: 2 additions & 1 deletion examples/design-system/packages/typescript-config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node",
"module": "ESNext",
"moduleResolution": "Bundler",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
Expand Down
17 changes: 9 additions & 8 deletions examples/design-system/packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "@acme/ui",
"version": "0.0.0",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
"license": "MIT",
"files": [
"dist/**"
],
"exports": {
"./button": {
"types": "./src/button.tsx",
"import": "./dist/button.mjs",
"require": "./dist/button.js"
}
},
"scripts": {
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
"dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
"build": "tsup",
"dev": "tsup --watch",
"lint": "eslint . --max-warnings 0",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
Expand Down
1 change: 0 additions & 1 deletion examples/design-system/packages/ui/src/index.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions examples/design-system/packages/ui/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "tsup";

export default defineConfig((options) => ({
entryPoints: ["src/button.tsx"],
format: ["cjs", "esm"],
dts: true,
sourcemap: true,
external: ["react"],
...options,
}));
4 changes: 3 additions & 1 deletion examples/design-system/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"outputs": ["dist/**", "storybook-static/**"],
"dependsOn": ["^build"]
},
"lint": {},
"lint": {
"dependsOn": ["^lint"]
},
"dev": {
"cache": false,
"persistent": true
Expand Down

0 comments on commit 9e962f3

Please sign in to comment.