fex-team / mod

BaseJS
274 stars 130 forks source link

mod.js中的js文件之间的依赖关系该如何处理呢? #10

Open renhao opened 10 years ago

renhao commented 10 years ago

比如:

var $ = require('juqery'); var Bootstrap = require('bootstrap');

这样写会报错,因为Bootstrap需依赖jquery; 请问这样的情况如何处理?

hefangshi commented 10 years ago

可以参考一下 https://github.com/hefangshi/modjs-autoload-demo

比如我们在页面中只要require('main')

https://github.com/hefangshi/modjs-autoload-demo/blob/master/index.html#L28-L30

在页面加载时,就会先加载main.js中声明的各种依赖模块

https://github.com/hefangshi/modjs-autoload-demo/blob/master/modules/main.js#L3-L9

另外你是否是直接独立使用的mod.js?mod.js是不能独立使用的,必须配合后端静态资源管理方案,如fis-plus, jello等,或者纯前端的静态资源管理方案fis-pure,这些方案会根据你的依赖关系进行模块加载。

BelinChung commented 10 years ago

你尝试把 jQuery 挂载在 window 变量下 $ = require('juqery');