我们所有的服务器项目都包含一个git子模块文件夹(让我们说modules
),其中包含我们的自定义模块/组件。
此类模块依赖项在本地安装(请参阅serverApp/package.json
),以便我们不必将整个子模块文件夹包含在最终的rpm中。我遇到问题的是限制node_modules
中包含的文件数量。
子模块结构如下所示:
modules
|--loader
|--dist => compiled js files here that are created when installing the module
|--ts => contains typescript files that shouldn't be included in node_modules
|--package.json
|--tsconfig.json
|--more modules
|--.gitignore
在.npmignore
内添加modules/loader
文件似乎无法帮助复制整个文件夹。
模块/装载器/ tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true
}
}
模块/装载器/的package.json
{
"name": "loader",
"version": "1.2.0",
"private": true,
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"preinstall": "npm run build",
"build": "../../node_modules/typescript/bin/tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@types/lodash": "^3.9.3",
"@types/nomnom": "0.0.28",
"@types/yamljs": "^0.2.30",
"lodash": "^3.9.3",
"nomnom": "^1.8.1",
"yamljs": "^0.2.1"
},
"devDependencies": {
"typescript": "~2.3.4"
}
}
serverApp /的package.json
{
"name": "my-server-app",
"version": "2.3.0",
"description": "",
"main": "myServerApp.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "private",
"dependencies": {
"loader": "file:modules/loader"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13"
}
}
我不确定是否与我们有.gitignore
file这个事实有关,或者因为该模块未在本地发布和安装。
npm version => 5.3.0
修改
不能指定"files"
中的modules/loader/package.json
答案 0 :(得分:0)
您是否使用node 0.6.13 / npm 1.1.9
进行了检查?此问题在npm 1.1.4
中很常见。
看看这个link
答案 1 :(得分:0)
在结账后我发现了以下有用的问题需要提及的问题:
我们使用 .npmignore 文件来保存您的软件包。 如果没有 .npmignore 文件,但有 .gitignore 文件,则npm将忽略.gitignore文件匹配的内容。
如果要包含 .gitignore 文件排除的内容,可以创建一个空的 .npmignore 文件来覆盖它。 和git一样,npm在包的所有子目录中查找 .npmignore 和 .gitignore 文件,而不仅仅是根目录。
与.gitignore文件类似.npmignore也遵循这些规则
以#开头的空行或行将被忽略&标准的glob模式有效。
您可以使用正斜杠 / 结束模式以指定目录。
您可以通过感叹号来启动模式来否定模式。
默认情况下,会忽略以下路径和文件,因此无需将其明确添加到 .npmignore
此外,除了捆绑的依赖项外,node_modules中的所有内容都将被忽略。 npm会自动为您处理此问题,因此请不要将node_modules添加到 .npmignore 。
测试您的.npmignore或文件配置是否有效
如果要仔细检查您的软件包是否仅包含您在发布时要使用的文件,可以在本地运行 npm pack命令,这将在工作目录中生成tarball,它与出版的方式相同。
您还可以在此处查看同一问题Consider methodologies for reducing the number of files within node_modules
#14872
感谢。