美文网首页我爱编程
ngx proj 在 Electron、nw.js 与 Brow

ngx proj 在 Electron、nw.js 与 Brow

作者: 环零弦 | 来源:发表于2018-04-11 11:35 被阅读0次

    一直以来都是在 WebStorm 中编程,然后直接 build 成目标,然后 Electron 直接打开目标目录。当在项目中需要引入自己编写的 js 文件时,可以直接使用 Electron相应的模块引入即可,如下:

    this.randylib = window.require('electron').remote.require('./randy-assets/librandy');
    

    当然也可以使用 Electronipc 倒腾一下。
    但是众所周知, Electronnw.js 思维是不一样的,如何在 nw.js 中引入自己编写的 js 包是问题的难点。
    所以,步骤如下:

    1. rebuild ref 和 ffi 模块

    Into ffi and ref directory and

    .../node_modules/ffi$ nw-gyp rebuild -target=0.14.7 -arch=64
    .../node_modules/ref$ nw-gyp rebuild -target=0.14.7 -arch=64
    

    2. .angular-cli.json 文件中加入外引 js 文件的声明

    Like this:

    "scripts": [
      "randy-assets/librandy4nw.js"
    ]
    

    3. 在文件中声明引入的函数,使用即可

    declare var execSQLQuery: any
    

    4. 要注意

    之前在 Electron 中,ffi 加载动态链接库的路径是:

    `${__dirname}`
    

    但是 __dirname 变量并不能在 nwjs 中被识别,所以改为:

    process.cwd() + '/randy-assets';
    

    这种方式。

    参考资料

    相关文章

      网友评论

        本文标题:ngx proj 在 Electron、nw.js 与 Brow

        本文链接:https://www.haomeiwen.com/subject/kllahftx.html