【问题标题】:Electron write file when packaged打包时的电子写文件
【发布时间】:2019-09-17 23:13:12
【问题描述】:

在电子中,当应用程序被打包时,我如何使用电子打包器编写文件。

以下将创建和更新开发中的文件。但是一旦我使用 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"
  },

【问题讨论】:

    标签: electron electron-packager


    【解决方案1】:

    我还没有尝试过,但也许你可以使用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')
        }
      ])],
      // ...
    })
    

    【讨论】:

    • 谢谢。事实证明,如果我从打包过程中删除 `--asar`,文件就在那里。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 2019-01-07
    • 2020-09-03
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 2017-12-14
    相关资源
    最近更新 更多