英文:
Is there a best practice for the files field in the package.json?
问题
在 package.json 文件中,我设置了 "files": ["./src", "./lib"]
。
这个在 package.json 中的条目的目的是:
可选的 files 字段是一个文件模式的数组,描述了在将您的包安装为依赖项时要包含的条目。
我的代码目前是从位于 ./src
的 TypeScript 代码编译到位于 ./lib
的 JavaScript 代码。实际上,源代码是公开可用的在 Github 上。
将源文件夹添加到包中是否多余?这会增加包中数据的大小。
另一方面,这可能有助于其他人发现错误。
在这种情况下,最佳做法是什么?
英文:
In the package.json file I set "files": ["./src", "/.lib"]
This entry in the package.json is supposed to do this:
> The optional files field is an array of file patterns that describes the entries to be included when your package is installed as a dependency.
My code is currently compiled from Typescript code at ./src
to Javascript code at ./lib
. The source code is actually available publicly on Github.
Is it redundant to add the source folder to the package? This will increase the size of data from the package as well.
On the other hand, this may help others to spot bugs.
What would be the best practice for this case?
答案1
得分: 1
在我看来,最好包括源代码。原因如下:
- 您的编译设置(如目标)有时可能不是用户想要的(比如,如果他们需要支持旧浏览器或旧版本的Node),因此他们希望出于某种原因从源代码进行编译。
- 在调试时通常非常有帮助。编辑编译后的源代码会很混乱,但如果他们在项目中原地进行调试,他们可以切换到源代码并在
node_modules
中进行编辑。这在尝试理解错误或库的工作原理时非常有用。
值得注意的是,当用户这样做时,通常会假定他们在支持方面是独自一人。但这个逃生通道可以很有用。
英文:
In my opinion, it's better to include the source. The reasons are as follows:
- Your compilation settings (like the target) may not be what the user wants sometimes (let's say if they needed support for an old browser or older version of Node) and so they want to compile it from source themselves for whatever reason.
- It's often very helpful during debugging. Editing the compiled source is noisy but if they are debugging it in situ in their project, they can switch to the source and edit that in
node_modules
. This can be useful when trying to understand bugs or how the library works.
Worth noting when a user does this it's usually assumed they are on their own in terms of support. But the escape hatch can be useful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论