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

add remix example #416

Merged
merged 2 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/create-remix-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules

.cache
.env
.vercel
.output

/build/
/public/build
/api/index.js

package-lock.json
34 changes: 34 additions & 0 deletions examples/create-remix-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Welcome to Remix!

- [Remix Docs](https://remix.run/docs)

## Deployment

After having run the `create-remix` command and selected "Vercel" as a deployment target, you only need to [import your Git repository](https://vercel.com/new) into Vercel, and it will be deployed.

If you'd like to avoid using a Git repository, you can also deploy the directory by running [Vercel CLI](https://vercel.com/cli):

```sh
npm i -g vercel
vercel
```

It is generally recommended to use a Git repository, because future commits will then automatically be deployed by Vercel, through its [Git Integration](https://vercel.com/docs/concepts/git).

## Development

To run your Remix app locally, make sure your project's local dependencies are installed:

```sh
npm install
```

Afterwards, start the Remix development server like so:

```sh
npm run dev
```

Open up [http://localhost:3000](http://localhost:3000) and you should be ready to go!

If you're used to using the `vercel dev` command provided by [Vercel CLI](https://vercel.com/cli) instead, you can also use that, but it's not needed.
7 changes: 7 additions & 0 deletions examples/create-remix-app/api/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/create-remix-app/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { RemixBrowser } from "@remix-run/react";
import { hydrate } from "react-dom";

hydrate(<RemixBrowser />, document);
26 changes: 26 additions & 0 deletions examples/create-remix-app/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server";
import { CssBaseline } from "@nextui-org/react";

export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
const styles = CssBaseline.flush();
let html = renderToString(
<RemixServer context={remixContext} url={request.url} />
).replace(
/<\/head>/,
`<style id="stitches">${styles.props.dangerouslySetInnerHTML.__html}</style></head>`
);

responseHeaders.set("Content-Type", "text/html");

return new Response("<!DOCTYPE html>" + html, {
status: responseStatusCode,
headers: responseHeaders,
});
}
48 changes: 48 additions & 0 deletions examples/create-remix-app/app/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { MetaFunction } from "@remix-run/node";
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { createTheme, NextUIProvider } from "@nextui-org/react";
import useDarkMode from "use-dark-mode";

const lightTheme = createTheme({
type: "light",
theme: {},
});

const darkTheme = createTheme({
type: "dark",
theme: {},
});

export const meta: MetaFunction = () => ({
charset: "utf-8",
title: "Remix with NextUI",
viewport: "width=device-width,initial-scale=1",
});

export default function App() {
const darkMode = useDarkMode(false);

return (
<html lang="en">
<head>
<Meta />
<Links />
</head>
<body>
<NextUIProvider theme={darkMode.value ? darkTheme : lightTheme}>
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</NextUIProvider>
</body>
</html>
);
}
37 changes: 37 additions & 0 deletions examples/create-remix-app/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
Container,
Grid,
Switch,
Text,
useTheme,
Link,
} from "@nextui-org/react";
import useDarkMode from "use-dark-mode";

export default function Index() {
const darkMode = useDarkMode(false);
const { isDark } = useTheme();
return (
<Container>
<Text h1 margin={"0 0 $4 0"} css={{ ta: "center" }}>
Welcome to <Link href="https://remix.run/">Remix</Link> with{" "}
<Link color={"secondary"} href="https://nextui.org/">
NextUI
</Link>
</Text>
<Grid.Container
justify="center"
alignContent="center"
css={{ gap: "$8", mb: "$8" }}
>
<Text>Enable {isDark ? "light" : "dark"} mode</Text>
<Switch
shadow
color="primary"
checked={isDark}
onChange={() => darkMode.toggle()}
/>
</Grid.Container>
</Container>
);
}
35 changes: 35 additions & 0 deletions examples/create-remix-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "remix-template-vercel",
"private": true,
"description": "",
"license": "",
"sideEffects": false,
"scripts": {
"build": "remix build",
"dev": "remix dev"
},
"dependencies": {
"@nextui-org/react": "^1.0.8-beta.5",
"@remix-run/node": "^1.4.0",
"@remix-run/react": "^1.4.0",
"@remix-run/vercel": "^1.4.0",
"@vercel/node": "^1.14.0",
"add": "^2.0.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"use-dark-mode": "^2.3.1",
"yarn": "^1.22.18"
},
"devDependencies": {
"@remix-run/dev": "^1.4.0",
"@remix-run/eslint-config": "^1.4.0",
"@remix-run/serve": "^1.4.0",
"@types/react": "^17.0.24",
"@types/react-dom": "^17.0.9",
"eslint": "^8.11.0",
"typescript": "^4.5.5"
},
"engines": {
"node": ">=14"
}
}
Binary file added examples/create-remix-app/public/favicon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/create-remix-app/remix.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @type {import('@remix-run/dev').AppConfig}
*/
module.exports = {
serverBuildTarget: "vercel",
// When running locally in development mode, we use the built in remix
// server. This does not understand the vercel lambda module format,
// so we default back to the standard build output.
server: process.env.NODE_ENV === "development" ? undefined : "./server.js",
ignoredRouteFiles: [".*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "api/index.js",
// publicPath: "/build/",
};
2 changes: 2 additions & 0 deletions examples/create-remix-app/remix.env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@remix-run/dev" />
/// <reference types="@remix-run/node/globals" />
4 changes: 4 additions & 0 deletions examples/create-remix-app/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createRequestHandler } from "@remix-run/vercel";
import * as build from "@remix-run/dev/server-build";

export default createRequestHandler({ build, mode: process.env.NODE_ENV });
20 changes: 20 additions & 0 deletions examples/create-remix-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
7 changes: 7 additions & 0 deletions examples/create-remix-app/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"build": {
"env": {
"ENABLE_FILE_SYSTEM_API": "1"
}
}
}