【微信小程序】uniapp微信小程序环境配置

468 阅读1分钟

1.抛弃config文件来一键运行小程序

1. 初始化项目

npm init -y (y --》代表yes ,省去了默认选项点击)

2.此时生成package.json 文件

image.png

3.配置运行环境 uni-app

{
  "name": "xxx-xxxx",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "dependencies": {
    "uview-ui": "^1.8.4"
  },
  "devDependencies": {
    "sass": "^1.62.1",
    "sass-loader": "^10.4.1"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "http://123.60.67.216/xx-xxx/xxx-xx-xxx-xx.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "uni-app": {
  	"scripts": {
  		"dev": {
  			"title": "本地测试版",
  			"env": { 
  				"UNI_PLATFORM": "mp-weixin", 
  				"VUE_APP_BASE_URL": "http://192.168.1.25:8020/xx-xx/"
  			}
  		},
  		"pre": {
  			"title": "测试服务器版",
  			"env": {
  				"UNI_PLATFORM": "mp-weixin",
  				"VUE_APP_BASE_URL": "https://admin-test.xxxxx.com/xx-xx/"
  			}
  		},
  		"prod": {
  			"title": "正式版",
  			"env": {
  				"UNI_PLATFORM": "mp-weixin",
  				"VUE_APP_BASE_URL": "https://xx.xx.com/xx-xx/"
  			}
  		}
  	}
  }
}

4.此时就可以一键运行到配置的环境了

image.png