Skip to content

Commit 822543d

Browse files
authored
Merge pull request #95 from netlify/nickytonline/fixes-to-netlify-functions-template
fix: support npm run dev (remix dev) and Netlify CLI
2 parents b36cf85 + d977e56 commit 822543d

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22

33
/.cache
44
/public/build
5+
/build
56
.env
67

78
# Local Netlify folder

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "remix build",
66
"dev": "remix dev",
7-
"start": "cross-env NODE_ENV=production netlify dev",
7+
"start": "netlify serve",
88
"typecheck": "tsc -b"
99
},
1010
"dependencies": {

remix.config.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
const baseConfig =
2+
process.env.NODE_ENV === "production"
3+
? // when running the Netify CLI or building on Netlify, we want to use
4+
{
5+
server: "./server.js",
6+
serverBuildPath: ".netlify/functions-internal/server.js",
7+
}
8+
: // otherwise support running remix dev, i.e. no custom server
9+
undefined;
10+
111
/** @type {import('@remix-run/dev').AppConfig} */
212
module.exports = {
3-
serverBuildTarget: "netlify",
4-
server:
5-
process.env.NETLIFY || process.env.NETLIFY_LOCAL
6-
? "./server.js"
7-
: undefined,
13+
...baseConfig,
814
ignoredRouteFiles: ["**/.*"],
9-
// appDirectory: "app",
10-
// assetsBuildDirectory: "public/build",
11-
// serverBuildPath: ".netlify/functions-internal/server.js",
12-
// publicPath: "/build/",
15+
// add your own custom config here if you want to.
16+
//
17+
// See https://remix.run/docs/en/v1/file-conventions/remix-config
1318
};

remix.init/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,27 @@ Ensure all packages are installed by running:
3737
npm install
3838
```
3939

40-
The Netlify CLI starts your app in development mode, rebuilding assets on file changes.
40+
Run
4141

4242
```sh
43-
npm run dev
43+
netlify dev
4444
```
4545

46-
Open up [http://localhost:3000](http://localhost:3000), and you should be ready to go!
46+
Open up [http://localhost:8888](http://localhost:8888), and you're ready to go!
4747

48-
Note: When running the Netlify CLI, file changes will rebuild assets, but you will not see the changes to the page you are on unless you do a browser refresh of the page. Due to how the Netlify CLI builds the Remix App Server, it does not support hot module reloading.
48+
### Adding Redirects and Rewrites
49+
50+
To add redirects and rewrites, add them to the `netlify.toml` file or to the [\_app_redirects](_app_redirects) file. For more information about redirects and rewrites, see the [Netlify docs](https://docs.netlify.com/routing/redirects/).
51+
52+
### Serve your site locally
53+
54+
Run
55+
56+
```sh
57+
npm run start
58+
```
59+
60+
to serve your site locally at [http://localhost:8888](http://localhost:8888).
4961

5062
## Deployment
5163

remix.init/_app_redirects

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This template uses this file instead of the typicial Netlify _redirects file.
2+
# For more information about redirects and rewrites, see https://docs.netlify.com/routing/redirects/.
3+
4+
# Do not remove the line below. This is required to serve the site when deployed.
5+
/\* /.netlify/functions/server 200
6+
7+
# Add other redirects and rewrites here and/or in your netlify.toml

remix.init/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const edgeFilesToCopy = [
1818
];
1919

2020
// Netlify Functions template file changes
21-
const filesToCopy = [["README.md"], ["netlify-toml", "netlify.toml"]];
21+
const filesToCopy = [
22+
["README.md"],
23+
["netlify-toml", "netlify.toml"],
24+
["_app_redirects"],
25+
];
2226

2327
const tsExtensionMatcher = /\.ts(x?)$/;
2428

remix.init/netlify-toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[build]
2-
command = "remix build"
2+
command = "remix build && cp _app_redirects public/_redirects"
33
publish = "public"
44

5-
[[redirects]]
6-
from = "/*"
7-
to = "/.netlify/functions/server"
8-
status = 200
5+
[dev]
6+
command = "npm run dev"
7+
targetPort = 3000
98

109
[[headers]]
1110
for = "/build/*"

0 commit comments

Comments
 (0)