2017-10-12 105 views
1

鉴于电子应用程序。该文件夹结构看起来是这样的:电子构建Windows文件夹结构

App 
    - assets 
    -models 
     - exe files 
index.html 
main.js 

在执行编译后的网站通过输入以下命令的建议:

electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName="Electron Tutorial App" 

电子v.1.7.9正确地创建构建,但是它位于release-builds/resources文件夹中的app.asar文件中,因此模型文件夹内的所有内容都变得无法访问。在这个文件夹里面有应该​​按需运行的.exe文件。

然后,系统在以下URL中查找文件:parth_do_projeto/resources/app.asar/assets/models /,即它认为app.assar是一个文件夹,但在app.asar构建之后是一个文件。

由于原始文件夹中存在.exe文件,因此app.asar无法吸收可执行文件。

保持这些.exe文件的方式是什么?如果您构建的版本不带--asar参数,程序将正常工作,请输入,我的所有项目文件夹/源代码都已公开。

我的问题是生成构建,保持代码关闭并使用.exe文件的最佳方式是什么?

回答

0

您的问题的简短答案是使用unpackDir选项作为电子包装程序中的asar选项。这里是一个这样的样子:

'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.excludeFromASAR}, // compress project/modules into an asar blob excluding some things. 
    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(); 
    }); 
});