Commit ed0e1750 authored by Resi Respati's avatar Resi Respati Committed by Luis Fernando Alvarez D

[custom-server-typescript] fixed custom server build issues (#7385)

parent 091a81e6
......@@ -4,5 +4,5 @@ node_modules/
# next.js build output
.next
# typescript build output
# production server output
dist
......@@ -40,5 +40,6 @@ now
## The idea behind the example
The example shows how you can use [TypeScript](https://typescriptlang.com) on both the server and the client while using [Nodemon](https://nodemon.io/) to live reload the server code without affecting the Next.js universal code.
Server entry point is `server/index.ts` in development and `production-server/index.js` in production.
Server entry point is `server/index.ts` in development and `dist/index.js` in production.
The second directory should be added to `.gitignore`.
{
"watch": ["server"],
"ext": "ts",
"watch": ["server", "static"],
"exec": "ts-node --project tsconfig.server.json server/index.ts"
}
{
"name": "custom-server-typescript",
"version": "1.0.0",
"scripts": {
"dev": "nodemon",
"build": "next build && tsc && tsc --project tsconfig.server.json",
"start": "cross-env NODE_ENV=production node .next/server"
"build": "next build && tsc --project tsconfig.server.json",
"start": "cross-env NODE_ENV=production node dist/index.js"
},
"dependencies": {
"next": "latest",
"next": "^8.1.0",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"devDependencies": {
"@types/next": "^8.0.1",
"@types/react": "^16.8.8",
"@types/next": "^8.0.5",
"@types/react": "^16.8.17",
"@types/react-dom": "16.8.4",
"@zeit/next-typescript": "^1.1.1",
"cross-env": "^5.2.0",
"nodemon": "^1.18.10",
"ts-node": "^8.0.3",
"typescript": "^3.3.3333"
"nodemon": "^1.19.0",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
}
}
import { createServer } from 'http'
import { parse } from 'url'
import * as next from 'next'
import next from 'next'
const port = parseInt(process.env.PORT || '3000', 10)
const dev = process.env.NODE_ENV !== 'production'
......@@ -22,4 +22,7 @@ app.prepare()
}
})
.listen(port)
// tslint:disable-next-line:no-console
console.log(`> Server listening at http://localhost:${port} as ${dev ? 'development' : process.env.NODE_ENV}`);
})
{
"compileOnSave": false,
"compilerOptions": {
"noEmit": true,
"strict": true,
"target": "esnext",
"module": "esnext",
"jsx": "preserve",
"allowJs": true,
"lib": ["dom", "es2017"],
"baseUrl": ".",
"moduleResolution": "node",
"strict": true,
"allowJs": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"isolatedModules": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"skipLibCheck": true,
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"dom",
"es2015",
"es2016"
],
"outDir": ".next"
"sourceMap": true
},
"exclude": [".next", "server/**/*.*"]
"exclude": ["dist", ".next", "out", "next.config.js"]
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"module": "commonjs",
"outDir": "dist",
"target": "es2017",
"lib": ["es2017"]
"isolatedModules": false,
"noEmit": false
},
"include": ["server/**/*.ts"],
"exclude": [".next"]
"include": ["server/**/*.ts"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment