CNode

Grunt 中使用 requirejs 合并和压缩文件的配置问题

问答
AAylein发布于12 年前最后回复12 年前3 回复10888 浏览0 收藏

最近在看jQuery源码 。。 简直云里雾里 jQeury是怎么样把这么多源文件合并混淆为一个jQuery.ver.min.js文件的呢

查看回复

回复 (3)

W
wh1100717#1·12 年前

build脚本 https://github.com/jquery/jquery/blob/master/build/tasks/build.js

Release脚本 https://github.com/jquery/jquery/blob/master/build/release.js

其实这和Grunt没什么太大的关系... 主要还是Jquery自己写了一些task来处理自己特殊的业务逻辑和项目构建,甚至包括了googleCDN,MicrosoftCDN release等内容。

自己的项目一般用不到这么复杂的...

A
Aylein#2·12 年前
引用 wh1100717build脚本 https://github.com/jquery/jquery/blob/master/build/tasks/build.js Release脚本 https://gith...

@wh1100717 非常感谢 0 0 以前只注意到了第一个文件 因为看到 build/tasks/build.js 里有一个 grunt 注册

grunt.registerTask( "custom", function() { var args = this.args, modules = args.length ? args[ 0 ].replace( /,/g, ":" ) : ""; grunt.log.writeln( "Creating custom build...\n" ); grunt.task.run([ "build::" + (modules ? ":" + modules : ""), "uglify", "dist" ]); });

所以一直以为 运行一个 grunt custom 就会生成一个合并压缩的文件 感觉很神奇

A
Aylein#3·12 年前

// Trace dependencies and concatenate files requirejs.optimize( config, function( response ) { grunt.verbose.writeln( response ); grunt.log.ok( "File '" + name + "' created." ); done(); }, function( err ) { done( err ); }); 这个函数好像很重要 requirejs 官网 在nodejs中使用requirejs页面有这个函数的介绍 。。 但是看不懂。。 requirejs

参与回复
登录后即可参与回复。登录