如何npm发布特定的文件夹但作为包根目录 [英] How to npm publish specific folder but as package root
问题描述
我有一个项目,其中包括一个gulp任务,用于构建和打包源并将其发布在名为dist
的目录中.我的目标是将其发布为npm软件包,但仅将其发布到dist文件夹. npm文档说,我可以使用files
标记指定要导出的文件.有用.但是,文档还说:
I have a project that include a gulp task for building and packaging the sources and release in a directory called dist
. My goal is publish it as a npm package, but only my dist folder. The npm documentation says that I can use the files
tag to specify files to export. It works. But, documentation also says that:
如果在数组中命名文件夹,则该文件夹还将包含文件 在该文件夹中
If you name a folder in the array, then it will also include the files inside that folder
结果是一个npm包,其中的node_modules如下:
The result, is a npm package, which node_modules looks like:
但是我想在软件包的根目录(没有该dist
文件夹)查看我的所有文件.我的index.js
文件位于dist
文件夹中,但应位于根目录下.我尝试将标签files
设置为/dist/**/*
,但是没有用.
But I'd like to see all my files at the package's root (without that dist
folder). My index.js
file is inside the dist
folder, but should be at root. I've tried to set tag files
as /dist/**/*
but it didn't work.
我该如何实现?
推荐答案
我也有同样的愿望,但我认为仅使用npm工具是无法实现这一目标的.可以使用另一个脚本/工具来安排您的包裹.
I have the same desire but I think there is no way of accomplishing this with only using npm tooling. Another script/tool could be used to arrange your package.
当前,我将package.json
复制到dist
文件夹中,然后在dist
文件夹中运行npm pack
.我认为这基本上可以为我们的包裹提供所需的安排.
Currently I am copying my package.json
into the dist
folder and then running npm pack
inside the dist
folder. I think this essentially provides the desired arrangement of our package.
以下是有关此npm设计的一些相关读物:为什么Node中没有Directories.lib .
Here is some relevant reading on this npm design: Why no Directories.lib in Node.
有趣的是,jspm确实遵守package.json
中的directories.lib
选项,并且在解析npm软件包时会重新排列文件.这一切对我来说都是因为我想建立一个可以被jspm或npm/webpack使用的公共库.
It's also interesting to note that jspm DOES respect the directories.lib
option in package.json
and rearranges the files when resolving the npm package. This all has come about for me because I am wanting to build a common library which can be consumed by jspm or npm/webpack.
这篇关于如何npm发布特定的文件夹但作为包根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!