1. node.js 项目包下的 package.json :
实例:
{
"name" : "chatroooms",
"version" : "0.0.1",
"description" : "Minimalist multiroom chat server",
"dependencies" : {
"socket.io" : "~0.9.6",
"mime" : "~1.2.7"
}
}
或者
{
"name" : "learn-nodejs",
"version" : "0.0.1",
"description" : "This is my learning package",
"license" : "SEE LICENSE IN license.txt",
"repository" : {
"type" : "git",
"url" : "https://github.com/npm/npm.git"
},
"dependencies" : {
"socket.io" : "~0.9.6",
"mime" : "~1.2.7"
}
}
一般 name, version, description, license 和 repository 是必须写的。更全的一点的还有:
{
"name": "module-name",
"version": "10.3.1",
"description": "An example module to illustrate the usage of a package.json",
"author": "Your Name <you.name@example.org>",
"contributors": [{
"name": "Foo Bar",
"email": "foo.bar@example.com"
}],
"bin": {
"module-name": "./bin/module-name"
},
"scripts": {
"test": "vows --spec --isolate",
"start": "node index.js",
"predeploy": "echo im about to deploy",
"postdeploy": "echo ive deployed",
"prepublish": "coffee --bare --compile --output lib/foo src/foo/*.coffee"
},
"main": "lib/foo.js",
"repository": {
"type": "git",
"url": "https://github.com/nodejitsu/browsenpm.org"
},
"bugs": {
"url": "https://github.com/nodejitsu/browsenpm.org/issues"
},
"keywords": [
"nodejitsu",
"example",
"browsenpm"
],
"dependencies": {
"primus": "*",
"async": "~0.8.0",
"express": "4.2.x",
"winston": "git://github.com/flatiron/winston#master",
"bigpipe": "bigpipe/pagelet",
"plates": "https://github.com/flatiron/plates/tarball/master"
},
"devDependencies": {
"vows": "^0.7.0",
"assume": "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0",
"pre-commit": "*"
},
"preferGlobal": true,
"private": true,
"publishConfig": {
"registry": "https://your-private-hosted-npm.registry.nodejitsu.com"
},
"subdomain": "foobar",
"analyze": true,
"license": "MIT"
}
更多关于package.json的解释,可以参考npm官网说明:https://docs.npmjs.com/files/package.json
2. node.js 既然是依靠google V8引擎驱动的,而chrome浏览器内置了V8,所以就诞生了 node-webkit 这样的项目.
它的执行宿主也是 浏览器,但是由于 node.js 的支持,我们可以轻松访问当前执行环境的OS ,这不就是PC 客户端程序的功能吗.
可见 node-webkit 项目利用了web UI 的优势,node.js 访问本地OS 的优势,从而用 javascript 实现了一个本地 客户端程序.
今天我们首先来看下一个简单的 node-webkit 项目中 package.json 中,各项所代表的意义.
实例:
{
"name": "ServerManage",
"main": "index.html",
"nodejs": true,
"window": {
"title": "Server Manage",
"toolbar": false,
"width": 480,
"height": 350,
"resizable": true,
"show_in_taskbar": true,
"frame": true,
"kiosk": false,
"position": "center"
},
"webkit": {
"plugin": true
},
"chromium-args": "--enable-threaded-compositing"
}
必填字段
main node-webkit打开时的默认页面
name 包的名字,必须为独一无二的,可由字母,数字,下划线组成,不能有空格
功能性字段
nodejs node-webkit中是否启用 node.js (布尔值)
node-main node-webkit打开时的加载的node.js文件
可通过process.mainModule访问
window 控制窗口的样子,后文细讲。
webkit 控制webkit特性是否启用,后文细讲。
窗口字段
title 默认打开的窗口页面的title
toolbar 是否显示工具栏,地址栏等(布尔值)
icon 此应用图标的路径地址
position 只可能是这么几个值null center mouse。null指无定位,center指在显示器中间,mouse指在鼠标的位置。
min_width/min_height (整形)定义宽度和高度的最小值。
resizable 窗口是否可调整大小 (布尔值)
always-on-top 窗口是否总是置顶状态(布尔值)
fullscreen 打开时是否全屏(默认是否全屏打开)
frame 是否显示窗口框架 (布尔值) 不显示将无法拖动
show 是否在任务栏上显示 (布尔值)
kiosk 是否处于kiosk状态,在kiosk状态下将全屏并且阻止用户关闭窗口(布尔值)
参考:node-webkit 项目中的 package.json 格式
原文转自:Node.js:项目中的 package.json 格式
本文详细解析了Node.js项目中的package.json文件结构及其各字段意义,包括必填字段、功能性字段及窗口字段等内容,帮助开发者更好地理解并配置项目。

被折叠的 条评论
为什么被折叠?



