目錄結構javascript
原main.jshtml
// RequireJS配置 requirejs.config({ baseUrl: '../js',//js文件載入基路徑 //enforceDefine: true,//enforceDefine用來強制模塊使用define定義,不然可能會報No define call for ...之類錯誤 paths: { ctrl: './models', libs:"./lib", 'jquery':"./lib/jquery", "backbone":"./lib/backbone", 'underscore':"./lib/underscore" } /*路徑別名*/ }); require(["ctrl/m1","jquery"], function (m1,$) { var view=new m1() $("html body").html(view.el) });
新建built.jsjava
({ appDir:'./', baseUrl: './', dir:'./app-build', paths: { ctrl: './models', libs:"./lib", 'jquery':"./lib/jquery", "backbone":"./lib/backbone", 'underscore':"./lib/underscore" }, modules:[{ name:"./lib/main" }] })