我正在创建第二个BrowserWindow并加载一个html文件。 HTML文件指向TypeScript文件。因此,它给出了错误。如何告诉包裹将文件转换为js并在主进程中加载url?
// main.ts
const windows: BrowserWindow[] = []
ipcMain.on('something:start', (event: Event) => {
const url = format({
pathname: resolve('app/renderer/secondWindow.html'),
protocol: 'file:',
slashes: true
})
const window = new BrowserWindow({ width: 800, height: 600, show: true })
window.loadURL(url)
window.on('closed', () => {
windows.splice(windows.findIndex(w => w === window), 1)
})
windows.push(window)
})
//secondWindow.html
<html>
<head>
<meta charset="UTF-8" />
<title>LetLock - Encrypt process</title>
</head>
<body>
<div id="root"></div>
</body>
<script src="./someFunctions.ts"></script>
</html>
// package.json
"scripts": {
"start": "run-p -r parcel:launch electron:launch",
"dist": "run-s parcel:build \"electron:build {@}\" --",
"electron:launch": "run-s parcel:main electron:start",
"electron:start": "electron .",
"electron:build": "build --dir --x64 --publish=never",
"parcel:launch": "parcel app/renderer/index.html --port 1124 --out-dir app/renderer/.parcel/development",
"parcel:build": "run-s parcel:main parcel:renderer",
"parcel:main": "parcel build app/main/main.ts --out-dir app/main/.parcel --out-file main --target electron",
"parcel:renderer": "parcel build app/renderer/index.html --public-url ./ --out-dir app/renderer/.parcel/production",
"test": "run-s parcel:build \"test:jest {@}\" --",
"test:jest": "jest",
"lint": "tslint app/**/*.ts{,x}"
},
答案 0 :(得分:0)
我希望在您尝试引用它和运行时之前完成转换。因此,请参考转译的结果-即.js
文件?