2017-05-28 55 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」開關來設置你想要的電子版本。