All our server projects contain a git submodule folder (let's say modules
), which contains our custom modules/components.
Such module dependencies are installed locally (see serverApp/package.json
) so that we don't have to include the whole submodule folder to the final rpm. What I'm having trouble with is limiting the number of files included in node_modules
.
The submodule structure looks like the following:
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
Adding an .npmignore
file inside modules/loader
doesn't seem to help as the whole folder is copied.
modules/loader/tsconfig.json
{ "compilerOptions": { "target": "es6", "module": "commonjs", "declaration": true, "outDir": "./dist", "strict": true } }
modules/loader/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" } }
I'm not sure if it has to do with the fact that we have a .gitignore
file or because the module is not published and installed locally.
npm version => 5.3.0
EDIT
Doesn't work with specifying the "files"
in modules/loader/package.json
either
3 Answers
Answers 1
Did you checked with node 0.6.13 / npm 1.1.9
? This issue is common in npm 1.1.4
. have a look on this link
Answers 2
As after checkout the issue I found out below useful points which need to mention out :
We use a .npmignore file to keep stuff out of your package. If there's no .npmignore file, but there is a .gitignore file, then npm will ignore the stuff matched by the .gitignore file.
If you want to include something that is excluded by your .gitignore file, you can create an empty .npmignore file to override it. Like git, npm looks for .npmignore and .gitignore files in all subdirectories of your package, not only the root directory.
Similar to .gitignore file .npmignore also follow these rules
Blank lines or lines starting with # are ignored & Standard glob patterns work.
You can end patterns with a forward slash / to specify a directory.
You can negate a pattern by starting it with an exclamation point !.
By default, the following paths and files are ignored, so there's no need to add them to .npmignore explicitly
Additionally, everything in node_modules is ignored, except for bundled dependencies. npm automatically handles this for you, so don't bother adding node_modules to .npmignore.
Testing whether your .npmignore or files config works
If you want to double check that your package will include only the files you intend it to when published, you can run the npm pack command locally which will generate a tarball in the working directory, the same way it does for publishing.
And you can also checkout same issue here Consider methodologies for reducing the number of files within node_modules
#14872 Thanks.
Answers 3
You mentioned that you do not want to include "whole submodule" into the "final rpm", by which I presume the package you will finally prepare. I reproduced similar setup and added a '.npmignore' to ignore "submodule" which I installed using npm install --save ./task_in
where 'task_in' was my module kept along side of the main package's('task') 'package.json'.
And when the final package was prepared using npm pack
while being in the 'task' folder, I got a package(a tar file) without the folder('task_in') as indicated in the '.npmignore'.
While working, though, I found that the module 'task_in' folder was copied to 'node_modules' which is automatically not included in the final package( refer here). Also, while the package is prepared, ".gitignore" is over-ridden by ".npmignore".
So, this is my "two cents" and I hope it helps you.
0 comments:
Post a Comment