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