How to add folders and files to electron build using electron-builder

前端 未结 3 732
悲哀的现实
悲哀的现实 2021-01-02 12:49

I am creating an electron which running react generated from create-react-app. Then i add nedbjs(a persistence database) and camojs(ODM for nedb) as dependency. To connect r

3条回答
  •  旧时难觅i
    2021-01-02 13:30

    Was running into issues with this as well, and found the files property to be the solution. This particular example copies a directory from my node_modules into the final build directory.

    i.e. on Windows, it copies the files to: yourapp.exe/$PLUGINSDIR/app-64.7z/resources/app/

    builder.config.js

    module.exports = {
      productName: "myapp",
      appId: "com.reflex.app",
      directories: {
        output: "build",
      },
      files: [
        "package.json",
        {
          // SOLUTION
          from: "yourdirectoryorfilenamehere",
          to: "yourdirectoryorfilenamehere",
          filter: ["**/*"], // This will recursively include all sub-directories & files
        },
      ],
      // ... other configuration here ...
    };
    
    

    And then you can access the final files via a script in src/renderer/ or src/main

    import { app } from "electron"; // For main process
    
    /* 
    Or use this instead for the renderer process: 
    import { remote } from 'electron' // For renderer process
    const { app } = remote
    */
    
    const path = require("path");
    const yourdirectoryorfilenamehere = path.join(app.getAppPath(), "/yourdirectoryorfilenamehere");
    console.log(yourdirectoryorfilenamehere) // When built, this will show the path to where all your resources from (`files: []`) were saved 
    

提交回复
热议问题