如何应用r.js对requirejs下的js代码合并

1、在根目录新建build.js

({
    baseUrl:'js',
    paths:{
                jquery:'static/jquery-1.10.2.min',
                underscore:'static/underscore',
                bootstrap:'static/bootstrap'
            },
    shim:{
                'bootstrap':['jquery']
            },
    name:'main',
    out:'js/main-build.js'

})

2、cmd下找到项目所在目录 执行 node r.js -o build.js

C:\xampp\htdocs\test\require>node r.js -o build.js

3、合并成功

Tracing dependencies for: main
Uglifying file: C:/xampp/htdocs/test/require/js/main-build.js

C:/xampp/htdocs/test/require/js/main-build.js
----------------
C:/xampp/htdocs/test/require/js/static/jquery-1.10.2.min.js
C:/xampp/htdocs/test/require/js/static/underscore.js
C:/xampp/htdocs/test/require/js/static/bootstrap.js
C:/xampp/htdocs/test/require/js/cache.js
C:/xampp/htdocs/test/require/js/main.js

4、修改data-main 引用生成的main-build.js

<script data-main="main-build" src="require.js"></script>

5、查看网络

如何应用r.js对requirejs下的js代码合并_第1张图片

大功告成!

详细的build.js配置参见: https://github.com/jrburke/r.js/blob/master/build/example.build.js

 

css

none  不压缩,仅合并

standard  标准压缩 去换行、空格、注释

standard.keepLines  除标准压缩外,保留换行

standard.keepComments  除标准压缩外,保留注释

standard.keepComments.keepLines  除标准压缩外,保留换行和注释

 node r.js -o cssIn=css/main.css out=css/built.css optimizeCss=standard
 
 

你可能感兴趣的:(如何应用r.js对requirejs下的js代码合并)