Skip to content

Commit fa18899

Browse files
docs: Quick start counter guide example and documentation update: Vite (#372)
* feat: updated quick start counter guide example and documentation * lint fix * feat: added vercel config * fix: nightly conflict * fix: updated vite template according to new import structure --------- Co-authored-by: Call Delegation <106365423+calldelegation@users.noreply.github.com>
1 parent 45fb438 commit fa18899

37 files changed

+9646
-20196
lines changed

docs/guides/docs/counter-dapp/building-a-frontend.mdx

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,46 @@ To split our project's contract from frontend code, let's initialize our fronten
3535
cd ..
3636
```
3737

38-
Now, initialize a React project with TypeScript using [`Create React App`](https://create-react-app.dev/).
38+
Now, initialize a React project with TypeScript using [`Vite`](https://vitejs.dev/).
3939

4040
<TestAction
41-
id="create-react-app"
41+
id="create-vite-project"
4242
action={{
4343
name: 'runCommand',
4444
commandFolder: 'guides-testing/fuel-project'
4545
}}
4646
/>
4747

4848
```sh
49-
npx create-react-app frontend --template typescript
49+
npm create vite@latest frontend -- --template react-ts
5050
```
5151

5252
The output should be similar to this:
5353

5454
```sh
55-
Success! Created frontend at Fuel/fuel-project/frontend
55+
Scaffolding project in Fuel/fuel-project/frontend...
56+
57+
Done. Now run:
58+
59+
cd frontend
60+
npm install
61+
npm run dev
62+
```
63+
64+
### Installing
65+
66+
Move into the `frontend` folder and install the dependencies by running:
67+
68+
<TestAction
69+
id="install-basic-deps"
70+
action={{
71+
name: 'runCommand',
72+
commandFolder: 'guides-testing/fuel-project'
73+
}}
74+
/>
75+
76+
```sh
77+
cd frontend && npm install
5678
```
5779

5880
You should now have two folders inside your `fuel-project` folder: `counter-contract` and `frontend`.
@@ -66,14 +88,6 @@ You should now have two folders inside your `fuel-project` folder: `counter-cont
6688
The `fuels` package includes all the main tools you need to interact with your Sway programs and the Fuel network.
6789
The `@fuel-wallet` packages include everything you need to interact with user wallets.
6890

69-
### Installing
70-
71-
Move into the `frontend` folder by running:
72-
73-
```sh
74-
cd frontend
75-
```
76-
7791
> `fuels` requires Node version {props.nodeVersion}.
7892
7993
Install the following packages in your `frontend` folder:
@@ -144,41 +158,41 @@ Inside the `frontend/src` folder let's add code that interacts with our contract
144158

145159
Because we'll be using `@fuels/react`, first we need to wrap our app with the `FuelProvider` component.
146160

147-
Add the imports below to the top of your `frontend/src/index.tsx` file and setup a query client:
161+
Add the imports below to the top of your `frontend/src/main.tsx` file and setup a query client:
148162

149163
<TestAction
150164
id="provider-import"
151165
action={{
152166
name: 'modifyFile',
153-
filepath: 'guides-testing/fuel-project/frontend/src/index.tsx',
154-
atLine: 6,
167+
filepath: 'guides-testing/fuel-project/frontend/src/main.tsx',
168+
atLine: 5,
155169
}}
156170
/>
157171

158172
<CodeImport
159-
file="../../examples/counter-dapp/frontend/src/index.tsx"
173+
file="../../examples/counter-dapp/frontend/src/main.tsx"
160174
lang="tsx"
161-
lineStart="6"
162-
lineEnd="13"
175+
lineStart="5"
176+
lineEnd="10"
163177
/>
164178

165-
Next, modify your `frontend/src/index.tsx` file to wrap the `App` component with the `FuelProvider` and `QueryClientProvider` components.
179+
Next, modify your `frontend/src/main.tsx` file to wrap the `App` component with the `FuelProvider` and `QueryClientProvider` components.
166180

167181
<TestAction
168182
id="fuel-wallet-provider"
169183
action={{
170184
name: 'modifyFile',
171-
filepath: 'guides-testing/fuel-project/frontend/src/index.tsx',
172-
atLine: 19,
173-
removeLines: [19],
185+
filepath: 'guides-testing/fuel-project/frontend/src/main.tsx',
186+
atLine: 11,
187+
removeLines: [11,12,13,14,15],
174188
}}
175189
/>
176190

177191
<CodeImport
178-
file="../../examples/counter-dapp/frontend/src/index.tsx"
192+
file="../../examples/counter-dapp/frontend/src/main.tsx"
179193
lang="tsx"
180-
lineStart="19"
181-
lineEnd="27"
194+
lineStart="11"
195+
lineEnd="23"
182196
/>
183197

184198
Next, change the file `fuel-project/frontend/src/App.tsx` to:
@@ -217,24 +231,20 @@ Inside the `fuel-project/frontend` directory run:
217231
id="start-app"
218232
action={{
219233
name: 'runCommand',
220-
preCommand: "pnpm pm2 start 'PORT=4000 BROWSER=none <COMMAND>' --name 'react-dapp' --cwd ./guides-testing/fuel-project/frontend"
234+
preCommand: "pnpm pm2 start 'BROWSER=none <COMMAND>' --name 'react-dapp' --cwd ./guides-testing/fuel-project/frontend"
221235
}}
222236
/>
223237

224238
```sh
225-
npm start
239+
npm run dev
226240
```
227241

228242
```sh
229-
Compiled successfully!
230-
231-
You can now view frontend in the browser.
232-
233-
Local: http://localhost:3000
234-
On Your Network: http://192.168.4.48:3000
243+
VITE v5.3.5 ready in 108 ms
235244

236-
Note that the development build is not optimized.
237-
To create a production build, use npm run build.
245+
➜ Local: http://localhost:5173/
246+
➜ Network: use --host to expose
247+
➜ press h + enter to show help
238248
```
239249

240250
Click the "Connect" button and select the wallet you have installed to connect your wallet.
@@ -281,7 +291,7 @@ action={{
281291
id="go-to-frontend"
282292
action={{
283293
name: 'goToUrl',
284-
url: "http://localhost:4000"
294+
url: "http://localhost:5173"
285295
}}
286296
/>
287297

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:react-hooks/recommended',
8+
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['react-refresh'],
12+
rules: {
13+
'react-refresh/only-export-components': [
14+
'warn',
15+
{ allowConstantExport: true },
16+
],
17+
},
18+
}
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
3-
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.js
7-
8-
# testing
9-
/coverage
10-
11-
# production
12-
/build
13-
14-
# misc
15-
.DS_Store
16-
.env.local
17-
.env.development.local
18-
.env.test.local
19-
.env.production.local
20-
1+
# Logs
2+
logs
3+
*.log
214
npm-debug.log*
225
yarn-debug.log*
236
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,30 @@
1-
# Getting Started with Create React App
1+
# React + TypeScript + Vite
22

3-
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
44

5-
## Available Scripts
5+
Currently, two official plugins are available:
66

7-
In the project directory, you can run:
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
89

9-
### `npm start`
10+
## Expanding the ESLint configuration
1011

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
1313

14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
14+
- Configure the top-level `parserOptions` property like this:
1615

17-
### `npm test`
16+
```js
17+
export default {
18+
// other rules...
19+
parserOptions: {
20+
ecmaVersion: 'latest',
21+
sourceType: 'module',
22+
project: ['./tsconfig.json', './tsconfig.node.json', './tsconfig.app.json'],
23+
tsconfigRootDir: __dirname,
24+
},
25+
}
26+
```
1827

19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21-
22-
### `npm run build`
23-
24-
Builds the app for production to the `build` folder.\
25-
It correctly bundles React in production mode and optimizes the build for the best performance.
26-
27-
The build is minified and the filenames include the hashes.\
28-
Your app is ready to be deployed!
29-
30-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31-
32-
### `npm run eject`
33-
34-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
35-
36-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37-
38-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
39-
40-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
41-
42-
## Learn More
43-
44-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45-
46-
To learn React, check out the [React documentation](https://reactjs.org/).
28+
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
29+
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
30+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list

docs/guides/examples/counter-dapp/frontend/fuels.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { createConfig } from 'fuels';
22

33
export default createConfig({
44
contracts: [
5-
'../counter-contract',
5+
'../counter-contract',
66
],
77
output: './src/sway-api',
88
});
99

1010
/**
1111
* Check the docs:
12-
* https://fuellabs.github.io/fuels-ts/tooling/cli/fuels/config-file
12+
* https://docs.fuel.network/docs/fuels-ts/fuels-cli/config-file/
1313
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)