require js 将config和入口函数分开写

原文地址

https://github.com/jrburke/requirejs/issues/354

Area there any plans to standardize/recommend a particular approach? If there is, I would suggest the following:

// homepage.html
<script data-id="requirejs" data-logic="home" data-main="js/config" src="js/lib/require.js"></script>

In, config.js

require.config({
    baseUrl: 'js'
});

// Load app logic as specified in `data-logic` attribute
require([document.querySelector('script[data-id="requirejs"]').getAttribute("data-logic")]);
posted @ 2015-11-25 20:42  象牛  阅读(385)  评论(0编辑  收藏  举报