是否可以使JavaScript模块兼容NodeJS和RequireJS? [英] Is it possible to make JavaScript module compatible with both NodeJS and RequireJS?

查看:386
本文介绍了是否可以使JavaScript模块兼容NodeJS和RequireJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在调查各种模块概念如何在NodeJS和浏览器应用程序中应用NodeJS要求(显然在NodeJS应用程序中)和RequireJS用于Web浏览器环境。

I have been investigating how various module concepts can be applied within NodeJS and browser applications using the the NodeJS require (obviously in NodeJS apps) and RequireJS for the web browser environment.

然后我突然意识到某些模块可能对客户端和服务器应用程序都有用,因此可以重复使用。

It then dawned on me that some modules may be useful for use by both the client and server applications and thus could be reused.

如何开发模块如此他们是否兼容这两种环境?

How can modules be developed so that they are compatible with both of these environments?

一个是同步的,一个是异步的。我的第一个想法是利用异步语法,然后为NodeJS定义一个自定义模块,它只是同步调用异步回调。但是,如果没有首先使用NodeJS同步回调,RequireJS模拟器如何被包含到跨环境模块中?

One is synchronous and one asynchronous. My first thought was to utilise the asynchronous syntax and then to define a custom module for NodeJS which simply invokes the asynchronous callback, synchronously. But how would the RequireJS-emulator be included into the cross-environment module without first using the NodeJS synchronous callback?

推荐答案

看到这个发布:弥合Node.js和浏览器之间的模块差距

这篇关于是否可以使JavaScript模块兼容NodeJS和RequireJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆