electronelectron-builder

how to import my js file to the main/index.js pre-compilation , not after compilation?


import { app, BrowserWindow, ipcMain, shell } from "electron";
import { join } from "path";
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
import icon from '../../resources/icon.png?asset'

const getAuthKey = require("./getAuthKey");            <--------------here
const { execSync } = require("child_process");
const iconv = require("iconv-lite");
App threw an error during load
Error: Cannot find module './getAuthKey.js'
{
  "name": "xxx",
  "version": "1.0.0",
  "description": "An Electron application with Vue",
  "main": "./out/main/index.js",                        <----------------here
  
  
  
}

i want to require my js file to src directory not out directory


Solution

  • export function getAuthKey() {}
    
    import { getAuthKey } from './getAuthKey'
    

    not like this

    module.exports = { getAuthKey };
    
    const {getAuthKey} = require('./getAuthKey');