How to build dar without including source code

Is there a flag or way to build a .dar file without including the source code in it. e.g. excluding the .daml files.

If not since the dar file is just an archive is there any adverse effect to removing all .daml files before uploading the dar to a ledger.

There is no flag for this at the moment but you can manually remove them from the DAR if you want without any effect. The ledger only cares about the manifest and the .dalf files referenced from the manifest.

Keep in mind though that Daml-LF is deliberately not intended to obfuscate your code: Parties that interact with a template should know what they’re interacting with.