Accessing filesystem in Angular 2 app using Electron

前端 未结 5 1290
抹茶落季
抹茶落季 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:32

    As I understand it, you build the application with Webpack.

    You can expose all Node modules via the externals array in your webpack config.

    module.exports = {
       "externals": {
          "electron": "require('electron')",
          "child_process": "require('child_process')",
          "fs": "require('fs')",
          "path": "require('path')",
          ...
       }
    }
    

    Since they are provided through the Webpack externals, one does not have to require them but use them with imports.

    import * as fs from 'fs'
    

    You can read more about this problem in my article.

提交回复
热议问题