标签: wirejs

使用PhantomJS运行RequireJS/WireJS应用程序

我正在尝试执行一个使用RequireJS(2.1.8),WireJS(0.10.2)和PhantomJS(1.9.2)的基本应用程序:

  • 使用PhantomJS运行应用程序时(这是我的目标),WireJS无法加载(请参阅下面的错误).
  • 使用Chrome运行应用时,它会正常完成.

请帮助指出WireJS在PhantomJS下正常运行的缺失部分.

以下是我的app文件.

1)app.html

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>SaphirJS.core</title>
<script data-main="app" src="../../../target/deps/require-0.0.1/2.1.8/require.js">  </script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

2)app.js

"use strict";

require.config({
    baseUrl: ".",

    packages: [
        { name: 'wire', location: '../../../target/deps/wire-0.0.1/0.10.2', main: 'wire' },
        { name: 'when', location: '../../../target/deps/when-0.0.1/2.4.1', main: 'when' },
        { name: 'meld', location: '../../../target/deps/meld-0.0.1/1.3.0', main: 'meld' }
    ]
});

require(["wire!wireContext"], function(wireContext) {
    alert(wireContext.message);
});
Run Code Online (Sandbox Code Playgroud)

3)wireContext.js

define({
    message: "Hello World!"
});
Run Code Online (Sandbox Code Playgroud)

4)phantom-runner.js

(function() {
    'use strict';

    var args = require('system').args,
        timeoutRef = undefined,
        timeLimit …
Run Code Online (Sandbox Code Playgroud)

requirejs phantomjs wirejs

4
推荐指数
1
解决办法
2156
查看次数

node.js中wire.js的示例

我是Node的新手,来自C#背景,我希望通过Node找出依赖注入的主要内容之一.我知道wire.js具有这种能力,我已经阅读了我能在其上找到的所有内容,我甚至已经下载了Html"Hello World"示例.但是,我仍然无法让它正常工作.

以下是我尝试让它发挥作用的方法:

  1. 我将hello-wired.js和hello-wired-spec.js文件拖到我的Node项目中.
  2. 我将/ js/wire中的wire文件夹从示例应用程序中拉到我的Node应用程序中的/ node-modules/wire.
  3. 我在构造函数中删除了hello-world.js中的代码行,因为我没有Html节点,并且我使构造函数无参数.然后我将sayHello中的行替换为使用console.log(),因为我没有InnerHtml.
  4. 我创建了一个测试操作


app.get('/testwired', function (req, res) {
    require('wire!hello-wired-spec', function (spec) {
        console.log(spec);
        res.send(spec.sayHello("this is a test"));
    });
});
Run Code Online (Sandbox Code Playgroud)


我得到的错误是它无法找到模块线!hello-wired-spec.我认为这意味着我没有配置wire.js知道从哪里获取我的规范,但我无法弄清楚如何.我也不知道我是否应该使用回调.

任何帮助是极大的赞赏.

node.js wirejs

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

使用requirejs预加载polyfill库

我正在创建一个wirejs应用程序requirejs.对于IE 8,我使用polyfills:cujo/polyjs库并要求在加载之前预先加载此lib wirejs.

如果我用作curlAMD加载器,根据文档,我有以下选项:

curl({ preloads: [ "poly" ] });
Run Code Online (Sandbox Code Playgroud)

对我有用的是:

// in index.html

<script data-main="js/app" src="js/lib/require.js"></script>

// in js/app.js

define(function(){
   // set configuration options
   requirejs.config({// set config with paths});

   // require the library and HOPE it will load before
   // everything else!
   require(['poly']);

});
Run Code Online (Sandbox Code Playgroud)

本文档建议使用shimconfig来实现此目的.但是,我还没弄清楚如何.我试过的一些事情:

// DID NOT WORK!!
requirejs.config({

....
"shim": {
   "poly": {
     "exports": "poly"
    }
 }
});
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来解决这个问题?

任何帮助表示赞赏!...感谢您的时间!

requirejs polyfills wirejs

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

标签 统计

wirejs ×3

requirejs ×2

node.js ×1

phantomjs ×1

polyfills ×1