Unused package in package.json affect the project
Clash Royale CLAN TAG#URR8PPP
Unused package in package.json affect the project
I need to know if package.json
contains many unused packages. It will affect my project size or runtime execution.
package.json
Most of the packages are not used in the project.
"dependencies":
...,
"angular-calendar": "^0.24.0",
"angular2-text-mask": "^8.0.4",
"aws-sdk": "^2.175.0",
"core-js": "^2.4.1",
"date-fns": "^1.29.0",
"enum": "^2.5.0",
"fullcalendar": "^3.6.1",
"hammerjs": "^2.0.8",
"husky": "^0.14.3",
"jquery": "^3.3.1",
"json2typescript": "^1.0.5",
"lodash": "^4.17.4",
"marked": "^0.3.6",
"material-design-icons": "^3.0.1",
"moment": "^2.22.1",
"replace-in-file": "^3.4.0",
"rxjs": "^5.1.0",
"ts-helpers": "^1.1.2",
"zone.js": "^0.8.4"
,
"devDependencies":
...,
"@types/jasmine": "2.5.47",
"@types/marked": "^0.0.28",
"@types/node": "~7.0.16",
"codelyzer": "~3.0.1",
"copy-webpack-plugin": "^4.3.0",
"tslint": "~5.2.0",
"typescript": "2.4.2"
3 Answers
3
Package.json contains the list of dependencies and dev-dependencies needed for building your project. Any package not referenced by your module will not go into final production bundle, so doesn't affect runtime size.
you can check the size of your vendor.bundle.js inside dist folder, by adding and removing few unused packages in package.json and doing a production build.
ng build --prod --vendor-chunk=true
In terms of project size on disk, yes it will increase as all the packages from package.json are downloaded in your node_modules project folder.
If you are using prod build or build optimizer the cli will remove every unused modules etc from your project.
ng build --prod --build-optimizer
Use the above command for production build.
For more details visit this article
Thanks , Get errors while running above command. I run ng build --prod --aot=false. My should is should I remove unused modules or ignore it. If these module wont effect my project.
– Nits
Aug 10 at 10:31
you can remove unused code using tree shacking
– Chellappan
Aug 10 at 10:55
what errors? usually when you are in development mode cli does not generate many errors but when you build production you get errors
– Ans Bilal
Aug 10 at 11:05
Using source-map-explorer, you can analyze the bundle size of each Package.You need to install source-map-explorer using npm.
npm install source-map-explorer --save-dev
To build the app sourece code. you can use
ng build --prod --source-map
To run the explorer, you can use this command
node_modules/.bin/source-map-explorer dist/main.*.bundle.js
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Welcome to Stack Overflow! I edited the title and content of your question in order to improve grammar. Please edit in the specific error-message you're encountering in case that's necessary to identify the specific problem. Good luck!
– Mickaël B
Aug 10 at 13:04