config

可以使用 config 方法来配置seajs。

seajs.config({
alias: { //~~~类似requirejs的paths
'es5-safe': 'es5-safe/0.9.2/es5-safe',
'json': 'json/1.0.1/json',
'jquery': 'jquery/1.7.1/jquery'
},
preload: [
Function.prototype.bind ? '' : 'es5-safe',
this.JSON ? '' : 'json'
],
debug: true,
map: [
['http://example.com/js/app/', 'http://localhost/js/app/']
],
base: 'http://example.com/path/to/libs/', //~~~类似requirejs的baseUrl
charset: 'utf-8',
timeout: 20000
});

支持以下配置选项:

alias

当模块标识很长时,可以使用 alias 配置来简化。~~~设置路径别名

seajs.config({
alias: {
'app': 'http://path/to/app',
'jquery': 'jquery/1.7.1/jquery'
}
});

a.js:

define(function(require, exports, module) {
var $ = require('jquery');
//=> http://path/to/libs/jquery/1.7.1/jquery.js var biz = require('app/biz');
//=> http://path/to/app/biz.js
});

解析某个模块标识时,如果不想解析别名,可以在标识前面添加一个井号(#):

define(function(require, exports, module) {
var $ = require('#jquery');
//=> http://path/to/libs/jquery.js
});

preload

使用 preload 配置项,可以在普通模块加载前,提前加载并初始化好特定模块。

// 在老浏览器中,提前加载好 ES5 和 json 模块:
seajs.config({
preload: [
Function.prototype.bind ? '' : 'es5-safe',
this.JSON ? '' : 'json'
]
});

preload 中的空字符串会被忽略掉。

debug

值为 true 时,加载器会使用 console.log 输出所有警告和错误。 默认为 false, 加载器只抛出异常。

另外,还可以将 debug 值设为 2 . 这种情况下, 每个脚本请求都会加上唯一时间戳。这在测试期间很有用,可以强制浏览器每次都请求最新版本。

map

该配置可将某个文件映射到另一个。可用于在线调试,非常方便。更多信息,请参考 映射插件

base

SeaJS 在解析顶级标识时,会相对 base 路径来解析。详情请参阅 顶级标识

** 注意:请不要配置 base 路径,除非加载器无法自动获取。详情请参考 加载方式

charset

获取模块文件时,<script> 标签的 charset 属性。 默认是 utf-8

timeout

加载器等待脚本加载的最长时间。单位为毫秒,默认值是 20000(20秒)。

noConflict

为了避免冲突,或者需要定制全局命名空间以符合自己的口味时,可以使用 noConflict 方法来实现。 ~~~类似jquery.noConflict

var myLoader = seajs.noConflict();
myLoader.use('./main'); /* main.js */
define(function(require, exports, module) {
// snip...
});

还可以通过给该方法传递 true,来释放 define 方法。 很少会有这么做的必要, 请三思而后行。

var myLoader = seajs.noConflict(true);
myLoader.use('./main'); /* main.js */
myLoader.define(function(require, exports, module) {
// snip...
});

转: seajs手册与文档之 -- 配置选项的更多相关文章

  1. 转: seajs手册与文档之 -- 模块标识

    目录 模块标识 相对标识 顶级标识 普通路径 文件后缀的提示 模块标识 模块标识是一个字符串,用来标识模块.在 require. require.async 等加载函数中,第一个参数都是模块标识.de ...

  2. 转: seajs手册与文档之 -- 快速参考 ( ~~useful )

    目录 快速参考 seajs.use seajs.config define require require.async exports module.exports 快速参考 该页面列举了 SeaJS ...

  3. 转: seajs手册与文档之 -- require规则

    require 规则 正确拼写 不要修改 使用直接量 动态依赖的小提示 书写规则 使用 SeaJS 书写模块代码时,需要遵循一些简单规则: 1. 正确拼写 在模块代码中,第一个参数 必须 命名为 re ...

  4. 转: seajs手册与文档之--模块定义

    模块定义 define id dependencies factory exports require require.async require.resolve require.load requi ...

  5. CsvHelper文档-5配置

    CsvHelper文档-5配置 CsvHelper库被设计成快速且简单易用,但是有时候默认的是设置不符合要求,需要你自己改变一些东西.所以csvHelper内置了很多自定义设置选项来改变读写行为.特别 ...

  6. Sea.js 手册与文档

    Sea.js 手册与文档 首页 | 索引 目录 何为 CommonJS 何为 CommonJS 模块 为何封装模块 何为 CommonJS? CommonJS 是一个有志于构建 JavaScript ...

  7. 【数据库】6.0 MySQL入门学习(六)——MySQL启动与停止、官方手册、文档查询

    1.0 MySQL主要有四种启动方式:直接启动.安全启动.服务启动.多实例启动. 直接启动: 服务器启动: 安全启动(最常用): 多实例启动: 2.0如何获得MySQL帮助 2.1官方手册 下面提供百 ...

  8. solr schema.xml文档节点配置

    首先,讲解一下/usr/local/solr/collection1/conf/schema.xml的配置,此文档功能类似于配置索引数据库. Field:类似于数据库字段的属性(此文统一使用用“字段” ...

  9. 【Ansible 文档】配置

    http://docs.ansible.com/ansible/latest/intro_configuration.html http://docs.ansible.com/ansible/late ...

随机推荐

  1. hdoj 2620 Bone Collector(0-1背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 思路分析:该问题为经典的0-1背包问题:假设状态dp[i][v]表示前i件物品恰放入一个容量为v ...

  2. 关于webroot与web-inf

    struts.xml中配置redirect重定向路径的问题,要把转发的页面放到WebRoot下才能访问到,要是放在WEB-INF下面就访问不到.

  3. HDU 11488 Hyper Prefix Sets (字符串-Trie树)

    H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...

  4. 超高性价比USB转CAN适配器,2500V工业级隔离,兼容ZLG软件

    淘宝链接: http://item.taobao.com/item.htm?spm=a230r.1.14.16.QGsAZg&id=20134109594&initiative_new ...

  5. 设置android:supportsRtl=&quot;true&quot;无效问题

     今天解bug时,遇到这样一个问题:   问题描写叙述:切换系统语言为阿拉伯文时,actionbar布局没有变为从右向左排列.   于是,我在Androidmanifest.xml文件里的 appli ...

  6. 记WebUtility.HtmlDecode将&nbsp;转成特殊空格的问题

    在.net中 System.Web.HttpUtility.HtmlDecode(或者WebUtility.HtmlDecode) 方法会将   解码为特殊空格(Ascii值为,对应的值为:\u00A ...

  7. [Swust OJ 589]--吃西瓜(三维矩阵压缩)

    题目链接:http://acm.swust.edu.cn/problem/589/ Time limit(ms): 2000 Memory limit(kb): 65535   Description ...

  8. Dojo实现Tabs页报错(一)

    1.在用Dojo写tab页的过程中出现了一些错误 dojo源码如下: <%-- Document : grid Created on : 2013-12-15, 18:05:47 Author ...

  9. The Standard Librarian: I/O and Function Objects: Containers of Pointers

    C++ Experts Forum The Standard Librarian: I/O and Function Objects: Containers of Pointers Matthew A ...

  10. 启用Apache Mod_rewrite模块

    Ubuntu 环境 在终端中执行 sudo a2enmod rewrite 指令后,即启用了 Mod_rewrite 模块. 另外,也可以通过将 /etc/apache2/mods-available ...