feat: use import maps instead of deps files (#209)
This commit updates fresh to use import maps instead of deps files in generated projects.
This commit is contained in:
@@ -31,7 +31,7 @@ Here is an example of an island component that counts down to a specific time.
|
||||
// islands/Countdown.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, useEffect, useMemo, useState } from "../deps.client.ts";
|
||||
import { h, useEffect, useMemo, useState } from "$fresh/runtime.ts";
|
||||
|
||||
const timeFmt = new Intl.RelativeTimeFormat("en-US");
|
||||
|
||||
@@ -73,7 +73,7 @@ client with the correct props:
|
||||
// routes/countdown.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h } from "../deps.client.ts";
|
||||
import { h } from "$fresh/runtime.ts";
|
||||
import { Countdown } from "../islands/Countdown.tsx";
|
||||
|
||||
export default function Page() {
|
||||
|
||||
@@ -14,8 +14,8 @@ $ fresh init my-project
|
||||
Manifest generated and written to ./my-project/fresh.gen.ts
|
||||
```
|
||||
|
||||
This will create a directory containing a bunch of files. Out of all of the
|
||||
files, only two are strictly necessary for a fresh project:
|
||||
This will create a directory containing some files and directories. There are 3
|
||||
files that are strictly necessary to run a fresh project:
|
||||
|
||||
- **`main.ts`**: This is the entrypoint for your project. It is the file that
|
||||
will you run to start your fresh application. This file doesn't actually need
|
||||
@@ -25,19 +25,17 @@ files, only two are strictly necessary for a fresh project:
|
||||
your routes and islands. This file is automatically generated based on your
|
||||
`routes/` and `islands/` folder by the `fresh` CLI when running the
|
||||
`fresh manifest` command.
|
||||
- **`import_map.json`**: This is an [import map][import-map] that is used to
|
||||
manage dependencies for the project. This allows for easy importing and
|
||||
updating of dependencies.
|
||||
|
||||
In addition to these two files, two other files are created that manage
|
||||
dependencies:
|
||||
A **`deno.json`** file is also created in the project directory. This file does
|
||||
two things:
|
||||
|
||||
- **`deps.client.ts`**: This file contains dependencies that you need on the
|
||||
client, and possibly also on the server. It should be assumed that all of the
|
||||
dependencies referenced by this file will be shipped to the client. By
|
||||
default, it just re-exports the `fresh` runtime.
|
||||
- **`deps.server.ts`**: This file contains dependencies that are only used on
|
||||
the server. These are often things like database drivers, API clients, or
|
||||
other code that should only be executed on the server. This file should never
|
||||
be referenced by modules that might be shipped to the client. By default this
|
||||
just re-exports the `fresh` server libraries.
|
||||
- It tells Deno about the location of the import map, so that it can be loaded
|
||||
automatically.
|
||||
- It registers a "start" [task][task-runner] to run the project without having
|
||||
to type a long `deno run` command.
|
||||
|
||||
Two important folders are also created that contain your routes and islands
|
||||
respectively:
|
||||
@@ -54,4 +52,6 @@ respectively:
|
||||
Finally a **`static/`** folder is created that contains static files that are
|
||||
automatically served "as is". [Learn more about static files][static-files].
|
||||
|
||||
[import-map]: https://deno.land/manual/linking_to_external_code/import_maps
|
||||
[task-runner]: https://deno.land/manual/tools/task_runner
|
||||
[static-files]: ../concepts/static-files
|
||||
|
||||
@@ -38,7 +38,7 @@ This is done with JSX.
|
||||
// routes/about.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h } from "../deps.client.ts";
|
||||
import { h } from "$fresh/runtime.ts";
|
||||
|
||||
export default function AboutPage() {
|
||||
return (
|
||||
|
||||
@@ -31,7 +31,7 @@ then adds a custom header to the response before returning it:
|
||||
// routes/about.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, Handlers } from "../deps.client.ts";
|
||||
import { h, Handlers } from "$fresh/runtime.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req, ctx) {
|
||||
@@ -58,7 +58,7 @@ response:
|
||||
```ts
|
||||
// routes/api/random-uuid.ts
|
||||
|
||||
import { Handlers } from "../deps.client.ts";
|
||||
import { Handlers } from "$fresh/runtime.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
GET(req) {
|
||||
|
||||
@@ -28,7 +28,7 @@ as arguments in it's `props` object though.
|
||||
// routes/greet/[name].tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
import { h, PageProps } from "$fresh/runtime.ts";
|
||||
|
||||
export default function AboutPage(props: PageProps) {
|
||||
const { name } = props.params;
|
||||
|
||||
@@ -24,8 +24,8 @@ renders it in a page component.
|
||||
// routes/github/[username].tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
import { Handlers } from "../../deps.server.ts";
|
||||
import { h, PageProps } from "$fresh/runtime.ts";
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
interface User {
|
||||
login: string;
|
||||
|
||||
@@ -33,8 +33,8 @@ server side:
|
||||
// routes/search.tsx
|
||||
|
||||
/** @jsx h */
|
||||
import { h, PageProps } from "../../deps.client.ts";
|
||||
import { Handlers } from "../../deps.server.ts";
|
||||
import { h, PageProps } from "$fresh/runtime.ts";
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
|
||||
const NAMES = ["Alice", "Bob", "Charlie", "Dave", "Eve", "Frank"];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user