You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron应用打包后资源文件未添加问题求助

解决Electron打包后extraResources未出现在resources目录的问题
  • 先确认项目根目录下存在extraResources文件夹,且SumatraPDF-3.4.6-64.exe确实在该文件夹内。

  • 修改vue.config.js里的extraResources配置,把输出路径调整到resources目录:

pluginOptions: {
    electronBuilder: {
        extraResources: [
            {
                "from": "extraResources/SumatraPDF-3.4.6-64.exe",
                "to": "resources/SumatraPDF-3.4.6-64.exe"
            }
        ],
        win: {
            target: "portable"
        }
    }
}

如果需要批量添加extraResources下所有文件,可简化为:

pluginOptions: {
    electronBuilder: {
        extraResources: ["extraResources/**"],
        win: {
            target: "portable"
        }
    }
}
  • 在Electron主进程中用正确的路径逻辑调用exe,确保开发环境和打包后都能正常访问:
const { app } = require('electron');
const path = require('path');
const { execFile } = require('child_process');

// 根据打包状态获取资源路径
const resourcesBasePath = app.isPackaged 
    ? path.join(path.dirname(app.getPath('exe')), 'resources') 
    : path.join(__dirname, '../extraResources');

const pdfExePath = path.join(resourcesBasePath, 'SumatraPDF-3.4.6-64.exe');

// 运行exe文件
execFile(pdfExePath, (err, stdout, stderr) => {
    if (err) {
        console.error('运行exe出错:', err);
        return;
    }
    console.log('stdout:', stdout);
    console.error('stderr:', stderr);
});
  • 重新执行打包命令,生成portable包后检查resources目录,目标exe文件应该已存在。

内容的提问来源于stack exchange,提问作者N.Maxim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 10:35:20