如何在 Electron.AtomWebPack 应用程序中使用 FS 模块?

How to use FS module inside Electron.AtomWebPack application?(如何在 Electron.AtomWebPack 应用程序中使用 FS 模块?)
本文介绍了如何在 Electron.AtomWebPack 应用程序中使用 FS 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我需要在文件中写入一些数据,使用 FS 模块 (fs.writeFile).我的堆栈是 webpack + react + redux + electron.

I need write some data in the file, using FS module (fs.writeFile). My stack is webpack + react + redux + electron.

第一个问题是:无法解析模块fs".我尝试使用

The first problem was: Cannot resolve module 'fs'. I tried to use

target: "node",
---
node: {
    global: true,
    fs: "empty",
}
---
resolve: {
    root: path.join(__dirname),
    fallback: path.join(__dirname, 'node_modules'),
    modulesDirectories: ['node_modules'],
    extensions: ['', '.json', '.js', '.jsx', '.scss', '.png', '.jpg', '.jpeg', '.gif']
},

经过多次尝试,问题得到解决(node: {fs: "empty"}).但随后出现了第二个问题:截图.

After several attempts, the problem is resolved ( node: {fs: "empty"} ). But then there was a second problem: screenshot.

//In method componentDidMount (React)
console.log('fs', fs);
console.log('typeOf', typeof fs.writeFile);

//By clicking on the button
console.log(fs);
console.log(typeof fs.writeFile);

可以看到,fs是空对象,不存在writeFile方法.我试图改变 webpack 的配置.

You can see, that fs is empty object, and method writeFile no exists. I tried to change the webpack's configuration.

const path = require('path');
const fs = require('fs');
const webpack = require("webpack");
console.log(fs);

在这种情况下 fs 不为空.

In this case fs is not empty.

如何解决这个问题?有什么想法吗?

How to solve this problem? Any ideas?

推荐答案

问题解决了.

需要在电子应用程序中使用(添加捆绑包的地方):

Need use in electron app (where you add the bundle):

var remote = require('electron').remote;
var electronFs = remote.require('fs');
var electronDialog = remote.dialog;

这篇关于如何在 Electron.AtomWebPack 应用程序中使用 FS 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)