问题描述
如何在.npmignore
中列出包文件(这些将被发布)调试记录?
我正在为 .gitignore
寻找类似于 git ls-files
的东西.
I'm looking for something like equivalent of git ls-files
for .gitignore
.
到目前为止我发现的唯一方法是打包包,然后列出我觉得有点笨拙的存档:
The only way I have found so far is to pack the package and then list the archive which I find a bit clumsy:
npm pack
tar -tzf <package-id>.tgz
推荐答案
正如 Mike 'Pomax' Kamermans 在 comment 可以利用 .npmignore
和 .gitignore
使用相同语法的事实:
As Mike 'Pomax' Kamermans mentioned in comment the fact that .npmignore
and .gitignore
use the same syntax can be leveraged:
git ls-files -co --exclude-per-directory=.npmignore
上面的命令根据 .npmignore
文件准确列出了未被 npm 忽略的文件.(除此之外,npm 会自动忽略一些其他条目,例如 node_modules
.)
The command above lists exactly files that are not npm-ignored according to .npmignore
file. (On top of that npm automatically ignores some other entries like node_modules
.)
Git ls-files
命令一般会列出工作目录和索引中文件的组合.
Git ls-files
command generally lists combinations of files in working directory and index.
-c
选项表示显示缓存文件-o
显示其他",即未跟踪的文件--exclude-per-directory=.npmignore
使用.npmignore
作为忽略条目的文件名
-c
option says show cached files-o
show 'other', i.e. untracked files--exclude-per-directory=.npmignore
use.npmignore
as name of files of ignore entries
由于上述方法有一堆例外 -无论 .npmignore
的内容如何,都永远不会或总是包含的文件 - 我觉得它不可靠.以下命令重量级但可靠:
Since the approach above has bunch of exceptions - files that will never or always included regardless of content of the .npmignore
- I find it unreliable. Following command is heavyweight but reliable:
file_name=$(npm pack) && tar -ztf $file_name && rm $file_name
它打包项目,列出包文件,最后删除创建的包.
It packages the project, lists package files and at the end removes created package.
这篇关于如何调试 .npmignore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!