Skip to content

Commit e0e2d90

Browse files
committed
Add rescript-template-vite
1 parent 921f4c7 commit e0e2d90

File tree

21 files changed

+3758
-0
lines changed

21 files changed

+3758
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
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?
25+
26+
# ReScript
27+
/lib/
28+
.bsb.lock
29+
.merlin
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ReScript / Vite Starter Template
2+
3+
This is a Vite-based template with following setup:
4+
5+
- [ReScript](https://rescript-lang.org) 10.1 with JSX 4 automatic mode and the new [`@rescript/core`](https://github.com/rescript-association/rescript-core) standard library
6+
- ES6 modules (ReScript code compiled to `.bs.mjs` files)
7+
- Vite 4 with React Plugin (Fast Refresh)
8+
- Tailwind 3
9+
10+
## Development
11+
12+
Run ReScript in dev mode:
13+
14+
```sh
15+
npm run res:dev
16+
```
17+
18+
In another tab, run the Vite dev server:
19+
20+
```sh
21+
npm run dev
22+
```
23+
24+
## Tips
25+
26+
### Fast Refresh & ReScript
27+
28+
Make sure to create interface files (`.resi`) for each `*.res` file.
29+
30+
Fast Refresh requires you to **only export React components**, and it's easy to unintenionally export other values that will disable Fast Refresh (you will see a message in the browser console whenever this happens).
31+
32+
### Why are the generated `.bs.mjs` files tracked in git?
33+
34+
In ReScript, it's a good habit to keep track of the actual JS output the compiler emits. It allows quick sanity checking if we made any changes that actually have an impact on the resulting JS code (especially when doing major compiler upgrades, it's a good way to verify if production code will behave the same way as before the upgrade).
35+
36+
This will also make it easier for your Non-ReScript coworkers to read and understand the changes in Github PRs, and call you out when you are writing inefficient code.
37+
38+
If you want to opt-out, feel free to remove all compiled `.mjs` files within the `src` directory and add `src/**/*.mjs` in your `.gitignore`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "rescript-template-vite",
3+
"sources": [
4+
{
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": [
10+
{
11+
"module": "es6",
12+
"in-source": true
13+
}
14+
],
15+
"suffix": ".bs.mjs",
16+
"bs-dependencies": ["@rescript/core", "@rescript/react"],
17+
"bsc-flags": ["-open RescriptCore"],
18+
"jsx": {
19+
"version": 4,
20+
"mode": "automatic"
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>ReScript + Vite + React</title>
9+
</head>
10+
11+
<body>
12+
<div id="root"></div>
13+
<script type="module" src="/src/Main.bs.mjs"></script>
14+
</body>
15+
16+
</html>

0 commit comments

Comments
 (0)