src
src
|-- index.html
|-- js
| |-- amdconfig.js
| |-- main.js
| |-- ...
|-- lib
|-- require
| |-- require.js
|-- d3
| |-- d3.js
|-- luciad
|-- ...
index.html
包含以下代码:
<script src="./lib/requirejs/require.js" type="text/javascript"></script><!-- require.js -->
<script src="./js/amdconfig.js" type="text/javascript"></script><!-- require.js config -->
<script type="text/javascript">
require(["app/js/main"]); /* main module */
</script>
amdconfig.js
(function(configure, app) {
var lib = [app, "lib"].join("/");
configure({
baseUrl : app,
urlArgs : "bust=" + (new Date()).getTime(),
packages : [{
name : "requirejs",
location : [lib, "requirejs"].join("/")
}, {
name : "luciad",
location : [lib, "luciad"].join("/")
}, {
name : "d3",
location : [lib, "d3"].join("/")
}, {
name : "app",
location : app
}],
cache : {}
})
})(
require.config ? require.config /* RequireJS */ : require, /* Dojo */
'.'
)
builder
|-- build.js
|-- package.json
如果有以下代码:
require('requirejs').optimize({
baseUrl: '../src',
paths: {
main: 'main',
requirejs : './lib/requirejs',
luciad : './lib/luciad',
d3 : './lib/d3',
app : './'
},
name: 'js/main',
out : '../dist/main.js',
optimize: "uglify2",
uglify2: {
output: {
beautify: false
},
compress: {},
warnings: true,
mangle: true
}
}, function (buildResponse) {
console.log(buildResponse);
});
构建脚本确实生成了一个缩小的
main.js
文件,并按预期在控制台中输出包含的文件列表。
src公司
define('namespaced/path',["dependency1", "dependency2"], function(a,b){...});
我想这就是预期的格式。。。