gpt4 book ai didi

meteor - 如何在 meteor 应用程序中使用 famo.us CDN 链接?

转载 作者:行者123 更新时间:2023-12-01 12:41:46 25 4
gpt4 key购买 nike

随着 famo.us 的发布,它拥有作为 CDN 托管库的所有库。我如何在 meteor 应用程序中使用它们?

我在 famo.us 代码中遇到了很多关于“定义”的问题...

我所做的是创建一个新的 meteor 应用程序,然后从 famo.us 样板文件中获取 html 并将其放入客户端文件夹中,看起来像

<head>  
<title>famo.us App</title>
<meta name="viewport" content="width=device-width, maximum-scale=1, user-scalable=no" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<!-- shims for backwards compatibility -->
<script type="text/javascript" src="http://code.famo.us/lib/functionPrototypeBind.js"></script>
<script type="text/javascript" src="http://code.famo.us/lib/classList.js"></script>
<script type="text/javascript" src="http://code.famo.us/lib/requestAnimationFrame.js"></script>

<!-- module loader -->
<script type="text/javascript" src="http://code.famo.us/lib/require.js"></script>

<!-- famous -->
<link rel="stylesheet" type="text/css" href="http://code.famo.us/famous/0.2/famous.css" />
<script type="text/javascript" src="http://code.famo.us/famous/0.2/famous.min.js"></script>

<!-- app code -->
<link rel="stylesheet" type="text/css" href="css/app.css" />
<script type="text/javascript">
require.config({'localhost:3000': 'public/'});
require(['main']);
</script>

</head>

<body>
</body>

然后我将样板的 src 文件夹中的 main.js 放入 meteor 的 client/compatibility 文件夹中。但它并没有真正起作用。回来了

Uncaught ReferenceError: define is not defined 

来自 main.js

和 main.js 看起来像

define(function(require, exports, module) {
// import dependencies
var Engine = require('famous/core/Engine');
var Modifier = require('famous/core/Modifier');
var Transform = require('famous/core/Transform');
var ImageSurface = require('famous/surfaces/ImageSurface');

// create the main context
var mainContext = Engine.createContext();

// your app here
var logo = new ImageSurface({
size: [200, 200],
content: 'http://code.famo.us/assets/famous_logo.svg',
classes: ['double-sided']
});

var initialTime = Date.now();
var centerSpinModifier = new Modifier({
origin: [0.5, 0.5],
transform : function(){
return Transform.rotateY(.002 * (Date.now() - initialTime));
}
});

mainContext.add(centerSpinModifier).add(logo);
});

从源代码来看,这似乎是因为 meteor 在加载 famo.us 之前编译了 main.js 并包含在内。

最佳答案

您是否尝试过直接在脚本标签中加载 main.js 而不是使用脚本标签“要求”它。我正在做类似的事情,我将 main.js 代码直接注入(inject)到 html 中,但这里是一个例子,我将它拆分出来并且它有效(虽然我没有使用 meteor 。)

很明显,我也对代码做了一些改动,没有使用 define,但这个改动是直接的。这是html和js ...HTML:

<html>
<head>
<title>Debug Output</title>
<meta name='viewport' content='width=device-width, maximum-scale=1, user-scalable=no' />
<meta name='mobile-web-app-capable' content='yes' />
<meta name='apple-mobile-web-app-capable' content='yes' />
<meta name='apple-mobile-web-app-status-bar-style' content='black' />
<script type='text/javascript' src='http://code.famo.us/lib/functionPrototypeBind.js'></script>
<script type='text/javascript' src='http://code.famo.us/lib/classList.js'></script>
<script type='text/javascript' src='http://code.famo.us/lib/requestAnimationFrame.js'></script>
<script type='text/javascript' src='http://code.famo.us/lib/require.js'></script>
<link rel='stylesheet' type='text/css' href='http://code.famo.us/famous/0.2/famous.css' />
<script type='text/javascript' src='http://code.famo.us/famous/0.2/famous.min.js'></script>
<link rel='stylesheet' type='text/css' href='styles/app.css' />
<script type='text/javascript' src='tstPackage.js'>
</script>
</head>
<body>
</body>
</html>

js:

require(['famous/core/Engine','famous/core/Surface'],function(Engine,Surface) {
// Famo.us Context Example
//var Engine = require('famous/core/Engine');
//var Surface = require('famous/core/Surface');

var mainContext = Engine.createContext();

var surface = new Surface({
size: [200, 200],
content: 'Hello World',
classes: ['red-bg'],
properties: {
lineHeight: '200px',
textAlign: 'center'
}
});

mainContext.add(surface);
// from https://famo.us/examples/0.2.0/core/context/example

});

关于meteor - 如何在 meteor 应用程序中使用 famo.us CDN 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com