是否应该将编译后的JavaScript文件提交给Git存储库? [英] Should compiled JavaScript files be committed to Git repo?

查看:77
本文介绍了是否应该将编译后的JavaScript文件提交给Git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是TypeScript的新功能,只是想知道社区认为最佳实践是什么.

当我进行生产编译时,我使用了webpack加载器.但是,当我运行测试时,我需要运行tsc && ava.这将在与.ts副本相同的位置生成一个.js等效文件.这些文件是否应该与.ts文件一起提交到存储库?我的第一个假设是不,因为它们应该在每次处理之前都要重新编译,例如启动服务器或执行测试已运行.但是,我只是想征询社区的意见.

解决方案

您的假设是绝对正确的-构建文物和输出不应添加到您的存储库中.造成这种情况的主要原因是,很容易在源.ts文件已更改但编译后的.js文件有所不同的情况下结束,因为它不是同时提交的.

您还为请求/合并评论添加了复杂性,因为将会有大量生成的代码不是评论的真正部分,而是在变更集中. >

最后,合并更改会有些麻烦,因为每次执行合并时都需要重新编译.js文件.

如果仅 使用源目录中的.ts文件,则可以将/**/*.js添加到.gitignore中,以防止意外添加文件.

New to TypeScript here and just wondering what the community views as best practice.

When I compile for production, I use the webpack loader. However, when I run my tests, I need to run tsc && ava. This generates a .js equivalent file in the same location as their .ts counterparts. Should these by committed to the repo alongside the .ts files? My first assumption is no because they should be re-compiled each time before a process e.g. starting your server or executing tests is run. However, I'd just like to get the community's opinion on this.

解决方案

Your assumption is absolutely correct - build artefacts and outputs shouldn't be added to your repository. The main reason for this is that it's easy to end up in a situation where the source .ts file has changed but the compiled .js file differs because it's not been committed at the same time.

You also add complexity to your pull-requests/merge reviews, as there will be a large amount of generated code that isn't really part of the review but is in the changeset.

Finally, merging changes becomes a bit of a pain, because you need to recompile the .js files for every merge you do.

If you only use .ts files in your source directory, you can add /**/*.js to your .gitignore to prevent files from being added accidentally.

这篇关于是否应该将编译后的JavaScript文件提交给Git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆