Vue3.0的项目部署,以及利用Cordova打包app运行到真机

普通vue项目的部署

  1. 在vue3.0中部署的配置文件又换了一个地方,在vue.co在这里插入代码片nfig.js加入这样的话
	module.exports = {
     
	    publicPath: './',
	    outputDir: 'dist',
	    assetsDir: 'static'
	}
  1. 在项目根目录中的src/router/index.js,修改
const router = new VueRouter({
     
	//mode: 'history',
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
  1. 进入控制台,cd 到项目根目录中
	npm run build
	or
	yarn build
  1. Cordova环境搭建
确保android环境搭建好了,jdk,sdk,gradle
安装了node环境
$ npm install cordova -g
$ cordova create hello com.briup.hello 我的App

  1. 上面这一步容易出错
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第1张图片解决办法找到cordova项目将其node_modules删除后重新获取一下依赖
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第2张图片Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第3张图片
  2. 添加平台
$ cd hello
$ cordova platform add android
#添加安卓环境,还有很多,例如ios 自行去cordova官网查询
$ cordova platform ls
  1. 检测当前平台环境是否可用。
$ cordova requirements

成功截图
Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第4张图片

  1. 运行真机,此时手机端一定要开启手机的开发者模式,usb调试开启。
$ adb devices
  1. 因为现在大多手机的版本是安卓9.0以上的,所以需要修改我们cordova中的配置文件
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第5张图片 打开AndroidMainfest.xml,配置
    android:networkSecurityConfig="@xml/network_security_config"。
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10000" android:versionName="1.0.0" package="com.briup.superfoods" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" 
    android:networkSecurityConfig="@xml/network_security_config" 
    android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            
        
    


打开res/xml,新建network_security_config.xml配置如下信息。
Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第6张图片

  1. 然后回到控制台,接着进行第八步的操作,执行
$ cordova run android
  1. app运行到手机
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第7张图片

Vue、axios、vue-element-admin技术栈的打包操作

  1. 更改.env.production文件
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第8张图片

  2. 更改vue.config.js。
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第9张图片

  3. main.js中注释代码
    Vue3.0的项目部署,以及利用Cordova打包app运行到真机_第10张图片

  4. 执行npm run build.

安卓环境搭建

建议大家直接下载as(android studio)进行搭建
下载地址or下载地址
或者参考此处博主的博客博客地址

你可能感兴趣的:(Web,node)