Is there a way to remove unused imports and declarations from Angular 2+?

后端 未结 7 631
长发绾君心
长发绾君心 2020-12-07 08:30

I\'m assigned to take some messed code from other developers who have already left the company recently.

I am curiously asking is there some plug-in of Visual Studio

相关标签:
7条回答
  • 2020-12-07 09:29

    There are already so many good answers on this thread! I am going to post this to help anybody trying to do this automatically! To automatically remove unused imports for the whole project this article was really helpful to me.

    In the article the author explains it like this:

    Make a stand alone tslint file that has the following in it:

    {
      "extends": ["tslint-etc"],
      "rules": {
        "no-unused-declaration": true
      }
    }
    

    Then run the following command to fix the imports:

     tslint --config tslint-imports.json --fix --project .
    

    Consider fixing any other errors it throws. (I did)

    Then check the project works by building it:

    ng build
    

    or

    ng build name_of_project --configuration=production 
    

    End: If it builds correctly, you have successfully removed imports automatically!

    NOTE: This only removes unnecessary imports. It does not provide the other features that VS Code does when using one of the commands previously mentioned.

    0 讨论(0)
提交回复
热议问题