I like Peopleware’s solution a lot more than the accepted solution, but you don’t even need gulp for that. You can simply do this in your package.json:
{
"scripts": {
"build": "tsc <your command line options>",
"postbuild": "cp package.json dist/package.json && cd dist && npm install --only=production"
}
}
The benefit of doing it this way is that you’re not copying the entirety of your node_modules folder, because it might have a ton of dependencies only used during development.
You can do the same with static assets such as images or what not with:
"copy-statics": "cp -r static dist/static"
Update: instead of using npm install --only-production it is safer to copy both package.json and package-lock.json and then run npm ci --production. This ensures that you only install the dependency snapshot that you have in your package-lock.json. So the command would look like this:
"postbuild": "cp package*.json dist && cd dist && npm ci --production"