Automate the process of packaging and publishing applets
The existing problems in
- The test cannot publish the version it wants.
- The code of Vue is packaged into the code of wechat applet.
- The packaged code cannot be pushed to the wechat developer platform.
- After the build, you cannot test directly with the corresponding environment.
Associated dependencies and configurations
-
Package into the format required by wechat
- Vue-cli-service uni-build installs the corresponding Vue scaffolding
- Operation and maintenance platform directly build into a fixed wechat package, regardless of the environment. The completed build file is in dist/dev/mp-weixin
"build": "cross-env NODE_ENV=prod UNI_PLATFORM=mp-weixin vue-cli-service uni-build --report"."prod": "cross-env NODE_ENV=prod UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch"."stg": "cross-env NODE_ENV=stg UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch".Copy the code
-
Push the packaged code to wechat platform
- Install miniprogram – ci
- In the development mp.weixin.qq.com/ development management/development Settings/applets code upload specified fixed IP whitelist
- In the development of mp.weixin.qq.com/ development management/development Settings/applets code upload generate applets code upload key
const ci = require('miniprogram-ci'); const config = require('./config.json'); // Release information const manifest = require('.. /manifest.json'); // Basic information of wechat applet let { wxVersion: version, wxDesc: desc } = config; const appid = manifest['mp-weixin'].appid; const cwd = process.cwd() + '/dist/dev/mp-weixin'; if(! version) version ='v1.0.0'; if(! desc) desc =new Date() + 'upload'; const project = new ci.Project({ appid: appid, type: 'miniProgram'.projectPath: cwd, privateKeyPath: process.cwd() + '/src/wxupload/private.wxea2e525a470f0b4d.key'./ / the secret key ignores: ['.. /node_modules/**/*']});Copy the code
- upload
ci.upload({ project, version, desc, setting: { minify: true, }, }).then(res= > { console.log(res) console.log('Upload successful') }).catch(error= > { if (error.errCode == -1) { console.log('Upload successful')}console.log(error) console.log('Upload failed') process.exit(-1)})Copy the code
- Release completion is also with preview function, generated a TWO-DIMENSIONAL code image scan code use.
-
So far the build, upload, publish and other functions have been completed.
use
- The o&M platform pulls the specified file branch package from the Git repository.
- After pulling, execute NPM build to generate packaged files based on the formal environment.
- The test needs to test the environment of the small program, release the need to select the corresponding environment.
- O&m platform replaces global environment variables specified by the foreground.
- Automatic release after replacement, automatic preview. The test can be accessed by previewing the QR code for specific applets.
The development process
- Vscode for development, from the corresponding environment, the default open hot update.
- Debug and preview with wechat applets.
- Fill in the current version number and version update description in the wechat profile.