简体   繁体   English

如何使用 npm-pkg 命令在 package.json 文件中添加一个点?

[英]How to add a dot in the package.json file using npm-pkg command?

I want to use the npm pkg set command to generate a package.json file like this:我想使用npm pkg set 命令生成一个 package.json 文件,如下所示:

{
  ...
  "exports": {
    ".": {
      "import": "./dist/my-lib.js",
      "require": "./dist/my-lib.umd.cjs"
    }
  }
  ...
}

But I'm not able to add the "."但我无法添加“。” key钥匙

I tried running npm pkg set exports..import=./dist/my-lib.js and npm pkg set exports.\.import=./dist/my-lib.js我尝试运行npm pkg set exports..import=./dist/my-lib.jsnpm pkg set exports.\.import=./dist/my-lib.js

You can set a property directly in json format:您可以直接以 json 格式设置属性:

npm pkg set export='{".":{"import": "./dist/my-lib.js","require": "./dist/my-lib.umd.cjs"}}' --json

Please note that this will overwrite existing "export" property.请注意,这将覆盖现有的“导出”属性。

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

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