Accessing filesystem in Angular 2 app using Electron

前端 未结 5 1283
抹茶落季
抹茶落季 2021-01-02 11:00

I know that Angular 2 is run on a web browser, which does not have access to the file system.

However, I\'m using Electron as my front-end, and also running the app

5条回答
  •  星月不相逢
    2021-01-02 11:23

    Solved it by:

    1) Eject webpack: ng eject

    2) Add target: 'electron-renderer' to the module.exports array inside webpack.config.js

    3) Require remote, since we're in the renderer, but fs is only available in the main process (Read more): var remote = require('electron').remote;

    4) Require fs (this time using remotes implementation of require): var fs = remote.require('fs');

    And now it works!

提交回复
热议问题