如何在Javascript中使用require函数
How to use require function inside a Javascript?
我试图在电子中导入Nodejs的fs,其中我试图使用require函数。
然而,我得到错误要求是没有定义的。如何解决这个问题?我们是否需要为electron和Nodejs的集成添加特殊的配置?我在我的index.html
文件中编写以下脚本:
function myFunction() {
var fs = require('fs')
}
关于require( 'fs' )
,我认为它只在主要过程中起作用。如果你尝试从渲染器进程,尝试使用需要使用remote
模块。
var remote = require( 'remote' );
var fs = remote.require( 'fs' );
在你的index.html中很早就写了
if (window.require) {
window.requireNode = window.require;
window.require = undefined;
}
,然后
<script src="js/lib/require.js"></script>
所以我可以写
window.requireNode("remote")
加载"节点电子"的东西在我的网页
和传统的
window.require("my/module")
加载模块
相关文章:
- 从require()'d文件访问函数
- 为什么我不能在 node.js(浏览器化)的 require() 函数中使用变量作为参数
- “require”关键字在节点红色函数节点中不起作用
- 在Require.js中,如果Require()是一个函数,那么Require.config()是如何存在的
- require.js+backbone.js:如何构造具有初始化函数的模块
- Durandal-Weyland优化没有't处理require函数
- Node.js,TypeError:xxx不是函数,在require'd文件
- 重写 require 函数
- 是否可以在客户端代码中使用 Require 函数
- Requirejs:等待模块内部的require函数
- Gruntfile.js带有“require”函数和传递参数
- 是否有嵌套require函数调用的原因
- 在node.js中使用require()函数的不同方式是什么?
- 如何在Javascript中使用require函数
- Jquery不返回通过PHP require()函数包含的元素
- JavaScript中的Require()函数
- 使用Sinon模拟require()'d函数
- 自定义RequireJS require()函数的用法
- 如何让数据文件夹中的页面访问require函数
- 给出ReferenceError: require的Javascript require()函数没有定义