小编cai*_*dme的帖子

我如何使用fs与电子反应?

我想使用react + webpack + electron来构建一个桌面应用程序.如何将fs模块注入反应,以便我可以使用它来读取本机文件?我有一个组件,如:

class Some extends Component {
  render() {
    return <div>{this.props.content}</div>
  }
}
export default Some;
Run Code Online (Sandbox Code Playgroud)

entry.js:

import React from 'react';
import { render } from 'react-dom';
import Some from './src/some.jsx';

const data = "some content";
/*
 How can I read data by fs module?
 import fs from 'fs' doesn't work here
*/
render(
  <Some content={data} />,
  document.getElementById('app')
);
Run Code Online (Sandbox Code Playgroud)

我使用webpack将js代码构建到bundle.js和index.html中

...
<div id="app"></div>
<script src="bundle.js"></script>
...
Run Code Online (Sandbox Code Playgroud)

webpack.config.js:

...
plugins: [new webpack.IgnorePlugin(new …
Run Code Online (Sandbox Code Playgroud)

reactjs webpack electron

13
推荐指数
2
解决办法
1万
查看次数

Nan构建错误

我正在关注这个例子,但文档不起作用.

我的binding.gyp:

{
  "targets":[
    {
      "target_name": "hello",
      "sources": ["hello.cpp"],
      "include_dirs": [
        "<!(node -e \"require('nan')\")"
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

和我的hello.cpp:

#include <nan.h>

using namespace v8;

NAN_METHOD(Method) {
    NanScope();
    NanReturenValue(String::New("world"));
}

void Init(Handle<Object> exports) {
    exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction());
}

NODE_MODULE(hello, Init)
Run Code Online (Sandbox Code Playgroud)

它没关系node-gyp configure,但是什么node-gyp build时候报告错误:

../hello.cpp:10:9: error: use of undeclared identifier 'NanScope'
    NanScope();
    ^
../hello.cpp:11:33: error: no member named 'New' in 'v8::String'
    NanReturenValue(String::New("world"));
                    ~~~~~~~~^
../hello.cpp:15:18: error: use of undeclared identifier 'NanSymbol'
exports->Set(NanSymbol("hello"), FunctionTemplate::New(Method)->GetFunction());
             ^
../hello.cpp:15:60: error: cannot initialize …
Run Code Online (Sandbox Code Playgroud)

nan node-gyp

10
推荐指数
1
解决办法
801
查看次数

为什么硬盘上的顺序写入比随机写入快

就像在文件尾部附加日志条目,或者就像mysql记录其重做日志一样,人们总是说顺序写入比随机写入快得多。但为什么?我的意思是,当您在磁盘上写入数据时,寻道时间和旋转时间决定性能。但是在两次连续的顺序写入之间,可能还有很多其他写入请求(例如 nginx 记录 access.log)。这些写入请求可能会将磁头移动到其他磁道,当您的进程进行顺序写入时,它需要再次将磁头移回原处,并产生旋转时间。即使没有其他过程时,磁头可以静止不动,但也需要等待旋转。那么,顺序写入优于随机写入是否真的只是因为在许多情况下顺序写入不包含寻道时间,而随机写入总是包含寻道时间,但顺序写入和随机写入都包含旋转时间?

database filesystems storage disk

3
推荐指数
1
解决办法
2058
查看次数

标签 统计

database ×1

disk ×1

electron ×1

filesystems ×1

nan ×1

node-gyp ×1

reactjs ×1

storage ×1

webpack ×1