开发环境下子窗口的js无法导入vue
Ha0Chen opened this issue · comments
Ha0Chen commented
子窗口加载child.html页面,如下:
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Alpha</title>
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<!-- <meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self'; font-src 'none';img-src 'none'; style-src 'self' 'unsafe-inline'"
/> -->
</head>
<body>
<div id="app"></div>
<script type="module" src="./src/main.js"></script>
</body>
</html>
main.js如下:
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App);
app.mount('#app');
主进程的index.js中加载子窗口的函数如下:
function createChildWindow(event, results) {
const childWidth = 400;
const childHeight = 300;
childWindow = new BrowserWindow({
width: childWidth,
height: childHeight,
parent: mainWindow,
modal: false,
autoHideMenuBar: true,
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
nodeIntegration: true,
contextIsolation: false,
sandbox: false
}
});
childWindow.setMenu(null);
childWindow.loadFile('src/renderer/child.html');
childWindow.on('closed', () => {
childWindow = null;
});
childWindow.on('ready-to-show', () => {
childWindow.show();
});
}
electron.vite.config.js如下:
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src')
}
},
plugins: [
vue()
]
}
})
最终打开子窗口控制台报错如下:
Uncaught TypeError: Failed to resolve module specifier "vue". Relative references must start with either "/", "./", or "../".
第一次接触electron和vite,不知道什么原因,希望能得到一些帮助,谢谢!
Leo Wang(草鞋没号) commented
electron-vite
这包不是 https://github.com/electron-vite/ 提供的包