Electron 电子封装时写入文件
在electron中,当使用electron packager打包应用程序时,如何编写文件。 以下内容将创建并更新正在开发的文件。但一旦我使用electron packager打包应用程序,文件将不再被创建。我需要改变什么Electron 电子封装时写入文件,electron,electron-packager,Electron,Electron Packager,在electron中,当使用electron packager打包应用程序时,如何编写文件。 以下内容将创建并更新正在开发的文件。但一旦我使用electron packager打包应用程序,文件将不再被创建。我需要改变什么 //导入 const path=require('path'); 常数fs=要求('fs'); //创建用于附加到日志文件的流 stream=fs.createWriteStream( join(uu dirname,'logfile.log'), { 旗帜:'a' } );
//导入
const path=require('path');
常数fs=要求('fs');
//创建用于附加到日志文件的流
stream=fs.createWriteStream(
join(uu dirname,'logfile.log'),
{
旗帜:'a'
}
);
//将内容附加到日志文件
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"
},
我还没有尝试过这个,但是也许你可以使用钩子来调用你需要的函数 后拷贝 函数数组 创建应用程序目录后要调用的函数数组 已复制到临时目录。每个函数用五个参数调用 参数:
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
谢谢事实证明,如果我从打包过程中删除“--asar”,文件就在那里。
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')
}
])],
// ...
})