Comments (5)
我觉得你对data-main
的理解稍微有点问题。
main指的是入口模块,用于app启动的。类似于C里的main函数。通常情况下一个应用总需要一个模块作为启动入口,data-main
正是为此诞生。
正确使用data-main
的姿势是:
<head>
<script data-main="main" src="js/require.js"></script>
</head>
假设你要配置config,正确姿势应该是:
<head>
<script data-main="main" src="js/require.js"></script>
<script>
require.config({
});
</script>
</head>
不正确的姿势是:
html:
-----------
<head>
<script data-main="js/config" src="js/require.js"></script>
</head>
js/config.js:
-----------
require.config({});
require(['main'], function (main) {
});
from esl.
确实是这样,但是随便举个例子而已。如果有data-main的话,我可以减少写一行入口模块的执行脚本
from esl.
了解,有空的时候我实现下,看看体积具体增加了多少,再决定是否加入此特性。此issue先保持open状态
from esl.
其实很早之前用require.js的第一思路是。
<script data-main="js/config" src="js/require.js"></script>
```javascript
// config.js
require.config({
paths: {
jquery:"lib/jquery.min"
}
});
```javascript
// 当前页面的js
require(['jquery'], function($){
console.log($)
});
然后直接就挂了。
from esl.
挂是对的。因为页面上js执行时,你config.js还没回来,所以require(['jquery']
压根就没法去正确的位置请求
from esl.
Related Issues (20)
- `relative2absolute` 的问题 HOT 5
- 求助 zrender中怎么直接加载模块 HOT 1
- esl在一些特殊情况下无法加载module HOT 1
- 一个比较严重的bundle bug, header上多次添加同一bundle模块url HOT 4
- 压缩混淆模块后,局部require的方法名如果不是require,则无法加载module HOT 2
- 能否让esl支持node, 各种原因想在node上用esl HOT 2
- require.config 修改 packages 的配置 HOT 1
- add cross origin attribute to root require
- 处理 bundles 时候有可能请求错误的地址 HOT 1
- bundles 要不要考虑支持 glob pattern 或 RegExp match HOT 6
- 全局 require 函数,处理 querystring 的疑似 bug? HOT 1
- 调用require函数时 data-main指定的文件尚未加载完成.
- 相同的packages配置在requirejs中可以使用, 在esl却有问题.
- Performance Issue
- require 模块失败后,再次 require 该模块不会重新加载
- esl 怎么不做UMD?
- esl 与 requirejs 表现不一致的地方 HOT 1
- ESL 支持IE6吗? HOT 1
- factroy中require正则有点问题 HOT 1
- 使用data-main,并在config中设置waitSeconds出错 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esl.