我的项目是通过 HBuilder X(3.4.14.20220607) 创建的 uni-ui 项目.
我通过HBuilder X提供的 "生成本地打包app资源" 功能,可以正常创建app本地资源包.然后通过android studio也可以正常编译出apk.
我现在想通过命令行实现自动生成本地打包app资源.
看了官方教程后,发现需要通过vue-cli命令行创建的项目才能进行打包.
于是我通过这个命令创建了空项目:
vue create -p dcloudio/uni-preset-vue my-project
然后复制这个项目中的package.json文件到我的项目中.
最终的package.json参考:
{
"id": "Test.Gui",
"displayName": "测试项目",
"version": "1.0.0",
"description": "测试项目",
"keywords": [],
"scripts": {
"serve": "npm run dev:h5",
"build": "npm run build:h5",
"build:app-plus": "cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build",
"build:custom": "cross-env NODE_ENV=production uniapp-cli custom",
"build:h5": "cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build",
"build:mp-360": "cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build",
"build:mp-alipay": "cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build",
"build:mp-baidu": "cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build",
"build:mp-jd": "cross-env NODE_ENV=production UNI_PLATFORM=mp-jd vue-cli-service uni-build",
"build:mp-kuaishou": "cross-env NODE_ENV=production UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build",
"build:mp-lark": "cross-env NODE_ENV=production UNI_PLATFORM=mp-lark vue-cli-service uni-build",
"build:mp-qq": "cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build",
"build:mp-toutiao": "cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build",
"build:mp-weixin": "cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build",
"build:mp-xhs": "cross-env NODE_ENV=production UNI_PLATFORM=mp-xhs vue-cli-service uni-build",
"build:quickapp-native": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-native vue-cli-service uni-build",
"build:quickapp-webview": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview vue-cli-service uni-build",
"build:quickapp-webview-huawei": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build",
"build:quickapp-webview-union": "cross-env NODE_ENV=production UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build",
"dev:app-plus": "cross-env NODE_ENV=development UNI_PLATFORM=app-plus vue-cli-service uni-build --watch",
"dev:custom": "cross-env NODE_ENV=development uniapp-cli custom",
"dev:h5": "cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve",
"dev:mp-360": "cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch",
"dev:mp-alipay": "cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch",
"dev:mp-baidu": "cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch",
"dev:mp-jd": "cross-env NODE_ENV=development UNI_PLATFORM=mp-jd vue-cli-service uni-build --watch",
"dev:mp-kuaishou": "cross-env NODE_ENV=development UNI_PLATFORM=mp-kuaishou vue-cli-service uni-build --watch",
"dev:mp-lark": "cross-env NODE_ENV=development UNI_PLATFORM=mp-lark vue-cli-service uni-build --watch",
"dev:mp-qq": "cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch",
"dev:mp-toutiao": "cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch",
"dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch",
"dev:mp-xhs": "cross-env NODE_ENV=development UNI_PLATFORM=mp-xhs vue-cli-service uni-build --watch",
"dev:quickapp-native": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-native vue-cli-service uni-build --watch",
"dev:quickapp-webview": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview vue-cli-service uni-build --watch",
"dev:quickapp-webview-huawei": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-huawei vue-cli-service uni-build --watch",
"dev:quickapp-webview-union": "cross-env NODE_ENV=development UNI_PLATFORM=quickapp-webview-union vue-cli-service uni-build --watch",
"info": "node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js",
"serve:quickapp-native": "node node_modules/@dcloudio/uni-quickapp-native/bin/serve.js",
"test:android": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=android jest -i",
"test:h5": "cross-env UNI_PLATFORM=h5 jest -i",
"test:ios": "cross-env UNI_PLATFORM=app-plus UNI_OS_NAME=ios jest -i",
"test:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu jest -i",
"test:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin jest -i"
},
"repository": "",
"engines": {
"HBuilderX": "^3.2.6"
},
"dcloudext": {
"category": [],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "y",
"IE": "n",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "y"
}
}
}
},
"dependencies": {
"@dcloudio/uni-app-plus": "^2.0.1-34920220609002",
"@dcloudio/uni-h5": "^2.0.1-34920220609002",
"@dcloudio/uni-helper-json": "*",
"@dcloudio/uni-i18n": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-360": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-alipay": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-baidu": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-jd": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-kuaishou": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-lark": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-qq": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-toutiao": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-vue": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-weixin": "^2.0.1-34920220609002",
"@dcloudio/uni-mp-xhs": "^2.0.1-34920220609002",
"@dcloudio/uni-quickapp-native": "^2.0.1-34920220609002",
"@dcloudio/uni-quickapp-webview": "^2.0.1-34920220609002",
"@dcloudio/uni-stat": "^2.0.1-34920220609002",
"@vue/shared": "^3.0.0",
"core-js": "^3.6.5",
"flyio": "^0.6.2",
"regenerator-runtime": "^0.12.1",
"vue": "^2.6.11",
"vuex": "^3.2.0"
},
"devDependencies": {
"@babel/runtime": "~7.17.9",
"@dcloudio/types": "^2.6.7",
"@dcloudio/uni-automator": "^2.0.1-34920220609002",
"@dcloudio/uni-cli-i18n": "^2.0.1-34920220609002",
"@dcloudio/uni-cli-shared": "^2.0.1-34920220609002",
"@dcloudio/uni-migration": "^2.0.1-34920220609002",
"@dcloudio/uni-template-compiler": "^2.0.1-34920220609002",
"@dcloudio/vue-cli-plugin-hbuilderx": "^2.0.1-34920220609002",
"@dcloudio/vue-cli-plugin-uni": "^2.0.1-34920220609002",
"@dcloudio/vue-cli-plugin-uni-optimize": "^2.0.1-34920220609002",
"@dcloudio/webpack-uni-mp-loader": "^2.0.1-34920220609002",
"@dcloudio/webpack-uni-pages-loader": "^2.0.1-34920220609002",
"@vue/cli-plugin-babel": "~4.5.15",
"@vue/cli-service": "~4.5.15",
"babel-plugin-import": "^1.11.0",
"cross-env": "^7.0.2",
"jest": "^25.4.0",
"mini-types": "*",
"miniprogram-api-typings": "*",
"postcss-comment": "^2.0.0",
"vue-template-compiler": "^2.6.11"
},
"browserslist": [
"Android >= 4.4",
"ios >= 9"
],
"resolutions": {
"@babel/runtime": "~7.17.9"
},
"uni-app": {
"scripts": {}
}
}
然后我通过下面的命令进行构建时提示下面所示信息:
npm run build:app-plus
> build:app-plus
> cross-env NODE_ENV=production UNI_PLATFORM=app-plus vue-cli-service uni-build
项目根目录下的dist文件夹没有生成.
也没有任何错误提示.
如果使用HBuilderX则能正常在 "项目目录\unpackage\resources"下生成所需要的文件.
请问我该如何操作才能使用命令行进行打包?
l***@163.com (作者)
感谢回复.
2022-06-15 09:55
l***@qq.com
HBuilderX 3.5.3.20220729
cli publish --platform APP --type appResource --project hotel
Clear-Item : 找不到接受实际参数“--platform”的位置形式参数。
所在位置 行:1 字符: 1
2022-08-11 09:40
DCloud_HB_WDL
回复 l***@qq.com: windows电脑,请注意是cli.exe
2022-08-11 10:28