-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templates/deno): use npm-managed dependencies
- Loading branch information
Showing
24 changed files
with
98 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"// This import map is used solely for the denoland.vscode-deno extension.": "", | ||
"// Remix does not support import maps.": "", | ||
"// Dependency management is done through `npm` and `node_modules/` instead.": "", | ||
"// Deno-only dependencies may be imported via URL imports (without using import maps).": "", | ||
|
||
"imports": { | ||
"react": "https://esm.sh/react@18.0.0", | ||
"react-dom": "https://esm.sh/react-dom@18.0.0", | ||
"react-dom/server": "https://esm.sh/react-dom@18.0.0/server", | ||
"@remix-run/dev/server-build": "https://esm.sh/@remix-run/dev@1.4.3/server-build", | ||
"@remix-run/deno": "https://esm.sh/@remix-run/deno@1.4.3", | ||
"@remix-run/react": "https://esm.sh/@remix-run/react@1.4.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true | ||
} | ||
"deno.lint": true, | ||
"deno.importMap": "./.vscode/resolve_npm_imports.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,74 @@ | ||
# Remix Deno Template | ||
# Remix + Deno | ||
|
||
⚠️ EXPERIMENTAL ⚠️ | ||
Welcome to the Deno template for Remix! | ||
|
||
For more, check out the [Remix docs](https://remix.run/docs). | ||
|
||
## Install | ||
|
||
```sh | ||
npx create-remix@latest --template <path/to/this/template> | ||
npx create-remix@latest --template deno | ||
``` | ||
|
||
## Scripts | ||
## Managing dependencies | ||
|
||
```sh | ||
npm run build | ||
``` | ||
### Deno modules | ||
|
||
```sh | ||
npm run start | ||
``` | ||
Import Deno modules via URL imports: | ||
|
||
```sh | ||
npm run dev | ||
```ts | ||
import { copy } from "https://deno.land/std@0.138.0/streams/conversion.ts"; | ||
``` | ||
|
||
## 🚧 Under construction 🚧 | ||
### Don't use Deno-friendly CDNs, use `npm` | ||
|
||
This section details temporary scaffolding for the Remix Deno template. | ||
All of this scaffolding is planned for removal at a later date. | ||
For other dependencies, simply use `npm` to install them. | ||
|
||
### `package.json` | ||
```sh | ||
npm install react react-dom | ||
``` | ||
|
||
A `package.json` is included for now so that `remix` CLI (from `@remix-run/dev`) can run the Remix compiler. | ||
```tsx | ||
import { useEffect } from "react"; | ||
``` | ||
|
||
In the future, we could provide a stand-alone executable for the Remix compiler OR `npx remix`, and we would remove the `package.json` file from this Deno template. | ||
Do not use Deno-friendly CDNs like https://esm.sh as those CDNs | ||
do not have good support for peer dependencies nor for specifying | ||
dev/prod environments via `NODE_ENV`. | ||
|
||
### Local `remix-deno` package | ||
### Don't use import maps | ||
|
||
For now, we are inlining Remix's `@remix-run/deno` package into `remix-deno` to enable faster experimentation and development. | ||
Remix does not support [import maps](https://deno.land/manual/linking_to_external_code/import_maps) for Deno. | ||
|
||
In the future, this template would not include the `remix-deno` directory at all. | ||
Instead, users could import from `@remix-run/deno` (exact URL TBD). | ||
## Development | ||
|
||
## 🐞 Known issues 🐞 | ||
From your terminal: | ||
|
||
### `dev` does not live reload | ||
```sh | ||
npm run dev | ||
``` | ||
|
||
Deno server is not currently configured to live reload when `--watch` detects changes, requiring a manual refresh in the browser for non-server changes (e.g. changing JSX content). | ||
This starts your app in development mode, rebuilding assets on file changes. | ||
|
||
To enable live reload, `@remix-run/react` must be built with `NODE_ENV=development`. | ||
To do so with `esm.sh`, `?dev` must be added to all imports that depend on React. | ||
However, bundling the React development build for `esm.sh` (`https://esm.sh/react@17.0.2?dev`) runs into an [esbuild bug](https://github.com/evanw/esbuild/issues/2099). | ||
## Production | ||
|
||
Need a better way to switch from development to production mode than adding/removing `?dev` for all React-dependent imports. | ||
Also, need esbuild bug to be resolved. | ||
First, build your app for production: | ||
|
||
### Pinned React imports | ||
```sh | ||
npm run build | ||
``` | ||
|
||
For all React-related imports (including `@remix-run/*` imports), we append `?pin=v68` to the URL. | ||
This is the only reliable way we were able to guarantee that only one copy of React would be present in the browser. | ||
Then run the app in production mode: | ||
|
||
No plans on how to address this yet. | ||
```sh | ||
npm start | ||
``` | ||
|
||
### @remix-run/dev/server-build | ||
## Deployment | ||
|
||
The `@remix-run/dev/server-build` import within `server.ts` (`import * as build from '@remix-run/dev/server-build'`) is a special import for the Remix compiler that points to the built server entry point (typically within `./build`). | ||
Building the Deno app (`npm run build`) results in two outputs: | ||
|
||
The `vscode_deno` plugin complains about this import with a red squiggly underline as Deno cannot resolve this special import. | ||
- `build/` (server bundle) | ||
- `public/build/` (browser bundle) | ||
|
||
No plans on how to address this yet. | ||
You can deploy these bundles to a host of your choice, just make sure it runs Deno! |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React from "./deps/react.ts"; | ||
import ReactDOM from "./deps/react-dom.ts"; | ||
import { RemixBrowser } from "./deps/@remix-run/react.ts"; | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import { RemixBrowser } from "@remix-run/react"; | ||
|
||
ReactDOM.hydrate(<RemixBrowser />, document); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React from "../deps/react.ts"; | ||
import React from "react"; | ||
|
||
export default function Index() { | ||
return ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
templates/deno/remix-deno/deps/@remix-run/server-runtime.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.