【问题标题】:Electron packaged for win32 does not work为win32打包的电子不起作用
【发布时间】:2016-06-07 09:46:24
【问题描述】:

我一直在使用 Electron 和 AngularJS 并构建了一个简单的应用程序。 如果我用电子运行它,它会按预期工作。 使用 electron-packager 将应用程序打包成 win32 可执行文件后,它不再工作了。 (打开白色窗口就可以了)。

打包时有没有看到一些调试? 我不知道出了什么问题,我唯一可能做的“错误”就是包含一些外部 CDN 库。这在 Electron 中是否允许,还是我必须使用 node 安装所有东西?

【问题讨论】:

  • 我认为在 Electron 中使用 CDN 不是一个好主意,您的应用最终会花费更长的时间来启动并且无法离线工作。但是,这应该仍然有效,打开 DevTools 并查看(this question 可能是相关的)。
  • 谢谢。我有一些错误,包括一些在项目之外具有绝对路径的库。 CDN 不是问题。

标签: electron


【解决方案1】:

要在 Electron 中进行有效调试,您必须在应用程序的 main.js 文件中打开浏览器嵌入式开发工具,然后在 Electron 启动后访问它们。例如,下面是一些代码,它将加载您的应用程序并打开带有子菜单的菜单,该子菜单启动 Chrome 的开发人员工具(或通过此处定义为 Windows 的 Ctrl-Shift-I 快捷方式)。

app.on('ready', function () {
    'use strict';

    var path = require('path');
    var iconPath = path.resolve(__dirname, './dist/app.ico');
    const appIcon = new Tray(iconPath);
    mainWindow = new Window({
        width: 1280,
        height: 1024,
        autoHideMenuBar: false,
        useContentSize: true,
        resizable: true,
        icon: iconPath
        //  'node-integration': false // otherwise various client-side things may break
    });
    appIcon.setToolTip('My App');
    mainWindow.loadURL('http://localhost:3000/');

    var template = [
        {
            label: 'View',
            submenu: [
                {
                    label: 'Toggle Developer Tools',
                    accelerator: (function() {
                        if (process.platform === 'darwin') {
                            return 'Alt+Command+I';
                        } else {
                            return 'Ctrl+Shift+I';
                        }
                    })(),
                    click: function(item, focusedWindow) {
                        if (focusedWindow) {
                            focusedWindow.toggleDevTools();
                        }
                    }
                },
            ]
        }
    ];


    var menu = Menu.buildFromTemplate(template);
    Menu.setApplicationMenu(menu);

    mainWindow.focus();

});

【讨论】:

    猜你喜欢
    • 2019-03-26
    • 2020-08-02
    • 2017-07-26
    • 1970-01-01
    • 2017-07-04
    • 2019-12-17
    • 2019-01-17
    • 2019-11-20
    • 2021-11-18
    相关资源
    最近更新 更多