Skip to content

Commit 5714ec1

Browse files
authored
refactor(nprogress): Upgrade to latest remix version with vite (#482)
1 parent 98ca688 commit 5714ec1

12 files changed

+168
-69
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16
1+
lts/*

nprogress/.eslintrc.cjs

+84
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+
};

nprogress/.eslintrc.js

-4
This file was deleted.

nprogress/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ node_modules
22

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

nprogress/app/root.tsx

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
import type { LinksFunction, MetaFunction } from "@remix-run/node";
22
import {
33
Links,
4-
LiveReload,
54
Meta,
65
Outlet,
76
Scripts,
87
ScrollRestoration,
98
useNavigation,
109
} from "@remix-run/react";
1110
import NProgress from "nprogress";
12-
import nProgressStyles from "nprogress/nprogress.css";
11+
import nProgressStyles from "nprogress/nprogress.css?url";
1312
import { useEffect } from "react";
1413

1514
export const links: LinksFunction = () => [
1615
// if you already have one only add this stylesheet to your list of links
1716
{ rel: "stylesheet", href: nProgressStyles },
1817
];
1918

20-
export const meta: MetaFunction = () => ({
21-
charset: "utf-8",
22-
title: "New Remix App",
23-
viewport: "width=device-width,initial-scale=1",
24-
});
25-
26-
export default function App() {
27-
const transition = useNavigation();
28-
useEffect(() => {
29-
// when the state is idle then we can to complete the progress bar
30-
if (transition.state === "idle") NProgress.done();
31-
// and when it's something else it means it's either submitting a form or
32-
// waiting for the loaders of the next location so we start it
33-
else NProgress.start();
34-
}, [transition.state]);
19+
export const meta: MetaFunction = () => ([
20+
{ title: "New Remix App" },
21+
]);
3522

23+
export function Layout({ children }: { children: React.ReactNode }) {
3624
return (
3725
<html lang="en">
3826
<head>
27+
<meta charSet="utf-8" />
28+
<meta name="viewport" content="width=device-width, initial-scale=1" />
3929
<Meta />
4030
<Links />
4131
</head>
4232
<body>
43-
<Outlet />
33+
{children}
4434
<ScrollRestoration />
4535
<Scripts />
46-
<LiveReload />
4736
</body>
4837
</html>
4938
);
5039
}
40+
41+
export default function App() {
42+
const navigation = useNavigation();
43+
useEffect(() => {
44+
// when the state is idle then we can to complete the progress bar
45+
if (navigation.state === "idle") NProgress.done();
46+
// and when it's something else it means it's either submitting a form or
47+
// waiting for the loaders of the next location so we start it
48+
else NProgress.start();
49+
}, [navigation.state]);
50+
51+
return <Outlet />;
52+
}

nprogress/app/routes/_index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import { Link } from "@remix-run/react";
22

33
export default function Index() {
44
return <Link to="/slow-page">Slow Page</Link>;
5-
}
5+
}

nprogress/app/routes/slow-page.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { json } from "@remix-run/node";
2-
import { Link } from "@remix-run/react";
3-
4-
export const loader = async () => {
5-
await new Promise((resolve) => setTimeout(resolve, 1000));
6-
return json({});
7-
};
8-
9-
export default function Screen() {
10-
return <Link to="/">Home</Link>;
11-
}
1+
import { json } from "@remix-run/node";
2+
import { Link } from "@remix-run/react";
3+
4+
export const loader = async () => {
5+
await new Promise((resolve) => setTimeout(resolve, 1000));
6+
return json({});
7+
};
8+
9+
export default function Screen() {
10+
return <Link to="/">Home</Link>;
11+
}

nprogress/package.json

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
{
2+
"name": "nprogress2",
23
"private": true,
34
"sideEffects": false,
5+
"type": "module",
46
"scripts": {
5-
"build": "remix build",
6-
"dev": "remix dev",
7-
"start": "remix-serve build",
7+
"build": "remix vite:build",
8+
"dev": "remix vite:dev",
9+
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
10+
"start": "remix-serve ./build/server/index.js",
811
"typecheck": "tsc"
912
},
1013
"dependencies": {
11-
"@remix-run/node": "^1.19.3",
12-
"@remix-run/react": "^1.19.3",
13-
"@remix-run/serve": "^1.19.3",
14+
"@remix-run/node": "^2.9.2",
15+
"@remix-run/react": "^2.9.2",
16+
"@remix-run/serve": "^2.9.2",
17+
"isbot": "^4.1.0",
1418
"nprogress": "^0.2.0",
15-
"isbot": "^3.6.5",
1619
"react": "^18.2.0",
1720
"react-dom": "^18.2.0"
1821
},
1922
"devDependencies": {
20-
"@remix-run/dev": "^1.19.3",
21-
"@remix-run/eslint-config": "^1.19.3",
23+
"@remix-run/dev": "^2.9.2",
2224
"@types/nprogress": "^0.2.0",
23-
"@types/react": "^18.0.34",
24-
"@types/react-dom": "^18.0.11",
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",
2529
"eslint": "^8.38.0",
26-
"typescript": "^5.0.4"
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": ">=18.0.0"
3041
}
31-
}
42+
}

nprogress/remix.config.js

-11
This file was deleted.

nprogress/remix.env.d.ts

-2
This file was deleted.

nprogress/tsconfig.json

+15-5
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
}

nprogress/vite.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { vitePlugin as remix } from "@remix-run/dev";
2+
import { installGlobals } from "@remix-run/node";
3+
import { defineConfig } from "vite";
4+
import tsconfigPaths from "vite-tsconfig-paths";
5+
6+
installGlobals();
7+
8+
export default defineConfig({
9+
plugins: [remix(), tsconfigPaths()],
10+
});

0 commit comments

Comments
 (0)