我正在尝试在我的 Electron 项目中使用 Webpack 将 Typescript 代码捆绑到我的主进程中(渲染器是一个使用 CLI 管理的 Angular 项目)。
但是在我的主进程中我依赖 registry-js :
import { enumerateValues, HKEY } from "registry-js";
Registry-js 构建为 .node-binary
。所以我的问题是如何将其包含在我的 bundle 中?目前我的 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"),
}
}
};
当我启动应用程序时,出现TypeError: Cannot read property 'HKEY_LOCAL_MACHINE' of undefined
我可以做什么来将二进制文件包含在我的 Webpack 构建中,以便能够在开发模式和生产构建中运行我的应用程序?
最佳答案
Webpack 无法捆绑 native 插件模块。您应该使用适当的加载器,例如node-loader或node-addon-loader,并在创建包时复制二进制文件。
关于node.js - Electron:包含 Webpack 的二进制依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57659522/