Electron如何打包使其支持龙芯和方腾、兆芯平台的麒麟系统
<p>Electron如何打包使其支持龙芯和方腾、兆芯平台的<span class="wpcom_tag_link">麒麟系统</span></p><p>electron 支持在Windows平台打包成linux版本,但是编译成deb或者rpm需要在对应的平台上如,deb需要在银河麒麟上打包,rpm需要在中标麒麟上打包。</p>
<p>1、构建和编译在win10上开发和编译:我选择electron vue框架开发,集成electron-packager打包工具,自己又扩展了package.json electron vue框架自带的 electron v2.0.18。</p>
<pre class="wp-block-code"><code> "build:linux": "cross-env BUILD_TARGET=linux node .electron-vue/build.js",
"build:arm64": "cross-env BUILD_TARGET=linux arch=arm64 node .electron-vue/build.js",
"build:ky64": "cross-env BUILD_TARGET=linux arch=x64 node .electron-vue/build.js",
"build:mips": "cross-env BUILD_TARGET=linux arch=mips64el node .electron-vue/build.js",</code></pre>
<p>打包成Linux、arm、x64、amd64直接运行 npm run build 即可。兆芯对应x64、方腾对应Arm,龙芯对应mips,唯独mips electron官方支持到1.8版本,所以想要高版本需要自行编译或者到龙芯开源社区下载:http://www.loongnix.org/index.php/Electron</p>
<ul>
<li>打包成龙芯注意事项</li>
</ul>
<p>1、下载龙芯官方编译版本2、修改本地node库代码支持修改方法可以参考https://blog.csdn.net/isangmeng/article/details/113173549</p>
<p>2、编译操作步骤:</p>
<ol>
<li>1、下载对应龙芯编译版 Electron-v10.1.0 我下载的是 麒麟版electron_v10.1.0_kylin_v10.tar.gzhttp://ftp.loongnix.org/os/loongnix/1.0/electron/electron/electron-v10.1.0/</li>
</ol><ol>
<li>2、将下载的 electron_v10.1.0_kylin_v10.tar.gz 文件解压缩后压缩成zip文件,命名electron-v2.0.18-linux-mips64el.zip,然后复制到 C:\Users\Administrator\AppData\Local\electron\Cache 目录中 备用</li>
</ol><ol>
<li>3、修改本地库文件支持</li>
</ol>
<p>将node_modules\electron\install.js中</p>
<pre class="wp-block-code"><code>download({
cache: process.env.electron_config_cache,
version: version,
platform: process.env.npm_config_platform,
arch: process.env.npm_config_arch,
strictSSL: process.env.npm_config_strict_ssl === 'true',
force: process.env.force_no_cache === 'true',
quiet: process.env.npm_config_loglevel === 'silent' || process.env.CI,
mirror
}, extractFile)</code></pre>
<p>修改为</p>
<pre class="wp-block-code"><code>if(arch.indexOf('mips')>-1){
extractFile(0, 'electron-v2.0.18-linux-mips64el.zip');
}else{
// downloads if not cached
download({
cache: process.env.electron_config_cache,
version: version,
platform: process.env.npm_config_platform,
arch: process.env.npm_config_arch,
strictSSL: process.env.npm_config_strict_ssl === 'true',
force: process.env.force_no_cache === 'true',
quiet: process.env.npm_config_loglevel === 'silent' || process.env.CI,
mirror
}, extractFile)
}</code></pre>
<p>目的是用自行打包的zip来替代去官方下载,导致404错误修改node_modules/electron-packager/targets.js</p>
<pre class="wp-block-code"><code>const linuxArchBuildVersions = {
arm64: '>= 1.8.0',
mips64el: '^1.8.2-beta.5'
}</code></pre>
<p>改成</p>
<pre class="wp-block-code"><code>const linuxArchBuildVersions = {
arm64: '>= 1.8.0',
mips64el: '>=1.8.2-beta.5'
}</code></pre>
<p>目的是跳过版本比较限制</p>
<p>修改node_modules/electron-packager/node_modules/sumchecker/index.js</p>
<p>找到</p>
<pre class="wp-block-code"><code>validate (baseDir, filesToCheck) {
if (typeof filesToCheck === 'string') {
filesToCheck =
}
return this.readFile(this.checksumFilename, false)
.then(this.parseChecksumFile.bind(this))
.then(() => {
return this.validateFiles(baseDir, filesToCheck)
})
}</code></pre>
<p>改为:</p>
<pre class="wp-block-code"><code>validate (baseDir, filesToCheck) {
if (typeof filesToCheck === 'string') {
filesToCheck =
}
return this.readFile(this.checksumFilename, false)
.then(this.parseChecksumFile.bind(this))
.then(() => {
return new Promise((resolve, reject) => {
resolve()
});
//return this.validateFiles(baseDir, filesToCheck)
})
}</code></pre>
<p>目的是阻止验证SHASUM</p>
<p>那么接下来就可以直接运行 npm run build:mips</p>
<p>正常输出如下</p>
<pre class="wp-block-code"><code>$ npm run build:mips
> proclient@1.0.6 build:mips D:\Codes\kylinApp\ProClient
> cross-env BUILD_TARGET=linux arch=mips64el node .electron-vue/build.js
lets-build
√ building main process
√ building renderer process
Hash: 878d88ac655c5b098995
Version: webpack 4.42.0
Time: 1198ms
Built at: 2021/01/27 上午11:14:25
Asset SizeChunks Chunk Names
main.js2.14 KiB 0main
Entrypoint main = main.js
external "path" 42 bytes {0}
./src/main/index.js 2.24 KiB {0}
external "electron" 42 bytes {0}
external "fs" 42 bytes {0}
Hash: 74b85b3bed5fd09ee591
Version: webpack 4.42.0
Time: 13174ms
Built at: 2021/01/27 上午11:14:37
Asset SizeChunks Chunk Names
1.js 10.5 KiB 1, 3
10.js 1.41 KiB 10
11.js 8.5 KiB 11
12.js297 bytes 12
13.js252 bytes 13
2.js 6.66 KiB 2, 4
3.js 6.93 KiB 3
4.js 1.93 KiB 4
5.js 7.89 KiB 5
6.js 1.81 KiB 6
7.js 5.54 KiB 7
8.js 6.48 KiB 8
9.js 6.01 KiB 9
fonts/MaterialIcons-Regular--css.eot 140 KiB
fonts/MaterialIcons-Regular--css.ttf 125 KiB
fonts/MaterialIcons-Regular--css.woff 56.3 KiB
fonts/MaterialIcons-Regular--css.woff2 43.3 KiB
imgs/bg1--img.png 116 KiB
imgs/bg15--img.png 40.3 KiB
imgs/logo--assets.png 45.5 KiB
index.html782 bytes
renderer.js 483 KiB 0renderer
static/CryptoHelper.dll 8 KiB
static/JmrhDesWin.exe 22.5 KiB
static/iconfont.css 19.8 KiB
static/iconfont.svg 126 KiB
static/iconfont.ttf 24.8 KiB
static/img/0.png 28.7 KiB
static/img/00225131827.png 39 KiB
static/img/1.jpg 21.2 KiB
static/img/1.png 22.2 KiB
static/img/404.png 51 KiB
static/img/bg.jpg 236 KiB
static/img/bg1.png 116 KiB
static/img/bg15.png 40.3 KiB
static/img/dbg_1.png 233 KiB
static/img/dbg_2.png 3.03 KiB
static/img/in_top_bj.jpg 55.5 KiB
static/img/login/SignBG.jpg 3.52 KiB
static/img/login/Signin.jpg 6.93 KiB
static/img/login/logo.jpg 37.3 KiB
static/img/login/register.jpg 5.01 KiB
static/img/login/topbg.jpg 2.16 KiB
static/img/logo.png 45.5 KiB
static/img/nostar.png 9.4 KiB
static/img/star.png 1.33 KiB
static/img/type_0.jpg 24.8 KiB
static/img/type_1.jpg 43.2 KiB
static/img/type_2.jpg 26.9 KiB
static/img/type_3.png 101 KiB
static/img/type_4.jpg 52.7 KiB
static/img/user.jpg 2.04 KiB
static/index.css 5.1 KiB
static/lib/gz_address_v4.js 9.64 KiB
static/print.css 2.95 KiB
static/reset.css 2.62 KiB
static/reset.less 4.47 KiB
static/user/91520223587250761K/1600324392672.jpg 72.4 KiB
static/user/91520223587250761K/data.json 13.8 KiB
Entrypoint renderer = renderer.js
./src/renderer/common.js 5.13 KiB {0}
./node_modules/vue/dist/vue.esm.js 319 KiB {0}
./src/renderer/store/index.js + 3 modules 21.1 KiB {0}
| ./src/renderer/store/index.js 260 bytes
| ./src/renderer/store/modules/comm_store.js 17.4 KiB
| ./src/renderer/store/modules/db_store.js 330 bytes
| ./src/renderer/router/menu.js 2.99 KiB
./src/renderer/assets/db.js 3.12 KiB {0}
external "squel" 42 bytes {0}
./src/renderer/router/index.js 3.77 KiB {0}
external "axios" 42 bytes {0}
external "electron" 42 bytes {0}
external "vee-validate" 42 bytes {0}
./src/renderer/components/sidebar/loading.vue + 4 modules 1.39 KiB {0}
| ./src/renderer/components/sidebar/loading.vue 464 bytes
| ./src/renderer/components/sidebar/loading.vue?vue&type=template&id=6716256a& 217 bytes
| ./src/renderer/components/sidebar/loading.vue?vue&type=script&lang=js& 376 bytes
| ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/renderer/components/sidebar/loading.vue?vue&type=template&id=6716256a& 293 bytes
| ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/renderer/components/sidebar/loading.vue?vue&type=script&lang=js& 66 bytes
external "vue-i18n" 42 bytes {0}
external "muse-ui" 42 bytes {0}
./node_modules/vee-validate/dist/locale/zh_CN.js 2.73 KiB {0}
external "vue-simple-uploader" 42 bytes {0}
./src/renderer/main.js + 6 modules 10.9 KiB {0}
| ./src/renderer/main.js 2.17 KiB
| ./src/renderer/App.vue 446 bytes
| ./src/renderer/common/js/mixin.js 7.22 KiB
| ./src/renderer/App.vue?vue&type=template&id=2c2ecc9c& 201 bytes
| ./src/renderer/App.vue?vue&type=script&lang=js& 344 bytes
| ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./src/renderer/App.vue?vue&type=template&id=2c2ecc9c& 210 bytes
| ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./src/renderer/App.vue?vue&type=script&lang=js& 204 bytes
+ 244 hidden modules
Child html-webpack-plugin for "index.html":
Asset SizeChunksChunk Names
index.html534 KiB 0
Entrypoint undefined = index.html
./node_modules/html-webpack-plugin/lib/loader.js!./src/index.ejs 2.08 KiB {0}
./node_modules/lodash/lodash.js 528 KiB {0}
(webpack)/buildin/module.js 497 bytes {0}
OKAYtake it away `electron-packager`
WARNING: The callback-based version of packager() is deprecated and will be removed in a future major version, please convert to the Promise version or use the nodeify module.
Packaging app for platform linux mips64el using electron v2.0.18
DONE</code></pre>
<p>OK,electron编译完成</p>
<ul>
<li>银河麒麟对应的输出应该是 proclient-linux-arm64,中标麒麟龙芯平台应该是proclient-linux-mips64el,注意区分。</li>
</ul>
<p>3、打包接下来将编译好的 build\proclient-linux-arm64\ 文件夹ssh上传到对应的系统,这里使用银河麒麟操作,打包成deb文件。麒麟系统需具备nodejs环境、包含npm。首先运行</p>
<p>npm install -g electron-installer-debian</p>
<p>安装完成后,切换到proclient-linux-mips64el的上层文件夹,运行如下命令</p>
<p>electron-installer-debian –src proclient-linux-arm64/ –dest dist/installers/ –arch arm64</p>
<p>等待片刻就好,输出文件在 dist/installers 中。</p>
<p>中标麒麟平台使用的打包工具是</p>
<pre class="wp-block-code"><code>npm install -g electron-installer-redhat</code></pre>
<p>同时中标麒麟还要具备 rpm-build、rpm工具环境</p>
<p>如果你本身就是在麒麟系统上做开发,那就更方便了。</p>
<p>直接集成打包命令到package.json</p>
<pre class="wp-block-code"><code>"rpm64": "electron-installer-redhat --src dist/app-linux-x64/ --dest dist/installers/ --arch x86_64"</code></pre>
<pre class="wp-block-code"><code>"deb64": "electron-installer-debian --src dist/app-linux-x64/ --dest dist/installers/ --arch amd64"</code></pre>
<p>两个命令就完事了</p>
<p>npm run build:arm64</p>
<p>npm run deb64</p>
<p>附上打包库地址:</p>
<p>https://developer.aliyun.com/mirror/npm/package/electron-installer-debianhttps://developer.aliyun.com/mirror/npm/package/electron-installer-redhat</p><br><br>
来源:https://www.cnblogs.com/uyan/p/14590780.html
頁:
[1]