2017-05-28 54 views
2

我已经安装了电子和电子包装机,它们都是全球模式。当我建立我的应用程序电子包装商搜索本地电子模块。如何迫使电子包装商使用我安装的全球电子模块?电子包装机和gloabl电子模块

回答

1

简短的回答是,你所描述的不是你“应该”使用电子包装器的方式。通常情况下,您的目的是在您正在处理的项目目录下创建本地软件包(exe或其他)。例如,在Windows平台上的电子/角项目建设可能具有以下一种结构:

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文件通常包含参照上述两个包,如:

.. .. .. 
    "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中,您通常会包含一个调用来运行指向本地电子版本的打包程序。喜欢的东西:

'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(); 
    }); 
}); 

如果你不想打造电子,由于是本地存在,您可以更改参数,你想打包使用任何电子版本的版本相同。如,更换这行代码:

// 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选项中显示。您可以看到选项in their online github user docs的完整列表。在你的情况下,如果你正在使用命令行,那么使用“--electron-version”开关来设置你想要的电子版本。