Instead of uploading the precompiled dist directory, I want to compile src at server side instead.
Here are my scripts inside package.json:
\"scripts\":
Spent a while to deploy my simple typescript create-react-app to Heroku. Here what worked for me.
package.json - does not need postinstall at all
In the command line install buildpack for your application run: heroku buildpacks:add zidizei/typescript heroku buildpacks:add heroku/nodejs
You can also search for buildpacks run: heroku buildpacks:search typescript
My server looks like that (/root/server.js)
const express = require('express')
const app = express()
const PORT = process.env.PORT || 3000
app.use(express.static('build'));
app.listen(PORT, () => console.log(`Listening on port ${PORT}`))
package.json
"scripts": {
"start": "node server.js",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
Also before pushing to heroku, do run 'npm run build'.
My solution wont work if you gonna use webpack dev server, it must be custom server, in my case it was EXPRESS.