首页 > html > 如何删除node_modules文件夹中不需要的文件Angular 5

如何删除node_modules文件夹中不需要的文件Angular 5 (How to remove unwanted files in node_modules folder Angular 5)

2018-12-18 htmlcssangular5

问题

我想删除node_modules文件夹中不需要的文件,以减小大小和快速加载。加载时我的应用程序太慢我不知道是什么原因。任何人都建议我尽量减小文件大小。

这是我的package.json

    {
  "name": "CoreUI",
  "version": "1.0.0-alpha.4",
  "description": "Open Source Bootstrap Admin Template",
  "author": "",
  "url": "http://coreui.io",
  "copyright": "Copyright 2017 creativeLabs Łukasz Holeczek",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.2",
    "@angular/common": "^5.2.2",
    "@angular/compiler": "^5.2.2",
    "@angular/core": "^5.2.2",
    "@angular/forms": "^5.2.2",
    "@angular/http": "^5.2.2",
    "@angular/platform-browser": "^5.2.2",
    "@angular/platform-browser-dynamic": "^5.2.2",
    "@angular/platform-server": "^5.2.2",
    "@angular/router": "^5.2.2",
    "@angular/upgrade": "2.4.9",
    "angular-split": "^1.0.0-rc.3",
    "angular2-fontawesome": "^0.9.3",
    "angular2-image-upload": "^1.0.0-rc.0",
    "angular2-multiselect-dropdown": "^2.2.1",
    "angular2-notifications": "^1.0.2",
    "angular2-ui-switch": "^1.2.0",
    "chart.js": "^2.5.0",
    "chart.piecelabel.js": "^0.10.0",
    "core-js": "2.4.1",
    "e-ngx-fileupload": "^1.2.0",
    "font-awesome": "^4.7.0",
    "moment": "2.17.1",
    "mydatepicker": "^2.6.1",
    "mydaterangepicker": "^4.2.1",
    "ng2-bootstrap": "^1.4.0",
    "ng2-charts": "^1.5.0",
    "ng2-ckeditor": "^1.2.0",
    "ng2-drag-drop": "^3.0.2",
    "ng2-dragula": "^1.5.0",
    "ng2-fancy-image-uploader": "^2.0.1",
    "ng2-split": "^0.1.6",
    "ng2-split-pane": "^1.4.0",
    "ngx-bootstrap": "^2.0.3",
    "ngx-chips": "^1.6.7",
    "ngx-cookie-service": "^1.0.10",
    "ngx-quill": "^3.4.0",
    "ngx-quill-editor": "^2.2.2",
    "ngx-toggle-switch": "^1.3.9",
    "rxjs": "5.2.0",
    "ts-helpers": "1.1.2",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-rc.1",
    "@angular/compiler-cli": "^5.2.2",
    "@types/jasmine": "2.5.45",
    "@types/node": "7.0.8",
    "codelyzer": "2.0.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.5.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.3.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.1",
    "ts-node": "2.1.0",
    "tslint": "4.5.1",
    "typescript": "^2.6.2"
  }
}

我只想在节点模块中存在依赖文件。

提前致谢。

解决方法

除非您对自己所做的事情有信心,否则请勿触摸node_modules文件夹?这是正常的。通常,node_module文件夹的大小稍微高一些。这是因为它包含您正在使用的库及其依赖项及其依赖项。

在这里,我可以提供一些建议来减少node_modules文件夹的空间使用

  • 尝试尽可能使用最新的稳定版本的库
  • 使用最少数量的库。(不要只是没有目的地安装库)
  • 如果只使用vanilla javascript可以实现任务,则不需要使用库。

如果您认为自己意外添加了包并通过手动编辑package.json文件将其删除。只需删除整个node_modules目录并运行npm installyarn install

虽然node_module文件夹的大小很高。它们对性能的影响不大。在运行时,节点知道要执行的代码和不执行的代码。

你可以找到更多的信息,文章。

问题

I want to delete the unwanted files in node_modules folder to reduce the size and for fast loading. My application is too slow while loading I don't know what's the reason.Can anyone suggest me to minimize the file size.

Here is my package.json

    {
  "name": "CoreUI",
  "version": "1.0.0-alpha.4",
  "description": "Open Source Bootstrap Admin Template",
  "author": "",
  "url": "http://coreui.io",
  "copyright": "Copyright 2017 creativeLabs Łukasz Holeczek",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.2",
    "@angular/common": "^5.2.2",
    "@angular/compiler": "^5.2.2",
    "@angular/core": "^5.2.2",
    "@angular/forms": "^5.2.2",
    "@angular/http": "^5.2.2",
    "@angular/platform-browser": "^5.2.2",
    "@angular/platform-browser-dynamic": "^5.2.2",
    "@angular/platform-server": "^5.2.2",
    "@angular/router": "^5.2.2",
    "@angular/upgrade": "2.4.9",
    "angular-split": "^1.0.0-rc.3",
    "angular2-fontawesome": "^0.9.3",
    "angular2-image-upload": "^1.0.0-rc.0",
    "angular2-multiselect-dropdown": "^2.2.1",
    "angular2-notifications": "^1.0.2",
    "angular2-ui-switch": "^1.2.0",
    "chart.js": "^2.5.0",
    "chart.piecelabel.js": "^0.10.0",
    "core-js": "2.4.1",
    "e-ngx-fileupload": "^1.2.0",
    "font-awesome": "^4.7.0",
    "moment": "2.17.1",
    "mydatepicker": "^2.6.1",
    "mydaterangepicker": "^4.2.1",
    "ng2-bootstrap": "^1.4.0",
    "ng2-charts": "^1.5.0",
    "ng2-ckeditor": "^1.2.0",
    "ng2-drag-drop": "^3.0.2",
    "ng2-dragula": "^1.5.0",
    "ng2-fancy-image-uploader": "^2.0.1",
    "ng2-split": "^0.1.6",
    "ng2-split-pane": "^1.4.0",
    "ngx-bootstrap": "^2.0.3",
    "ngx-chips": "^1.6.7",
    "ngx-cookie-service": "^1.0.10",
    "ngx-quill": "^3.4.0",
    "ngx-quill-editor": "^2.2.2",
    "ngx-toggle-switch": "^1.3.9",
    "rxjs": "5.2.0",
    "ts-helpers": "1.1.2",
    "zone.js": "0.7.2"
  },
  "devDependencies": {
    "@angular/cli": "1.0.0-rc.1",
    "@angular/compiler-cli": "^5.2.2",
    "@types/jasmine": "2.5.45",
    "@types/node": "7.0.8",
    "codelyzer": "2.0.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.5.0",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.3.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "5.1.1",
    "ts-node": "2.1.0",
    "tslint": "4.5.1",
    "typescript": "^2.6.2"
  }
}

I want only dependency files to be present in node modules.

Thanks in Advance.

解决方法

Don't touch the node_modules folder unless you are confident in what you are doing? It's normal. Usually, node_module folder is a little bit higher in size. It's because It contains the libraries that you are using and their dependencies and their dependencies as well.

Here I can give some suggestions to reduce the Space usage of the node_modules folder

  • Try to use Most recent stable versions of the libraries as can as possible
  • Use a minimum number of libraries. (Don't just Install libraries without a purpose)
  • If the task is possible to achieve with just vanilla javascript it is not needed to use a library for that.

If you are thinking you have accidentally added packages and removed them by manually editing the package.json file. just delete the entire node_modules directory and run npm install or yarn install

although the size of the node_module folder is high. they don't have much effect on the performance sake. at the runtime, node knows what codes to execute and what not to execute.

You can find additional information from this article.

相似信息