简体   繁体   English

.min或src作为node_module的package.json中的“main”-file

[英].min or src as “main”-file in package.json for node_module

I'm writing a Library for the Browser (JS, CSS) that was dependency-free up until now. 我正在为浏览器(JS,CSS)编写一个迄今为止无依赖的库。 Now I have at least one dependency and I'm thinking about wether or not to include the deps into the build or not. 现在我至少有一个依赖项,我正在考虑是否将deps包含在构建中。

Let's say my user uses a CDN - of course the minified file of my library should include the dependency. 假设我的用户使用CDN - 当然,我的库的缩小文件应该包含依赖项。 But what about module bundlers like webpack? 但是像webpack这样的模块捆绑包呢? If someone require / import s the lib, should the package.json point to the src entry or the minified file? 如果有人require / import lib,那么package.json应该指向src条目还是缩小文件? Wouldn't the module bundler install and include the dependency anyway, so the minified file would be duplicate code (of the dependency)? 模块捆绑器不会安装并包含依赖关系,因此缩小的文件将是重复的代码(依赖关系)?

What's the best practice for this? 这是最好的做法是什么?

Namely, I build a leaflet plugin that will depend on some modules of turfJS. 也就是说,我构建了一个小叶插件,它将取决于turfJS的某些模块。 Leaflet is a peerDependency whereas turf is a dependency. Leaflet是一个peerdependency而turf是一个依赖。

jsDelivr let's you combine your dependencies. jsDelivr让你结合你的依赖。 According to CDNperf , it offers one of the lowest latencies of any CDN. CDNperf称 ,它提供了任何CDN最低延迟之一。

.min or src as “main”-file in package.json for node_module .min或src作为node_module的package.json中的“main”-file

  • src: "main" field src: "main"字段
  • min: "unpkg" field min: "unpkg"字段

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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