diff --git a/docs/examples/changing-the-src-dir.md b/docs/examples/changing-the-src-dir.md new file mode 100644 index 00000000..f4501d7b --- /dev/null +++ b/docs/examples/changing-the-src-dir.md @@ -0,0 +1,76 @@ +--- +description: | + Change the source directory to effectively manage your project. +--- + +When you initialize a project with `deno run -A -r https://fresh.deno.dev`, +you'll end up with a project like the following: + +``` +. +├── README.md +├── components +│   └── Button.tsx +├── deno.json +├── dev.ts +├── fresh.gen.ts +├── islands +│   └── Counter.tsx +├── main.ts +├── routes +│   ├── [name].tsx +│   ├── api +│   │   └── joke.ts +│   └── index.tsx +└── static + ├── favicon.ico + └── logo.svg +``` + +## Using a `src` directory + +If you'd like your code to live in an `src` directory (or any other directory of +your choosing), then you'll need to do the following things: + +1. Move all your files, except `deno.json` and `README.md`, to the `src` + directory. +2. Modify the `start` task in `deno.json` to point to the new directory. + +Here's what the diff of `deno.json` looks like: + +```diff + { + "lock": false, + "tasks": { +- "start": "deno run -A --watch=static/,routes/ dev.ts" ++ "start": "deno run -A --watch=src/static/,src/routes/ src/dev.ts" + }, + "imports": { + "$fresh/": "file:///Users/reed/code/fresh/", +``` + +The resulting file structure looks like this: + +``` +. +├── README.md +├── deno.json +└── src + ├── components + │   └── Button.tsx + ├── dev.ts + ├── fresh.gen.ts + ├── islands + │   └── Counter.tsx + ├── main.ts + ├── routes + │   ├── [name].tsx + │   ├── api + │   │   └── joke.ts + │   └── index.tsx + └── static + ├── favicon.ico + └── logo.svg +``` + +Success! Your code now lives elsewhere. diff --git a/docs/examples/index.md b/docs/examples/index.md index 655f6ec7..852b4920 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -11,3 +11,4 @@ like to see here, please open - [Modifying the ``](./examples/modifying-the-head) - [Setting the language](./examples/setting-the-language) - [Writing tests](./examples/writing-tests) +- [Changing the source directory](./changing-the-src-dir.md) diff --git a/docs/toc.json b/docs/toc.json index 2ee8116d..5238120a 100644 --- a/docs/toc.json +++ b/docs/toc.json @@ -43,7 +43,8 @@ "pages": [ ["modifying-the-head", "Modifying the "], ["setting-the-language", "Setting the language"], - ["writing-tests", "Writing tests"] + ["writing-tests", "Writing tests"], + ["changing-the-src-dir", "Changing the source directory"] ] } }