node.js - package.json 中的 "style"字段

标签 node.js npm node-modules package.json

我注意到 BootstrapNormalize.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, 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/

其他工具也有支持,例如 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 just myModule.css -- in the order of the js dependency graph, and write the output to bundle.css.

关于node.js - package.json 中的 "style"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32037150/

相关文章:

reactjs - 从构建 React.js 中排除 .js 文件

javascript - Node js Rest Service将数据保存到特定的对象json中

node.js - npm 模块发布后丢失文件

css - 如何着手从 node.js 中的一组 url 创建图像库。

node.js - 序列化 findAll 排除字段

node.js - npm copyfiles 不正确的目标路径

javascript - 对话流中 request 和 Cheerio 的问题

node.js - 在 Node V14 中从 std/esm 迁移到 esm 支持——找不到命名导入——与 std/esm 一起工作正常

node.js - 部署到 Heroku 时已弃用 Meteor Fibers

javascript - 如何在 Node.js/ReactJS 中正确使用 DELETE by ID