Node.js Electron:将二进制依赖项包含在Web包中
我试图在我的electron项目中使用Webpack将Typescript代码捆绑到我的主进程中(渲染器是一个使用CLI管理的角度项目) 但在我的主要过程中,我依赖于: 注册表js构建为Node.js Electron:将二进制依赖项包含在Web包中,node.js,typescript,webpack,binary,electron,Node.js,Typescript,Webpack,Binary,Electron,我试图在我的electron项目中使用Webpack将Typescript代码捆绑到我的主进程中(渲染器是一个使用CLI管理的角度项目) 但在我的主要过程中,我依赖于: 注册表js构建为.node二进制文件。所以我的问题是如何将其包含在我的包中?当前我的webpack.config.js如下所示: const path = require("path"); module.exports = { entry: "./main.ts", target: "electron-main",
.node二进制文件
。所以我的问题是如何将其包含在我的包中?当前我的webpack.config.js
如下所示:
const path = require("path");
module.exports = {
entry: "./main.ts",
target: "electron-main",
output: {
path: "./dist-main",
filename: "main.bundle.js",
},
mode: "production",
module: {
rules: [
{
test: /\.ts?$/,
use: "ts-loader",
exclude: /node_modules/,
}
],
},
resolve: {
extensions: [".ts", ".js"],
alias: {
"registry-js": path.join(__dirname, "node_modules/registry-js/build/Release/registry.node"),
}
}
};
当我启动应用程序时,我得到一个类型错误:无法读取未定义的属性“HKEY\U LOCAL\U MACHINE”
如何在我的Webpack构建中包含二进制文件,以便能够在开发模式下运行我的应用程序并作为生产构建?Webpack无法绑定本机插件模块。在创建包时,您应该使用适当的加载程序,如节点加载程序或节点加载项加载程序,并复制二进制文件。您能告诉我如何操作吗?我已经试过了,但没有理解如何使用节点加载器。
const path = require("path");
module.exports = {
entry: "./main.ts",
target: "electron-main",
output: {
path: "./dist-main",
filename: "main.bundle.js",
},
mode: "production",
module: {
rules: [
{
test: /\.ts?$/,
use: "ts-loader",
exclude: /node_modules/,
}
],
},
resolve: {
extensions: [".ts", ".js"],
alias: {
"registry-js": path.join(__dirname, "node_modules/registry-js/build/Release/registry.node"),
}
}
};