“style” field in package.json

蹲街弑〆低调 提交于 2019-11-27 03:50:41

问题


I noticed that Bootstrap and Normalize.css both have a "style" field in their package.json.

Why do they have this? If I had to guess, it's to allow users to import the defined stylesheet as easily as doing require('bootstrap'), but that doesn't seem to be the case.


回答1:


From Techwraith's pull request that added it to Bootstrap:

Many modules in npm are starting to expose their css entry files in their package.json files. This allows tools like npm-css, rework-npm, and npm-less to import bootstrap from the node_modules directory. [...]

It's actually not written anywhere but in the code for these modules right now. We're hoping to get this standardized at some point, but we've all reached this convention separately, so I'm inclined to just go with it. [...]

If you want to read about this style of css development, I wrote a thing:

http://techwraith.com/your-css-needs-a-dependency-graph-too/

There's also support in other tools, such as the browserify plugin parcelify:

Add css to your npm modules consumed with browserify.

  • Just add a style key to your package.json to specify the package's css file(s). [...]

Parcelify will concatenate all the css files in the modules on which main.js depends -- in this case just myModule.css -- in the order of the js dependency graph, and write the output to bundle.css.



来源:https://stackoverflow.com/questions/32037150/style-field-in-package-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!