electron - 打包时的电子写入文件
问题描述
在电子中,使用电子打包器打包应用程序时如何编写文件。
以下将创建和更新开发中的文件。但是一旦我使用 electron-packager 打包应用程序,将不再创建该文件。我需要改变什么?
// imports
const path = require('path');
const fs = require('fs');
// create stream for appending to the log file
stream = fs.createWriteStream(
path.join(__dirname, 'logfile.log'),
{
flags:'a'
}
);
// append content to the log file
stream.write('test');
我是这样打包的:
"scripts": {
"start": "electron .",
"pack:win64": "electron-packager . my-app --out=dist/win64 --platform=win32 --arch=x64 --icon=assets/icon.png --prune=true --overwrite --asar"
},
解决方案
我还没有尝试过,但也许你可以使用afterCopy钩子来调用你需要的函数?
复制后
函数数组
将您的应用程序目录复制到临时目录后要调用的函数数组。每个函数都使用五个参数调用:
buildPath (String): The path to the temporary folder where your app has been copied to electronVersion (String): The version of electron you are packaging for platform (String): The target platform you are packaging for arch (String): The target architecture you are packaging for callback (Function): Must be called once you have completed your actions
const packager = require('electron-packager')
const { serialHooks } = require('electron-packager/hooks')
packager({
// ...
afterCopy: [serialHooks([
(buildPath, electronVersion, platform, arch) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('first function')
resolve()
}, 1000)
})
},
(buildPath, electronVersion, platform, arch) => {
console.log('second function')
}
])],
// ...
})
推荐阅读
- python - 对分组数据中的值进行排名
- node.js - 回调函数在 async.foreachlimit 上的 watefall 中未按预期工作
- intellij-idea - JetBrains IDE - 跳出括号/跳到表达式末尾的快捷方式
- space-complexity - 空间复杂性 - 删除非主导项
- python - 将 Qpixmap 从一个窗口发送到另一个窗口
- java - application.yml 和 @value
- crystal-lang - 如何在 Crystal 中解析 JSON 中的 Int 和 Float?
- java - 如何在硒中的chrome浏览器模式(身份验证器)上单击允许/阻止?
- node.js - dApp : Web3.eth.getCoinbase(function(err, account) 没有从 metamask 显示我连接的 rinkeby 帐户
- image - 如何在python和sagMaker中将字节数组编码为recordIO protobuf格式