package.json的两个字段-main和files

###main
main 字段就是当你import一个组件时的入口。比如element-ui,当我们引入时:

import ElementUI from 'element-ui';

系统会默认寻找main入口,显然,我们需要指定其打包目录lib作为入口,而当不指定main 字段时,默认值是模块根目录下面的 index.js 。
看一下element-ui的package.json:

{
  "name": "element-ui",
  "version": "2.15.13",
  "description": "A Component Library for Vue.js.",
  "main": "lib/element-ui.common.js",
  "files": [
    "lib",
    "src",
    "packages",
    "types",
    "web-types.json"
  ],
  "typings": "types/index.d.ts",
  "scripts": {
    ...
  },
  "faas": [
    {
      "domain": "element",
      "public": "temp_web/element"
    },
    {
      "domain": "element-theme",
      "public": "examples/element-ui",
      "build": [
        "yarn",
        "npm run deploy:build"
      ]
    }
  ],
  "repository": {
    "type": "git",
    "url": "git@github.com:ElemeFE/element.git"
  },
  "homepage": "http://element.eleme.io",
  "keywords": [
    "eleme",
    "vue",
    "components"
  ],
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/ElemeFE/element/issues"
  },
  "unpkg": "lib/index.js",
  "style": "lib/theme-chalk/index.css",
  "web-types": "./web-types.json",
  "dependencies": {
    ...
  },
  "peerDependencies": {
    "vue": "^2.5.17"
  },
  "devDependencies": {
    ...
  }
}

其实就是找的lib/element-ui.common.js:

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
...

###files
描述了将软件包作为依赖项安装时要包括的条目,默认值为[“*”],这意味着它将包括所有文件。
files里面指定哪些文件,安装时就出现哪些,不指定的,就隐藏了。你还可以在包的根目录或子目录中提供.npmignore 文件,以防止某些文件被发布。
.npmignore 文件的工作原理与.gitignore 一样。
如果存在.gitignore 文件,而缺少.npmignore,则将改用.gitignore 的内容。
files字段内容会覆盖.npmignore 和.gitignore的内容。
还是看一下element-ui的,这个版本基本把源代码都公开出来了,但后面的plus版本就隐藏了很多东西。

{
...
"files": [
    "lib",
    "src",
    "packages",
    "types",
    "web-types.json"
  ],
}

其他的字段,兄弟们请参考文章:https://www.jianshu.com/p/c86d511d99fd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值