# 执行npm init ,初始化 package.json,-y表示接受默认值
npm init -y
项目的package.json
{
"name": "deep-playground-prototype",# 名称和版本共同构成一个标识符
"version": "2016.3.10",# 发布时使用
"description": "", # 描述
"private": true,# 如果 "private": true 在 package.json 中设置,则 npm 将拒绝发布它。
"scripts": {
"clean": "rimraf dist",
"start": "npm run serve-watch",
"prep": "copyfiles analytics.js dist && concat node_modules/material-design-lite/material.min.js node_modules/seedrandom/seedrandom.min.js > dist/lib.js",
"build-css": "concat node_modules/material-design-lite/material.min.css styles.css > dist/bundle.css",
"watch-css": "concat node_modules/material-design-lite/material.min.css styles.css -o dist/bundle.css",
"build-html": "copyfiles index.html dist",
"watch-html": "concat index.html -o dist/index.html",
"build-js": "browserify src/playground.ts -p [tsify] | uglifyjs -c > dist/bundle.js",
"watch-js": "watchify src/playground.ts -p [tsify] -v --debug -o dist/bundle.js",
"build": "npm run prep && npm run build-js && npm run build-css && npm run build-html",
"watch": "npm run prep && concurrently \"npm run watch-js\" \"npm run watch-css\" \"npm run watch-html\"",
"serve": "npx serve dist/",
"serve-watch": "concurrently \"npx serve dist/\" \"npm run watch\""
},
"devDependencies": {
"@types/d3": "^3.5.34",
"concat": "^1.0.3",
"concurrently": "3.1.0",
"copyfiles": "1.0.0",
"rimraf": "2.5.4",
"serve": "^11.3.0",
"tsify": "^4.0.0",
"typescript": "^2.9",
"uglify-js": "^2.8.29",
"watchify": "^4.0.0"
},
"dependencies": {
"d3": "^3.5.16",
"material-design-lite": "^1.3.0",
"seedrandom": "^2.4.3"
}
}
开发依赖 devDependencies ,运行依赖 dependencies
npm i -D
参数 | 解释 |
---|---|
P, –save-prod | 包将出现在您的中 dependencies,默认设置 |
D, –save-dev | 包在devDependencies |
O, –save-optional | 包在 optionalDependencies |
no-save | 防止保存到 dependencies |
根据scripts里的配置,我们可以运行以下代码:
npm run clean
npm run start
npm run prep
npm run serve
在一开始的项目构建里一共运行了三句代码,其中有两个是与scripts有关的:
npm i # 安装依赖
npm run build # scripts中的build
npm run serve # scripts中的serve
参考与更多
npm Docs
中文译
package-lock.json
# webpack 项目管理
cnpm i -D webpack webpack-cli typescript ts-loader
or
npm i -D webpack webpack-cli typescript ts-loader
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)