最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Electron modify file store in .asar - Stack Overflow

programmeradmin6浏览0评论

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.

I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?

I see the extraResources option but I did not understand how its work.

It's also important that the config file stay in myapp/config folder.

Thanks for your help :)

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.

I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?

I see the extraResources option but I did not understand how its work.

It's also important that the config file stay in myapp/config folder.

Thanks for your help :)

Share Improve this question asked Jun 11, 2018 at 15:08 SynoSyno 411 silver badge6 bronze badges 1
  • I am also having similar issue. I want a file to be editable. Were you able to find solution to your problem? – vaasu varma Commented Nov 11, 2020 at 13:04
Add a ment  | 

5 Answers 5

Reset to default 2

What build tool do you use? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here

I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.

fs.chmod(filename, 0666, (error) => {
        console.log('Changed file permissions');
    });

   ...
    code to modify file
   ...

asar is in readonly

as you mentioned asar intended to be readonly package. For runtime-changing config, you should place it outside of asar and change values accordingly.

To manage settings you should use a node package that's specifically designed for this, like electron-settings or preferences.

As an alternative one may manually read an write config files that you place in the platform's native config directory.


Mutable application settings shouldn't be stored in the asar file. If it's required to replace a file in an asar archive for any other reason, use the the asar program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.

  • To unpack .asar files -> asar extract electron.asar app

  • modify as per your needs

  • To pack .asar files -> asar pack . electron.asar

发布评论

评论列表(0)

  1. 暂无评论