Skip to content

Commit

Permalink
refactor(remix-auth-form): Switch to V2 + Vite (#364)
Browse files Browse the repository at this point in the history
Co-authored-by: Mehdi Achour <machour@gmail.com>
  • Loading branch information
swalker326 and machour committed May 31, 2024
1 parent e837948 commit 7c087e4
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 73 deletions.
84 changes: 84 additions & 0 deletions remix-auth-form/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* This is intended to be a basic starting point for linting in your app.
* It relies on recommended configs out of the box for simplicity, but you can
* and should modify this configuration to best suit your team's needs.
*/

/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
env: {
browser: true,
commonjs: true,
es6: true,
},
ignorePatterns: ["!**/.server", "!**/.client"],

// Base config
extends: ["eslint:recommended"],

overrides: [
// React
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: ["react", "jsx-a11y"],
extends: [
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
],
settings: {
react: {
version: "detect",
},
formComponents: ["Form"],
linkComponents: [
{ name: "Link", linkAttribute: "to" },
{ name: "NavLink", linkAttribute: "to" },
],
"import/resolver": {
typescript: {},
},
},
},

// Typescript
{
files: ["**/*.{ts,tsx}"],
plugins: ["@typescript-eslint", "import"],
parser: "@typescript-eslint/parser",
settings: {
"import/internal-regex": "^~/",
"import/resolver": {
node: {
extensions: [".ts", ".tsx"],
},
typescript: {
alwaysTryTypes: true,
},
},
},
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
],
},

// Node
{
files: [".eslintrc.cjs"],
env: {
node: true,
},
},
],
};
4 changes: 0 additions & 4 deletions remix-auth-form/.eslintrc.js

This file was deleted.

1 change: 0 additions & 1 deletion remix-auth-form/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ node_modules

/.cache
/build
/public/build
.env
23 changes: 6 additions & 17 deletions remix-auth-form/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction, MetaFunction } from "@remix-run/node";
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";

export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export const meta: MetaFunction = () => {
return [
{ title: "New Remix App" },
{ name: "description", content: "Welcome to Remix!" },
];
};

export default function App() {
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
Expand All @@ -30,11 +16,14 @@ export default function App() {
<Links />
</head>
<body>
<Outlet />
{children}
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}
10 changes: 10 additions & 0 deletions remix-auth-form/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Link } from "@remix-run/react";

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix</h1>
<Link to="/login">Login</Link>
</div>
);
}
47 changes: 25 additions & 22 deletions remix-auth-form/app/routes/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@ export default function Screen() {
const { error } = useLoaderData<typeof loader>();

return (
<Form method="post">
{error ? <div>{error.message}</div> : null}
<div>
<label htmlFor="email">Email</label>
<input
type="email"
name="email"
id="email"
defaultValue="user@domain.tld"
/>
</div>
<>
<pre>/login</pre>
<Form method="post">
{error ? <div>{error.message}</div> : null}
<div>
<label htmlFor="email">Email</label>
<input
type="email"
name="email"
id="email"
defaultValue="user@domain.tld"
/>
</div>

<div>
<label htmlFor="password">Password</label>
<input
type="password"
name="password"
id="password"
defaultValue="test"
/>
</div>
<div>
<label htmlFor="password">Password</label>
<input
type="password"
name="password"
id="password"
defaultValue="test"
/>
</div>

<button>Log In</button>
</Form>
<button>Log In</button>
</Form>
</>
);
}
1 change: 1 addition & 0 deletions remix-auth-form/app/routes/private.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function Screen() {
const { email } = useLoaderData<typeof loader>();
return (
<>
<pre>/private</pre>
<h1>Hello {email}</h1>

<Form method="post">
Expand Down
37 changes: 23 additions & 14 deletions remix-auth-form/package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
{
"name": "template",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix build",
"dev": "remix dev --manual",
"start": "remix-serve ./build/index.js",
"build": "remix vite:build",
"dev": "remix vite:dev",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "remix-serve ./build/server/index.js",
"typecheck": "tsc"
},
"dependencies": {
"@remix-run/css-bundle": "^2.0.1",
"@remix-run/node": "^2.0.1",
"@remix-run/react": "^2.0.1",
"@remix-run/serve": "^2.0.1",
"isbot": "^3.6.8",
"@remix-run/node": "^2.9.2",
"@remix-run/react": "^2.9.2",
"@remix-run/serve": "^2.9.2",
"isbot": "^4.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"remix-auth": "^3.6.0",
"remix-auth-form": "^1.4.0"
"remix-auth": "^3.7.0",
"remix-auth-form": "^1.5.0"
},
"devDependencies": {
"@remix-run/dev": "^2.0.1",
"@remix-run/eslint-config": "^2.0.1",
"@remix-run/dev": "^2.9.2",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"eslint": "^8.38.0",
"typescript": "^5.1.6"
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"typescript": "^5.1.6",
"vite": "^5.1.0",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": ">=14.0.0"
"node": ">=20.0.0"
}
}
8 changes: 0 additions & 8 deletions remix-auth-form/remix.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions remix-auth-form/remix.env.d.ts

This file was deleted.

20 changes: 15 additions & 5 deletions remix-auth-form/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"include": [
"**/*.ts",
"**/*.tsx",
"**/.server/**/*.ts",
"**/.server/**/*.tsx",
"**/.client/**/*.ts",
"**/.client/**/*.tsx"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/node", "vite/client"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2019",
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
// Vite takes care of building everything, not tsc.
"noEmit": true
}
}
16 changes: 16 additions & 0 deletions remix-auth-form/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
plugins: [
remix({
future: {
v3_fetcherPersist: true,
v3_relativeSplatPath: true,
v3_throwAbortReason: true,
},
}),
tsconfigPaths(),
],
});

0 comments on commit 7c087e4

Please sign in to comment.