要打包 Vue 项目成 app,你可以使用一些工具,如 Cordova、Electron 或者 NativeScript。
使用 Cordova 打包:
- 安装 Cordova:
npm install -g cordova
- 创建 Cordova 项目:
cordova create my-app
- 进入项目目录:
cd my-app
- 添加平台,如 Android:
cordova platform add android
- 将 Vue 项目构建成可以部署的代码:
npm run build
- 将构建后的代码拷贝到 Cordova 项目中:
cp -r dist/* www/
- 构建并运行 Cordova 项目:
cordova build android
使用 Electron 打包:
- 安装 Electron:
npm install -g electron
- 将 Vue 项目构建成可以部署的代码:
npm run build
- 创建 Electron 配置文件
main.js
,内容如下:
const { app, BrowserWindow } =require('electron')
function createWindow () {
// 创建浏览器窗口
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
// 加载应用的 index.html
win.loadFile('dist/index.html')
}
app.whenReady().then(createWindow)