Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加载模板问题 #16

Open
eyson opened this issue Sep 5, 2014 · 2 comments
Open

加载模板问题 #16

eyson opened this issue Sep 5, 2014 · 2 comments

Comments

@eyson
Copy link

eyson commented Sep 5, 2014

1、加载模板问题

先看看官方文档的例子

define("main", function(require) {
  //此模块的 factory 函数能够被执行
  // You can require `.tpl` file directly
  var tpl = require("./data.tpl")

});

嗯,这样子是可以正常加载模板的。那再试试下面的写法

define("main",[], function(require) {
  //此模块的 factory 函数能够被执行
  // You can require `.tpl` file directly
  var tpl = require("./data.tpl")

});

区别不大,只是加了个空的依赖数组,模板加载就失效了,始终都会执行到seajs-css上;

2、加载样式问题

seajs-text

// for css

register({
name: "css",

ext: [".css"],

exec: function(uri, content) {
var code = [
'define("' + uri + '#", ["importstyle"], function(require, exports, module) {',
' var source = "' + jsEscape(content) + '"',
' var importStyle = require("importstyle")',
' module.exports = function() {',
' importStyle(source, "' + uri + '#")',
' }',
'})'
].join('\n')

globalEval(code)

}
})

对的,看到`importstyle`,它是 `seajs-style`插件的方法。你得自己在配置中加上`alias`
那问题是什么呢?

当你和 `seajs-css`插件一起使用的时候,就无法使用`link`方式加载样式了,只能摘取到样式字符串文本。

解决方法呢,把以上代码去掉就好了。

> 是不是这样子呢。
@afc163
Copy link
Member

afc163 commented Sep 5, 2014

请用 seajs-text 的稳定版,不要用 master 上的开发版。

@boboxiao
Copy link

define("main",[], function(require) {
//此模块的 factory 函数能够被执行
// You can require .tpl file directly
var tpl = require("./data.tpl")

});

这样写,加载模板就失效了!但是:

define("main", function(require) {
//此模块的 factory 函数能够被执行
// You can require .tpl file directly
var tpl = require("./data.tpl")
});
这样写,就能加载模板

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants