chore: upate

This commit is contained in:
草鞋没号 2020-08-31 09:50:57 +08:00
parent 278a3468d2
commit 79cd832cfc
11 changed files with 45 additions and 12 deletions

View File

@ -1,7 +1,7 @@
{
"name": "electron-vue",
"version": "0.0.1",
"main": "src/main/_.js",
"main": "dist/main/_.js",
"author": "草鞋没号 <308487730@qq.com>",
"license": "MIT",
"scripts": {
@ -17,8 +17,7 @@
"appId": "308487730@qq.com",
"files": [
"!node_modules",
"src/main/**",
"src/render/dist/**"
"dist/**"
],
"mac": {
"artifactName": "${productName}_setup_${version}.${ext}",

View File

@ -15,11 +15,14 @@ function createWin() {
win = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
nodeIntegration: true,
},
})
const URL = is_dev
? `http://localhost:${process.env.PORT}` // vite 启动的服务器地址
: `file://${join(__dirname, '../render/dist/index.html')}` // vite 构建后的静态文件地址
: `file://${join(__dirname, '../../dist/render/index.html')}` // vite 构建后的静态文件地址
win.loadURL(URL)
}

5
src/main/preload.js Normal file
View File

@ -0,0 +1,5 @@
const { ipcRenderer } = require('electron')
window.stopLoading = function() {
ipcRenderer.send('stop-loading-main')
}

View File

@ -3,7 +3,7 @@
<img style="height:200px;" src="./assets/electron.png" alt="Electron logo">
<img alt="Vue logo" src="./assets/logo.png" />
</div>
<HelloWorld msg="Hello Electron 9.0 + Vue 3.0 Vite" />
<HelloWorld msg="Hello Electron 9.0 + Vue 3.0 + Vite" />
</template>
<script>

View File

@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script type="module" src="/main.js"></script>
<script type="module" src="/main.ts"></script>
</body>
</html>

View File

@ -1,5 +0,0 @@
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
createApp(App).mount('#app')

9
src/render/main.ts Normal file
View File

@ -0,0 +1,9 @@
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
// vite 会编译 import 的形式;所以 electron 及 node.js 内置模块用 require 形式
const { ipcRenderer } = require('electron')
console.log(ipcRenderer)
createApp(App as any).mount('#app')

4
src/render/shims.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}

4
src/render/source.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
declare const React: string
declare module '*.json'
declare module '*.png'
declare module '*.jpg'

5
typings/typings.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
interface Window {
/** 浏览器下开发,关闭 electron 载入动画 */
stopLoading: () => void
}

View File

@ -6,11 +6,20 @@ import { UserConfig } from 'vite'
import dotenv from 'dotenv'
dotenv.config({ path: join(__dirname, '.env') })
const root = join(__dirname, 'src/render')
const config: UserConfig = {
root: join(__dirname, 'src/render'),
root,
port: +process.env.PORT,
base: './',
outDir: join(__dirname, 'dist/render'),
alias: {
// 别名必须以 / 开头、结尾
'/@/': root,
},
optimizeDeps: {
allowNodeBuiltins: ['electron-is-dev', 'electron-store', 'electron']
},
}
export default config