1.新建一个英文目录test(自定义)
一定要是英文。否则会出问题
npm init --yes
加了yes参数就设定为使用所有默认。
项目名字用你目录的名字,版本号为1.0.0,主入口是index.js等
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
也可以
npm init
自己去一步一步的自定义
以我项目的举例,说一些常用的
{
"name": "phone",
"version": "1.8.9",
"private": true,
"description": "phone basing on vant 2.0.6",
"author": "Army_海军 ",
"main": "index.js",
"scripts": {
"serve": "vue-cli-service serve --open",
"build": "vue-cli-service build --mode production",
"lint": "vue-cli-service lint",
"build:dep": "vue-cli-service build --mode deployment",
"build:prod": "vue-cli-service build --mode production --watch",
"dev": "vue-cli-service serve --open"
},
"dependencies": {
"@vant/touch-emulator": "^1.2.0",
"axios": ">=0.18.1",
"dayjs": "^1.7.7",
"exif-js": "^2.3.0",
"js-cookie": "2.2.0",
"js-md5": "^0.7.3",
"lodash": "^4.17.11",
"pdfvuer": "^1.3.0",
"qrcodejs2": "0.0.2",
"v-viewer": "^1.5.1",
"vant": "^2.4.1",
"vue": "^2.5.17",
"vue-clipboard2": "^0.3.1",
"vue-i18n": "^8.12.0",
"vue-router": "^3.0.1",
"vuelidate": "^0.7.4",
"vuex": "^3.1.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.5",
"@vue/cli-plugin-eslint": "^3.0.5",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-prettier": "^3.0.5",
"babel-plugin-import": "^1.9.1",
"babel-plugin-lodash": "^3.3.4",
"node-sass": "^4.9.3",
"sass-loader": "^7.1.0",
"svg-sprite-loader": "3.8.0",
"vue-template-compiler": "^2.5.17"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"license": "MIT"
}
Name
必填字段 项目名称,不要中文,一些特殊符号还有js关键字也尽量不要用.
version
是版本 格式就是 0.0.0 第一个是主板本号,次版本,小版本 比如 jquery 2.6.1 jquery 3.0.4
description
描述你的项目
main
指定了程序的的主入口文件
scripts
指定了运行脚本命令的npm命令行缩写
"scripts": {
"serve": "vue-cli-service serve --open",
"build": "vue-cli-service build --mode production",
"lint": "vue-cli-service lint",
"build:dep": "vue-cli-service build --mode deployment",
"build:prod": "vue-cli-service build --mode production --watch",
"dev": "vue-cli-service serve --open"
}
直接可以npm run serve 就相当于执行了 vue-cli-service serve --open
author
作者信息
dependencies
指定了项目运行所依赖的模块 例如 vue lodash
devDependencies
指定项目开发时所需要的模块 例如 babel webpack. 等等
license
开源协议。
keywords
搜索关键字