Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows上无法使用golang编写node native addon给electron干活 #1

Open
JustReactY opened this issue Jan 4, 2023 · 3 comments

Comments

@JustReactY
Copy link

今天看到了这个文章
请问是否遇到了这个问题?现在支持Windows是么?
https://www.jianshu.com/p/2bb52d13d734

@OctoberCity
Copy link

今天看到这篇文章 请问是否遇到了这个问题?现在支持Windows是什么? https://www.jianshu.com/p/2bb52d13d734

你解决了吗?

@wenlng
Copy link
Owner

wenlng commented Jul 21, 2024

今天看到了这个文章 请问是否遇到了这个问题?现在支持Windows是么? https://www.jianshu.com/p/2bb52d13d734

gonacli 是有处理的

@KeepRepeatLoop
Copy link

KeepRepeatLoop commented Sep 1, 2024

我尝试了一下,我这里使用的是Vue CLI Plugin Electron Builder。在使用gonacli make和在output目录下执行npm run build:release以后,会在build\Release\会产生*.node文件。所需要的两个文件分别是生成目录根目录中的动态链接库文件(Windows下为.dll,Linux应该是.so)以及*.node文件。只需要这两个文件,将文件复制到vue-electron-build项目的src目录中随后需要设置vue.config.js的webpack配置。

const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: true,
      preload: 'src/preload.js',
      chainWebpackMainProcess(config) {
        config.module
          .rule("node")
          .test(/\.node$/)
          .use("native-ext-loader")
          .loader("native-ext-loader")
      },
      chainWebpackRendererProcess: (config) => {
        config.module
        .rule("node")
        .test(/\.node$/)
        .use("native-ext-loader")
        .loader("native-ext-loader")
        .options({rewritePath:"src"})
      },
    }
  },
  lintOnSave: false  // 添加此行来禁用 ESLint 检查
})

然后在background.js中直接可以使用:

const addon = require("./**.node")

问题不大主要是需要webpack的一个node文件loader,踩坑时间都在这儿了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants