Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite migration support #188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SESSION_SECRET="super-duper-s3cret"
CYPRESS_ENV=true
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ yarn.lock

node_modules

/public/build
/server/index.mjs
/server/index.mjs.map
/server/metafile.*
/server/version.txt
/build
preferences.arc
sam.json
sam.yaml
Expand Down
7 changes: 2 additions & 5 deletions app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ runtime nodejs18.x
@http
/*
method any
src server

@plugins
plugin-remix
src plugin-remix.js
src build/server

@static
folder build/client

@tables
user
Expand Down
6 changes: 2 additions & 4 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction, LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import {
Expand All @@ -11,11 +10,10 @@ import {
} from "@remix-run/react";

import { getUser } from "~/session.server";
import stylesheet from "~/tailwind.css";
import stylesheet from "~/tailwind.css?url";

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

export const loader = async ({ request }: LoaderFunctionArgs) => {
Expand All @@ -28,7 +26,7 @@ export default function App() {
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" href="/_static/favicon.ico" />
<link rel="icon" href="/favicon.ico" />
<Meta />
<Links />
</head>
Expand Down
2 changes: 2 additions & 0 deletions app/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, test } from "vitest";

import { validateEmail } from "./utils";

test("validateEmail returns false for non-emails", () => {
Expand Down
9 changes: 9 additions & 0 deletions handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createRequestHandler } from "@remix-run/architect";
// @ts-expect-error - Remix doesn't have types for this file
// eslint-disable-next-line import/no-unresolved
import * as build from "virtual:remix/server-build";

export const handler = createRequestHandler({
build: build,
mode: process.env.NODE_ENV,
});
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix build",
"dev": "remix dev --manual -c \"arc sandbox -e testing\"",
"build": "remix vite:build",
"dev": "concurrently \"arc sandbox -e testing\" \"remix vite:dev\"",
"format": "prettier --write .",
"format:repo": "npm run format && npm run lint -- --fix",
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
Expand All @@ -19,8 +19,7 @@
"prettier": {},
"eslintIgnore": [
"/node_modules",
"/server/index.js",
"/public/build"
"/build"
],
"dependencies": {
"@architect/architect": "^10.16.3",
Expand Down Expand Up @@ -52,6 +51,7 @@
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-v8": "^1.4.0",
"autoprefixer": "^10.4.19",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"cypress": "^13.7.1",
"esbuild": "^0.20.2",
Expand All @@ -74,10 +74,11 @@
"postcss": "^8.4.38",
"prettier": "3.2.5",
"prettier-plugin-tailwindcss": "^0.5.13",
"remix-development-tools": "^4.2.2",
"start-server-and-test": "^2.0.3",
"tailwindcss": "^3.4.2",
"typescript": "^5.4.3",
"vite": "^5.2.6",
"vite": "^5.4.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.cjs → postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
Expand Down
24 changes: 0 additions & 24 deletions remix.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions remix.env.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions server.ts

This file was deleted.

8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"exclude": ["./cypress", "./cypress.config.ts"],
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"types": ["vitest/globals"],
"types": ["@remix-run/node", "vite/client"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "ES2020",
"moduleResolution": "node",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2020",
"strict": true,
Expand Down
60 changes: 60 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { vitePlugin as remix } from "@remix-run/dev";
import { installGlobals } from "@remix-run/node";
import { remixDevTools } from "remix-development-tools";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

installGlobals();

export default defineConfig(({ mode }) => {
const isProduction = mode === "production";
const isCypress = process.env.CYPRESS_ENV === "true";

return {
base: isProduction || isCypress ? "/_static/" : "/",
server: {
port: 4000,
open: true,
},
build: {
outDir: "build",
rollupOptions: {
output: {
entryFileNames: "[name]-[hash].js",
chunkFileNames: "[name]-[hash].js",
assetFileNames: "assets/[name]-[hash].[ext]",
},
},
},
plugins: [
remixDevTools(),
remix({
ignoredRouteFiles: ["**/*.css"],
buildDirectory: "build",
serverBuildFile: "index.mjs",
basename: "/",
}),
tsconfigPaths(),
{
name: "architect-handler",
// eslint-disable-next-line @typescript-eslint/no-unused-vars
apply(_config, env): boolean {
return env.command === "build" && env?.isSsrBuild === true;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
config: async (_config, _env) => {
return {
build: {
ssr: "handler.ts",
},
};
},
},
],
test: {
globals: true,
environment: "happy-dom",
setupFiles: ["./test/setup-test-env.ts"],
},
};
});
15 changes: 0 additions & 15 deletions vitest.config.ts

This file was deleted.