新建一个项目
/views 文件夹内新建一个ejs 比如hell.ejs
<script src="/sea.js"></script>
<script type="text/javascript">
//sea简单配置
seajs.config({
//base:"../public",
alias:{
"jquery":"jquery.js"
}
})
//加载入口模块
seajs.use(['./hello'],function(fn){
fn.Hello();
})
</script>
在路由/routers中添加一个跳转页面
router.get('/hello', function(req, res, next) {
res.render('hello', { title: 'Express' });
});
在public根目录创建一个hello.js (如果不是根目录则seajs.use()加载模块目录中则需改写"../public/xxx/hello.js")
define(function(require, exports, module) {
var $ = require('./jquery');
exports.Hello = function(){
$('<h2>Hello SeaJS !</h2>').appendTo('body');
}
});
打开localhost:3000/hello 页面显示 Hello SeaJS !
用到开发工具是WebStorm