tuts-test-library 1.0.2 β†’ 1.0.4

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.
Files changed (2) hide show
  1. package/README.md +272 -60
  2. package/package.json +15 -3
package/README.md CHANGED
@@ -1,73 +1,285 @@
1
- # React + TypeScript + Vite
1
+ # Building a Library using React 19 Library with Vite, Tsup, and PNPM
2
+ This guide details how to scaffold, configure, build, and publish a React 19 component library using TypeScript, Vite, and Tsup.
3
+ ___
2
4
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
5
+ ## STACK
6
+ - React 19
7
+ - Typescript
8
+ - Vite
9
+ - Tsup
4
10
 
5
- Currently, two official plugins are available:
6
11
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
12
+ ### 1. Initial Setup
13
+ - Initialize the project using the Vite React-TypeScript template and clean up default files.
9
14
 
10
- ## React Compiler
15
+ ```bash
16
+ # Create project
17
+ npm create vite@latest test-library -- --template react-ts
11
18
 
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
19
+ # Navigate to directory
20
+ cd test-library
13
21
 
14
- ## Expanding the ESLint configuration
22
+ # Install dependencies (ensure you are using pnpm)
23
+ pnpm install
15
24
 
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
25
+ # Remove default boilerplate
26
+ rm -rf src/* rm index.html
27
+ ```
28
+
29
+ ### 2. Install & Configure Tsup
30
+ - Install tsup as a development dependency.
31
+
32
+ ```bash
33
+ pnpm add -D tsup
34
+ ```
35
+
36
+ ##### 2.1 Create `tsconfig.tsup.json`
37
+ Create a dedicated TypeScript configuration file for the build process in the root directory.
38
+ ```json
39
+ {
40
+ "extends": "./tsconfig.json",
41
+ "compilerOptions": {
42
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
43
+ "target": "ES2022",
44
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
45
+ "module": "ESNext",
46
+ "declaration": true,
47
+ "emitDeclarationOnly": true,
48
+ "declarationDir": "dist",
49
+ "noEmit": false,
50
+ "types": ["vite/client"],
51
+
52
+ /* Bundler mode */
53
+ "jsx": "react-jsx",
54
+ "moduleResolution": "bundler",
55
+ "verbatimModuleSyntax": true,
56
+ "moduleDetection": "force",
57
+
58
+ /* Linting */
59
+ "strict": true,
60
+ "noUnusedLocals": true,
61
+ "noUnusedParameters": true,
62
+ "erasableSyntaxOnly": true,
63
+ "noFallthroughCasesInSwitch": true,
64
+ "noUncheckedSideEffectImports": true
65
+ },
66
+ "include": ["src"],
67
+ "exclude": ["node_modules", "dist"]
68
+ }
69
+ ```
70
+
71
+ ##### 2.2 Create `tsup.config.ts`
72
+ Create the configuration file for the Tsup bundler in the root directory.
73
+
74
+ ```ts
75
+ import { defineConfig } from 'tsup';
76
+
77
+ export default defineConfig({
78
+ entry: ['src/index.ts'],
79
+ format: ['esm', 'cjs'],
80
+ dts: true,
81
+ clean: true,
82
+ sourcemap: true,
83
+ external: ['react', 'react-dom'],
84
+ tsconfig: "tsconfig.tsup.json"
85
+ });
86
+ ```
87
+
88
+ ### 3. Configure Vite
89
+ Update `vite.config.ts` to handle path resolution. This ensures Vite can resolve absolute paths (like `@/`) correctly during development.
90
+
91
+ ```ts
92
+ import { defineConfig } from 'vite'
93
+ import react from '@vitejs/plugin-react'
94
+ import path from 'path';
95
+
96
+ // https://vite.dev/config/
97
+ export default defineConfig({
98
+ plugins: [react()],
99
+ resolve: {
100
+ alias: {
101
+ '@': path.resolve(__dirname, 'src')
102
+ }
103
+ }
104
+ })
105
+ ```
17
106
 
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
107
+ ### 4. Configure Package.json
108
+ Modify `package.json` to define entry points, scripts, and peer dependencies.
25
109
 
26
- // Remove tseslint.configs.recommended and replace with this
27
- tseslint.configs.recommendedTypeChecked,
28
- // Alternatively, use this for stricter rules
29
- tseslint.configs.strictTypeChecked,
30
- // Optionally, add this for stylistic rules
31
- tseslint.configs.stylisticTypeChecked,
110
+ > **Note:**
111
+ > Comments are not allowed in actual JSON files. Do not copy the comments starting with //.
32
112
 
33
- // Other configs...
34
- ],
35
- languageOptions: {
36
- parserOptions: {
37
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
- tsconfigRootDir: import.meta.dirname,
39
- },
40
- // other options...
41
- },
113
+ ```json
114
+ {
115
+ "name": "tuts-test-library", // change to your prefered library name
116
+ "private": false, // remove or change it to false
117
+ "main": "./dist/index.cjs", // add this
118
+ "module": "./dist/index.js", // add this
119
+ "types": "./dist/index.d.ts", // add this
120
+ "version": "1.0.0",
121
+ "type": "module",
122
+ "scripts": {
123
+ "dev": "tsup --watch --sourcemap", // add this
124
+ "build": "tsup", // add this
125
+ "lint": "eslint .",
126
+ "preview": "vite preview"
42
127
  },
43
- ])
44
- ```
45
-
46
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
-
48
- ```js
49
- // eslint.config.js
50
- import reactX from 'eslint-plugin-react-x'
51
- import reactDom from 'eslint-plugin-react-dom'
52
-
53
- export default defineConfig([
54
- globalIgnores(['dist']),
55
- {
56
- files: ['**/*.{ts,tsx}'],
57
- extends: [
58
- // Other configs...
59
- // Enable lint rules for React
60
- reactX.configs['recommended-typescript'],
61
- // Enable lint rules for React DOM
62
- reactDom.configs.recommended,
63
- ],
64
- languageOptions: {
65
- parserOptions: {
66
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
- tsconfigRootDir: import.meta.dirname,
68
- },
69
- // other options...
70
- },
128
+ "files": [
129
+ "dist"
130
+ ],
131
+ "dependencies": {
132
+ "react": "^19.2.0",
133
+ "react-dom": "^19.2.0"
71
134
  },
72
- ])
135
+ "peerDependencies": { // add this
136
+ "react": "^19.0.0",
137
+ "react-dom": "^19.0.0"
138
+ },
139
+ "publishConfig": { // add this
140
+ "access": "public"
141
+ },
142
+ "devDependencies": {
143
+ "@eslint/js": "^9.39.1",
144
+ "@types/node": "^24.10.1",
145
+ "@types/react": "^19.2.5",
146
+ "@types/react-dom": "^19.2.3",
147
+ "@vitejs/plugin-react": "^5.1.1",
148
+ "eslint": "^9.39.1",
149
+ "eslint-plugin-react-hooks": "^7.0.1",
150
+ "eslint-plugin-react-refresh": "^0.4.24",
151
+ "globals": "^16.5.0",
152
+ "tsup": "^8.5.1",
153
+ "typescript": "~5.9.3",
154
+ "typescript-eslint": "^8.46.4",
155
+ "vite": "^7.2.4"
156
+ }
157
+ }
158
+
159
+ ```
160
+
161
+ ### 5. Add Components
162
+ Create your library components and export them
163
+
164
+ ##### 5.1 Create `src/components/Hello.tsx`
165
+
166
+ ```tsx
167
+ function Hello() {
168
+ return (
169
+ <div>Test Library is Working Successfully!</div>
170
+ )
171
+ }
172
+
173
+ export default Hello
174
+ ```
175
+
176
+ ##### 5.2 export the component in `src/index.ts`
177
+
178
+ ```tsx
179
+ export { default as Hello } from './components/Hello'
180
+ ```
181
+
182
+ ### 6. Build and Test Locally
183
+
184
+ Run the build script to generate the `dist` folder.
185
+
186
+ ```bash
187
+ pnpm build
188
+ ```
189
+
190
+ ##### 6.1 Link Locally
191
+ To test the library in another local application:
192
+
193
+ ```bash
194
+ In your library folder run:
195
+ pnpm link
196
+ ```
197
+
198
+ To check if the library is linked:
199
+
200
+ ```bash
201
+ pnpm ls -g --depth=0
202
+ ```
203
+
204
+ ##### 6.2 Install the library in consumer application
205
+ In your consumer application folder run:
206
+
207
+ ```bash
208
+ pnpm link tuts-test-library # change to your actual library name
209
+ ```
210
+
211
+ Run your consumer application and import the component to test.
212
+
213
+ ```tsx
214
+ pnpm dev
215
+ ```
216
+
217
+ ```tsx
218
+ import { Hello } from 'tuts-test-library'; // change to your actual library name
219
+
220
+ function App() {
221
+ return <Hello />
222
+ }
223
+
224
+ export default App
225
+ ```
226
+
227
+ TA-DA! πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰
228
+ ![Display 1](./public/readme_img/display_1.png)
229
+
230
+ ***
231
+ ## PUBLISH THE LIBRARY IN [NPMJS](https://www.npmjs.com/)
232
+ ***
233
+
234
+ ### 1. Publishing to NPM
235
+
236
+ In your terminal, run:
237
+ ```bash
238
+ npm login
239
+ ```
240
+ _Follow the prompts for Username, Password, Email, and OTP._
241
+
242
+ ### 2. Once Successfully Logged in, Publish the Library
243
+ Run the publish command:
244
+ ```bash
245
+ npm publish --access public
246
+ ```
247
+
248
+ If you get an error:
249
+
250
+ > **NOTE:**
251
+ > If you receive a 403 error regarding 2FA or Granular Access Tokens:
252
+ > 1. Go to NPM Settings > Access Tokens.
253
+ > 2. Click Generate New Token.
254
+ > 3. Select Granular Access Token.
255
+ > 4. Set Permissions to Read and Write (Publish).
256
+ > 5. Select your specific package (or all packages).
257
+ > 6. Copy the generated token string.
258
+ > // **you have to create organization if you don't have one.**
259
+
260
+ - 403 error regarding 2FA or granular access tokensβ€”looks like this.
261
+ ![Display 2](./public/readme_img/display_2.png)
262
+
263
+ ### 3. Set Token
264
+ - after successful creation of token, set the token in your terminal.
265
+
266
+ ```bash
267
+ npm set //registry.npmjs.org/:_authToken=<YOUR_GENERATED_TOKEN_HERE>
268
+ ```
269
+
270
+ Retry to publish the library:
271
+ ```bash
272
+ npm publish --access public
73
273
  ```
274
+
275
+ TA-DA! πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰
276
+ ![Display 3](./public/readme_img/display_3.png)
277
+ ![Display 4](./public/readme_img/display_4.png)
278
+
279
+ ***
280
+ ## CONGRATULATIONS πŸŽ‰πŸŽ‰πŸŽ‰πŸŽ‰
281
+ You have successfully published your React 19 component library to NPMJS.
282
+
283
+ ***
284
+ ## Author
285
+ - LinkedIn - [Hatwell Jonel](https://www.linkedin.com/in/jonel-hatwell/)
package/package.json CHANGED
@@ -4,11 +4,10 @@
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
- "version": "1.0.2",
7
+ "version": "1.0.4",
8
8
  "type": "module",
9
9
  "files": [
10
- "dist",
11
- "README.md"
10
+ "dist"
12
11
  ],
13
12
  "scripts": {
14
13
  "dev": "tsup --watch --sourcemap",
@@ -20,6 +19,19 @@
20
19
  "react": "^19.2.0",
21
20
  "react-dom": "^19.2.0"
22
21
  },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/hatwell-jonel/react-arcade-games"
25
+ },
26
+ "homepage": "https://github.com/hatwell-jonel/test_library",
27
+ "keywords": [
28
+ "react19",
29
+ "typescript",
30
+ "vite",
31
+ "tsup",
32
+ "pnpm",
33
+ "tutorial"
34
+ ],
23
35
  "peerDependencies": {
24
36
  "react": "^19.0.0",
25
37
  "react-dom": "^19.0.0"