简体   繁体   中英

Is there any way to comment in or better organize a bower.json file?

I have a very large project with numerous bower dependencies. In many cases it is unclear whether these dependencies are even still in use within the application or if the version specified was chosen for a reason. Ideally, I would like to be able to put a comment for each dependency to state for which part of the application it is required, so as functionality in the application is removed, we can also remove unnecessary packages from the bower_components. Something like:

// videojs plug-in for adding navigable waveforms; used by the video component
"videojs-wavesurfer": "^1.2.2"

Unfortunately, json doesn't support commenting, but are there any possible solutions for annotating or better organizing a bower.json file to make it more understandable?

You cannot put comments in a JSON file. JSON is for data and nothing else.

If you would like to document your dependencies, consider adding a section to your README file that contains all of the information relevant to dependencies.

The classic approach to commenting JSON files is to add fake entries, which hopefully will be ignored by the consumer, such as:

"video-wavesurfer-comment": 
  "videojs plug-in for adding navigable waveforms; used by the video component"

For longer comments, use arrays:

"video-wavesurfer-comment": [
  "videojs plug-in for adding navigable waveforms; used by the video component",
  "Remove this for the non-video version."
]

Of course, you'll have to put these somewhere where someone won't try to parse them. For instance, they could not go WITHIN "dependencies": .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM