Add custom metadata or config to package.json, is it valid?

前端 未结 2 1788
粉色の甜心
粉色の甜心 2021-01-30 01:46

I have seen (don\'t remember where) a package.json file with custom keys starting with an underscore:

{
    \"name\": \"application-name\"
  , \"version\": \"0.0         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 01:59

    Given the nature of JSON and this statement from the Nodejitsu documentation I don't see anything wrong with that.

    NPM itself is only aware of two fields in the package.json:

    {
       "name" : "barebones",
       "version" : "0.0.0",
    }
    

    NPM also cares about a couple of fields listed here. So as long as it is valid JSON and doesn't interfere with Node.js or NPM everything should be alright and valid.

    Node's awareness of package.json files seems extends to the main field. Ref.

     { "name" : "some-library",
       "main" : "./lib/some-library.js" }
    

    If this was in a folder at ./some-library, then require('./some-library') would attempt to load ./some-library/lib/some-library.js.

    This is the extent of Node's awareness of package.json files.

    To avoid possible conflicts you should prefixing your keys with some character or word. An underscore is a common variant.

提交回复
热议问题