电子包装机和全球电子模块 [英] electron-packager and gloabl electron module

查看:65
本文介绍了电子包装机和全球电子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了电子和电子包装机,它们都处于全局模式。构建我的应用程序时,电子包装程序会搜索本地电子模块。

I have installed electron and electron-packager, all of them in global mode. When I build my app electron-packager searchs the local electron module. How forcing electron-packager to use the global electron module that I have installed?

推荐答案

简短的回答是,您所描述的是什么?如何迫使电子包装商使用已安装的全局电子模块?这不是您应该使用电子包装器的方式。通常,目的是要在要处理的项目目录下构建本地软件包(exe或类似文件)。例如,在Windows平台上构建的电子/角度项目可能具有以下类型的结构:

The short answer is that what you have described isn't the way you "should" use electron-packager. Normally, the intent is that you are building a local package (exe or such) under the project directory you are working on. For example, an electron/angular project building on a Windows platform might have the following kind of structure:

C:.
+---ClientSide
¦   +---index.html
¦   +---app
¦   ¦   +---app.component.ts
¦   ¦   +---app.module.ts
¦   ¦   +---main.ts
¦   ¦   +---AppContent/
¦   ¦   +---help/
¦   +---Styles
¦   +---test
¦       +---AppContent/
+---dist/
+---edist
|   \---Application-win32-ia32 [*location of binary source for the install]
+---Installer
    +---Application/
gulpfile.js
karma.conf.js
main.js
package.json
README.md
webpack.config.js

在这种情况下, package.json 文件通常包含对两个软件包的引用,如下所示:

In this kind of scenario, the package.json file typically contains reference to both packages, as in:

.. .. ..
  "devDependencies": {
    "@angular/animations": "4.4.4",
    "@angular/common": "4.4.4",
    "@angular/compiler": "4.4.4",
.. .. ..
.. .. ..
    "electron": "1.7.9",
    "electron-packager": "9.1.0",
.. .. ..

然后在本地 gulpfile.js 中包括一个运行包装程序的调用,该包装程序引用电子的本地版本。

Then within your local gulpfile.js you would typically include a call to run the packager that refers to the local version of electron. Something like:

'use strict';
...   ...
var packager = require('electron-packager');
var electronPackage = require('electron/package.json');
var pkg = require('./package.json');
// pull the electron version from the package.json file
var electronVersion = electronPackage.version;
...   ...

var opts = {
    name: pkg.name,
    platform: 'win32',
    arch: 'ia32',                           // ia32, x64 or all
    dir: './',                       // source location of app
    out: './edist/',              // destination location for app os/native binaries
    ignore: config.electronignore,          // don't include these directories in the electron app build
    icon: config.icon,
    asar: {unpackDir: config.electroncompiled}, // compress project/modules into an asar blob but don't use asar to pack the native compiled modules
    overwrite: true,
    prune: true,
    electronVersion: electronVersion ,       // Tell the packager what version of electron to build with
    appCopyright: pkg.copyright,            // copyright info
    appVersion: pkg.version,         // The version of the application we are building
    win32metadata: {                        // Windows Only config data
        CompanyName: pkg.authors,
        ProductName: pkg.name,
        FileDescription: pkg.description,
        OriginalFilename: pkg.name + '.exe'
    }
};


// Build the electron app
gulp.task('build:electron', function (cb) {

    console.log('Launching task to package binaries for ' + opts.name + ' v' + opts['appVersion']);

    packager(opts, function (err, appPath) {
        console.log(' <- packagerDone() ' + err + ' ' + appPath);
        console.log(' all done!');
        cb();
    });
});

如果您不想制造与本地电子相同的电子版本,则可以将该参数更改为您希望包装机使用的任何电子版本。如上所示,替换以下代码行:

If you don't want to build the same version of electron that as is present locally, you can change that parameter to whatever version of electron you'd like packager to use. As in, replacing this line of code:

// pull the electron version from the package.json file
var electronVersion = electronPackage.version;

使用类似这样的东西:

// Use a specific electron version
var electronVersion = '1.7.8';

如果要运行 electron-packager 在命令行中,您可以使用所有与我在API选项中显示的相同的选项。您可以在其在线github用户文档中查看选项的完整列表。在您的情况下,如果使用命令行,则使用 -electron-version 开关设置所需的电子版本。

If you are going to run electron-packager from the command line, you have all the same options available as I've shown here in the API options. You can see the full list of options in their online github user docs . In your case, if you are using command line then use the "--electron-version" switch to set the electron version you wish.

这篇关于电子包装机和全球电子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆