我注意到 Bootstrap和 Normalize.css两者的 package.json 中都有一个“样式”字段。
他们为什么有这个?如果我不得不猜测,它是为了让用户像 require('bootstrap')
一样轻松地导入定义的样式表,但似乎并非如此。
最佳答案
来自 Techwraith 的 pull request将其添加到 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
, andnpm-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/
其他工具也有支持,例如 browserify 插件 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 justmyModule.css
-- in the order of the js dependency graph, and write the output tobundle.css
.
关于node.js - package.json 中的 "style"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32037150/