NW.js (node-webkit) 和 Vue.js 需要系统信息模块的问题

NW.js (node-webkit) and Vue.js issue with require systeminformation module

我有一个项目将 NW.js 与 Vue.js 结合使用。问题是我不能包含 systeminformation module to the Vue.js because according to the documentation (see the core concept section) this lib doesn't work from inside the chromium 但只能在服务器端。 如何在 nw.js 中包含此库以使其在全球范围内可用,以便我可以在 vue 代码中使用它?

我一直在使用一种似乎有效的解决方案,但最近我发现它并非如此。我一直在做什么 - 我在 ./public/index.html 中包含了脚本,它适用于开发但不适用于构建。当我构建应用程序并将其移动到另一个地方时,它找不到 systeminformation 包的路径。

<!-- inside index.html -->

<script>
  const si = require("systeminformation");
</script>

知道如何克服这个问题吗?将不胜感激。谢谢。

这取决于您使用 Vue 的方式。如果你正在做一个简单的“CDN”风格,那么看看这个例子:

该 repo 中的自述文件将提供分步说明。

如果您使用的是 Vue-CLI 风格,那么这应该可行:

该存储库是 Vue-CLI 的完整样板 + NW.js