Ionic 3 - 使用电子的 'child_process'

Ionic 3 - use electron's 'child_process'

我正在构建一个桌面应用程序,我想在其中从我的应用程序打开外部应用程序。我正在使用电子的 child_process 来执行此操作。但是我被困在如何在 TypeScript 文件上导入 child_process

我尝试使用 require('child_process').execSystem.import('child_process').exec 但它抛出错误“找不到模块 'child_process'。

但是当我在 <script> 中的 index.html 上使用它时,它工作正常!

我找到了这个解决方案 。但它正在与 SystemJS 一起工作。但是我的项目没有配置SystemJS。

如有任何帮助,我们将不胜感激。提前致谢!

我得到了解决方案。

需要在webpack.config.js中添加以下数组。

 externals: [
(function () {
    var IGNORES = ["fs","child_process","electron","path","assert","cluster","crypto","dns","domain","events","http","https","net","os","process","punycode","querystring","readline","repl","stream","string_decoder","tls","tty","dgram","url","util","v8","vm","zlib"];
    return function (context, request, callback) {
        if (IGNORES.indexOf(request) >= 0) {
            return callback(null, "require('" + request + "')");
        }
        return callback();
    };
})()
],

这将告诉 ionic 忽略数组 IGNORES 中列出的模块。