So in heroku I have observed that they have a option to build the development code to production code by using npm run heroku-postbuild and then executes npm start so that whenever user opens the webpage the server wont build the code one again and start the server instead it will directly start the server.
So if there was something like whenever there are changes in files the app should execute:
npm run build && npm start
And when user hits website it should only execute :
npm start (and not npm run build)
Because when you use react scripts or webpack it takes time to build the code and then start the server so it is better to have it like that i mentioned.
I think you could give the option of executing what by using watch.json
Yes, youâre right, you can currently do that using watch.json! Itâs called âinstallâ rather than âbuildâ.
To control the patterns of which files (such as, by default, package.json) when they are changed changed cause âinstallâ to be run, and which files (such as, by default, *.js) when they are changed cause âstartâ to be run, you can edit watch.json - an example is here: https://glitch.com/edit/#!/watch-json?path=README.md:1:0
Hope this helps,
Johnicholas
1 Like
so if i want to run a bash command like ânpm run buildâ
What could i enter in watch.json
Will this work :
{
âinstallâ: {
âincludeâ: [
â^package\.json$â,
â^\.env$â,
âbuild.shâ
]
},
ârestartâ: {
âexcludeâ: [
â^public/â,
â^dist/â
],
âincludeâ: [
â\.js$â,
â\.jsx$â,
â\.jsonâ
]
},
âthrottleâ: 5000
}
Yes, but you would also want your package.json to contain something like this.
"scripts": {
"install": "npm run build",
"build": "bash build.sh",
"start": "node server.js"
},
I donât know precisely how your project is set up.
Hope this helps,
Johnicholas
Heyy I didnt get you
I hope you understand what I want
See basically glitch starts server it executes npm start. But I want to execute command npm run build && npm start
When I make changes to the files and folders
But after 15minutes the website goes to sleep after that when a user hits the website i want the server to restart by npm start(npm run build should not get executed)