###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