我使用 Electron-vite 命令
pnpm create @quick-start/electron
初始化项目
然后我在
getAuthKey.js
旁边的
src/main/
中创建一个js文件
index.js
最后我需要
getAuthKey.js
在src/main/index.js
,像这样:
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
}
const getAuthKey = require("../../src/main/getAuthKey");
out/main/index.js
而不是预编译。src/main/index.js
,我该怎么办?我想要求我的js文件到
src
目录而不是out
目录
export function getAuthKey() {}
import { getAuthKey } from './getAuthKey'
不是这样的
module.exports = { getAuthKey };
const {getAuthKey} = require('./getAuthKey');