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: docs/tsdown-readme.md
+50-33Lines changed: 50 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
-
# TSDX React w/ Storybook User Guide
1
+
# tsdown React w/ Storybook User Guide
2
2
3
-
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
3
+
Congrats! You just saved yourself hours of work by bootstrapping this project with tsdown. Let's get you oriented with what's here and how to use it.
4
4
5
-
> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
5
+
> This tsdown setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you're looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
6
6
7
7
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
8
8
9
9
## Commands
10
10
11
-
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
11
+
tsdown scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
12
12
13
-
The recommended workflow is to run TSDX in one terminal:
13
+
The recommended workflow is to run tsdown in one terminal:
14
14
15
15
```bash
16
-
npm start # or yarn start
16
+
npm start # or pnpm start
17
17
```
18
18
19
19
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
@@ -25,7 +25,7 @@ Then run either Storybook or the example playground:
25
25
Run inside another terminal:
26
26
27
27
```bash
28
-
yarn storybook
28
+
pnpm storybook
29
29
```
30
30
31
31
This loads the stories from `./stories`.
@@ -38,23 +38,23 @@ Then run the example inside another:
38
38
39
39
```bash
40
40
cd example
41
-
npm i # or yarn to install dependencies
42
-
npm start # or yarn start
41
+
npm i # or pnpm install to install dependencies
42
+
npm start # or pnpm start
43
43
```
44
44
45
-
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
45
+
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure tsdown is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
46
46
47
-
To do a one-off build, use `npm run build` or `yarn build`.
47
+
To do a one-off build, use `npm run build` or `pnpm build`.
48
48
49
-
To run tests, use `npm test` or `yarn test`.
49
+
To run tests, use `npm test` or `pnpm test`.
50
50
51
51
## Configuration
52
52
53
53
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
54
54
55
-
### Jest
55
+
### Vitest
56
56
57
-
Jest tests are set up to run with `npm test` or `yarn test`.
57
+
Vitest tests are set up to run with `npm test` or `pnpm test`.
58
58
59
59
### Bundle analysis
60
60
@@ -89,9 +89,9 @@ tsconfig.json
89
89
90
90
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
91
91
92
-
### Rollup
92
+
### tsdown
93
93
94
-
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
94
+
tsdown uses [esbuild](https://esbuild.github.io/) as a bundler and generates multiple output formats for various module formats and build settings. See [Optimizations](#optimizations) for details.
95
95
96
96
### TypeScript
97
97
@@ -108,25 +108,42 @@ Two actions are added by default:
108
108
109
109
## Optimizations
110
110
111
-
Please see the main `tsdx`[optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
111
+
tsdown provides fast builds using esbuild and includes several optimization features:
You can configure these options in your `tsdown.config.js` file:
122
120
123
-
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
121
+
```js
122
+
exportdefault {
123
+
entry:'src/index.ts',
124
+
outDir:'dist',
125
+
format: ['esm', 'cjs'],
126
+
dts:true,
127
+
external: ['react', 'react-dom'],
128
+
clean:true,
129
+
sourcemap:true,
130
+
minify:false,
131
+
splitting:false,
132
+
treeshake:true,
133
+
};
134
+
```
124
135
125
136
## Module Formats
126
137
127
-
CJS, ESModules, and UMD module formats are supported.
138
+
ESM and CommonJS module formats are supported by default.
139
+
140
+
The appropriate paths are configured in `package.json`:
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
146
+
Please report if any issues are found.
130
147
131
148
## Deploying the Example Playground
132
149
@@ -142,7 +159,7 @@ Alternatively, if you already have a git repo connected, you can set up continuo
142
159
143
160
```bash
144
161
netlify init
145
-
# build command: yarn build && cd example && yarn && yarn build
162
+
# build command: pnpm build && cd example && pnpm install && pnpm build
146
163
# directory to deploy: example/dist
147
164
# pick yes for netlify.toml
148
165
```
@@ -163,19 +180,19 @@ We recommend using [np](https://github.com/sindresorhus/np).
163
180
164
181
## Usage with Lerna
165
182
166
-
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
183
+
When creating a new package with tsdown within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
167
184
168
185
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
169
186
170
187
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
171
188
172
189
```diff
173
-
"alias": {
190
+
"alias": {
174
191
- "react": "../node_modules/react",
175
192
- "react-dom": "../node_modules/react-dom"
176
193
+ "react": "../../../node_modules/react",
177
194
+ "react-dom": "../../../node_modules/react-dom"
178
-
},
195
+
},
179
196
```
180
197
181
-
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead.[However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
198
+
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead.
0 commit comments