Skip to content

Commit 6e19285

Browse files
authored
refactor(rust): Switch to V2 + Vite (#501)
1 parent b257b6c commit 6e19285

11 files changed

+156
-54
lines changed

rust/.eslintrc.cjs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* This is intended to be a basic starting point for linting in your app.
3+
* It relies on recommended configs out of the box for simplicity, but you can
4+
* and should modify this configuration to best suit your team's needs.
5+
*/
6+
7+
/** @type {import('eslint').Linter.Config} */
8+
module.exports = {
9+
root: true,
10+
parserOptions: {
11+
ecmaVersion: "latest",
12+
sourceType: "module",
13+
ecmaFeatures: {
14+
jsx: true,
15+
},
16+
},
17+
env: {
18+
browser: true,
19+
commonjs: true,
20+
es6: true,
21+
},
22+
ignorePatterns: ["!**/.server", "!**/.client"],
23+
24+
// Base config
25+
extends: ["eslint:recommended"],
26+
27+
overrides: [
28+
// React
29+
{
30+
files: ["**/*.{js,jsx,ts,tsx}"],
31+
plugins: ["react", "jsx-a11y"],
32+
extends: [
33+
"plugin:react/recommended",
34+
"plugin:react/jsx-runtime",
35+
"plugin:react-hooks/recommended",
36+
"plugin:jsx-a11y/recommended",
37+
],
38+
settings: {
39+
react: {
40+
version: "detect",
41+
},
42+
formComponents: ["Form"],
43+
linkComponents: [
44+
{ name: "Link", linkAttribute: "to" },
45+
{ name: "NavLink", linkAttribute: "to" },
46+
],
47+
"import/resolver": {
48+
typescript: {},
49+
},
50+
},
51+
},
52+
53+
// Typescript
54+
{
55+
files: ["**/*.{ts,tsx}"],
56+
plugins: ["@typescript-eslint", "import"],
57+
parser: "@typescript-eslint/parser",
58+
settings: {
59+
"import/internal-regex": "^~/",
60+
"import/resolver": {
61+
node: {
62+
extensions: [".ts", ".tsx"],
63+
},
64+
typescript: {
65+
alwaysTryTypes: true,
66+
},
67+
},
68+
},
69+
extends: [
70+
"plugin:@typescript-eslint/recommended",
71+
"plugin:import/recommended",
72+
"plugin:import/typescript",
73+
],
74+
},
75+
76+
// Node
77+
{
78+
files: [".eslintrc.cjs"],
79+
env: {
80+
node: true,
81+
},
82+
},
83+
],
84+
};

rust/.eslintrc.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

rust/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22

33
/.cache
44
/build
5-
/public/build
65
.env

rust/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Installing Rust:
2020
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2121
```
2222

23-
Here we use `wasm-pack` to comile our Rust code down to WASM
23+
Here we use `wasm-pack` to compile our Rust code down to WASM
2424

2525
Installing [wasm-pack](https://github.com/rustwasm/wasm-pack):
2626

@@ -41,7 +41,7 @@ cd <library-name>
4141
wasm-pack build --target nodejs
4242
```
4343

44-
After succesfully bulding the library you can add this to your dependencies by running inside your remix project:
44+
After successfully building the library you can add this to your dependencies by running inside your remix project:
4545

4646
```sh
4747
npm install ./<library-name>/pkg

rust/app/root.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
import type { LinksFunction, MetaFunction } from "@remix-run/node";
21
import {
32
Links,
4-
LiveReload,
53
Meta,
64
Outlet,
75
Scripts,
86
ScrollRestoration,
97
} from "@remix-run/react";
108

11-
import globalStylesUrl from "~/styles/global.css";
9+
import globalStylesUrl from "~/styles/global.css?url";
1210

1311
export const links: LinksFunction = () => [
1412
{ rel: "stylesheet", href: globalStylesUrl },
1513
];
1614

17-
export const meta: MetaFunction = () => ({
18-
charset: "utf-8",
19-
title: "New Remix App",
20-
viewport: "width=device-width,initial-scale=1",
21-
});
22-
23-
export default function App() {
15+
export function Layout({ children }: { children: React.ReactNode }) {
2416
return (
2517
<html lang="en">
2618
<head>
19+
<meta charSet="utf-8" />
20+
<meta name="viewport" content="width=device-width, initial-scale=1" />
2721
<Meta />
2822
<Links />
2923
</head>
3024
<body>
31-
<Outlet />
25+
{children}
3226
<ScrollRestoration />
3327
<Scripts />
34-
<LiveReload />
3528
</body>
3629
</html>
3730
);
3831
}
32+
33+
export default function App() {
34+
return <Outlet />;
35+
}

rust/app/routes/_index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { ActionArgs, LinksFunction } from "@remix-run/node";
1+
import type { ActionFunctionArgs, LinksFunction } from "@remix-run/node";
22
import { json } from "@remix-run/node";
33
import { Form, useActionData } from "@remix-run/react";
44

55
import { add } from "~/rust.server";
6-
import indexStylesUrl from "~/styles/index.css";
6+
import indexStylesUrl from "~/styles/index.css?url";
77

88
export const links: LinksFunction = () => [
99
{ rel: "stylesheet", href: indexStylesUrl },
1010
];
1111

12-
export const action = async ({ request }: ActionArgs) => {
12+
export const action = async ({ request }: ActionFunctionArgs) => {
1313
const formData = await request.formData();
1414
const { left_operand, operator, right_operand } =
1515
Object.fromEntries(formData);
@@ -41,6 +41,7 @@ export default function Index() {
4141
name="left_operand"
4242
id="left_operand"
4343
placeholder="2"
44+
required
4445
/>
4546
<select className="operator" name="operator" id="operator">
4647
<option value="+">+</option>
@@ -54,6 +55,7 @@ export default function Index() {
5455
name="right_operand"
5556
id="right_operand"
5657
placeholder="2"
58+
required
5759
/>
5860
<button className="submit" type="submit">
5961
=

rust/package.json

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
{
2+
"name": "rust",
23
"private": true,
34
"sideEffects": false,
5+
"type": "module",
46
"scripts": {
5-
"build": "remix build",
7+
"build": "remix vite:build",
8+
"dev": "remix vite:dev",
69
"predev": "wasm-pack build rust-functions --target nodejs --out-name rust-functions",
7-
"dev": "remix dev",
8-
"start": "remix-serve build",
10+
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
11+
"start": "remix-serve ./build/server/index.js",
912
"typecheck": "tsc"
1013
},
1114
"dependencies": {
12-
"@remix-run/node": "^1.19.3",
13-
"@remix-run/react": "^1.19.3",
14-
"@remix-run/serve": "^1.19.3",
15-
"isbot": "^3.6.5",
15+
"@remix-run/node": "^2.9.2",
16+
"@remix-run/react": "^2.9.2",
17+
"@remix-run/serve": "^2.9.2",
18+
"isbot": "^4.1.0",
1619
"react": "^18.2.0",
1720
"react-dom": "^18.2.0",
1821
"rust-functions": "file:rust-functions/pkg"
1922
},
2023
"devDependencies": {
21-
"@remix-run/dev": "^1.19.3",
22-
"@remix-run/eslint-config": "^1.19.3",
23-
"@types/react": "^18.0.25",
24-
"@types/react-dom": "^18.0.8",
25-
"eslint": "^8.27.0",
26-
"typescript": "^4.8.4"
24+
"@remix-run/dev": "^2.9.2",
25+
"@types/react": "^18.2.20",
26+
"@types/react-dom": "^18.2.7",
27+
"@typescript-eslint/eslint-plugin": "^6.7.4",
28+
"@typescript-eslint/parser": "^6.7.4",
29+
"eslint": "^8.38.0",
30+
"eslint-import-resolver-typescript": "^3.6.1",
31+
"eslint-plugin-import": "^2.28.1",
32+
"eslint-plugin-jsx-a11y": "^6.7.1",
33+
"eslint-plugin-react": "^7.33.2",
34+
"eslint-plugin-react-hooks": "^4.6.0",
35+
"typescript": "^5.1.6",
36+
"vite": "^5.1.0",
37+
"vite-tsconfig-paths": "^4.2.1"
2738
},
2839
"engines": {
29-
"node": ">=14.0.0"
40+
"node": ">=20.0.0"
3041
}
3142
}

rust/remix.config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

rust/remix.env.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

rust/tsconfig.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
{
2-
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
2+
"include": [
3+
"**/*.ts",
4+
"**/*.tsx",
5+
"**/.server/**/*.ts",
6+
"**/.server/**/*.tsx",
7+
"**/.client/**/*.ts",
8+
"**/.client/**/*.tsx"
9+
],
310
"compilerOptions": {
4-
"lib": ["DOM", "DOM.Iterable", "ES2019"],
11+
"lib": ["DOM", "DOM.Iterable", "ES2022"],
12+
"types": ["@remix-run/node", "vite/client"],
513
"isolatedModules": true,
614
"esModuleInterop": true,
715
"jsx": "react-jsx",
8-
"moduleResolution": "node",
16+
"module": "ESNext",
17+
"moduleResolution": "Bundler",
918
"resolveJsonModule": true,
10-
"target": "ES2019",
19+
"target": "ES2022",
1120
"strict": true,
1221
"allowJs": true,
22+
"skipLibCheck": true,
1323
"forceConsistentCasingInFileNames": true,
1424
"baseUrl": ".",
1525
"paths": {
1626
"~/*": ["./app/*"]
1727
},
1828

19-
// Remix takes care of building everything in `remix build`.
29+
// Vite takes care of building everything, not tsc.
2030
"noEmit": true
2131
}
2232
}

rust/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { vitePlugin as remix } from "@remix-run/dev";
2+
import { defineConfig } from "vite";
3+
import tsconfigPaths from "vite-tsconfig-paths";
4+
5+
export default defineConfig({
6+
plugins: [
7+
remix({
8+
future: {
9+
v3_fetcherPersist: true,
10+
v3_relativeSplatPath: true,
11+
v3_throwAbortReason: true,
12+
},
13+
}),
14+
tsconfigPaths(),
15+
],
16+
});

0 commit comments

Comments
 (0)