84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
yuicompressor会替换本地变量名 于是require就被替换了掉了,但是http://seajs.org/docs/zh-cn/rules.htm... seajs要求require不被替换
yuicompressor好像不能为单独的变量加一个特殊规则 但要为了一个require不压缩所有的本地变量又觉得不划算呀。
走同样的路,发现不同的人生
spm已经支持了局部压缩,假设 a -> b -> c -> d
spm
spm build c.js
则仅仅会合并c和d,而spm还提供有同步和异步两种方案进行require。
require
仔细想了下,鉴于你的需求,我比较倾向于这样处理:
a 里面 require('b') b 里面 require.async('c') c 里面 require('d')
这样spm build的时候可以分开两步:
spm build
spm build a.js spm build c.js
这样可以打包为两个文件,因为这种局部打包其实说到最后还是怎么界定优化策略的问题,spm无法做得太多(或许还是不够聪明),但是因为seajs利用正则把require变成异步的方案仅推荐在开发的时候用,正式上线的时候还是区分开异步(require.async)和同步比较好。
我顺手做了个DEMO,https://gist.github.com/2583839 不知道这样做能否解决你的问题?
建议用 spm 来打包
可以把这个需求提给玉伯http://weibo.com/lifesinger看下。
修改源码 util.parseDependencies = function(code) { var ret = [], match, regRequire, regGet = /^function\s*\(\s*(\w+)/;
code = removeComments(code);
match = regGet.exec(code); regRequire = new RegExp('(?:^|[^.$])\\b' + match[1] + '\\s*\\(\\s*([\"\'])([^\"\'\\s\)]+)\\1\\s*\\)', 'g');
regRequire.lastIndex = 0;
while ((match = regRequire.exec(code))) { if (match[2]) { ret.push(match[2]) } }
return util.unique(ret) }
可以使用UglifyJS进行压缩:
UglifyJS hello.js -o hello.min.js -c -m -r require
spm
已经支持了局部压缩,假设 a -> b -> c -> dspm build c.js
则仅仅会合并c和d,而
spm
还提供有同步和异步两种方案进行require
。仔细想了下,鉴于你的需求,我比较倾向于这样处理:
a 里面 require('b')
b 里面 require.async('c')
c 里面 require('d')
这样
spm build
的时候可以分开两步:spm build a.js
spm build c.js
这样可以打包为两个文件,因为这种局部打包其实说到最后还是怎么界定优化策略的问题,
spm
无法做得太多(或许还是不够聪明),但是因为seajs利用正则把require
变成异步的方案仅推荐在开发的时候用,正式上线的时候还是区分开异步(require.async)和同步比较好。我顺手做了个DEMO,https://gist.github.com/2583839 不知道这样做能否解决你的问题?
建议用 spm 来打包
可以把这个需求提给玉伯http://weibo.com/lifesinger看下。
修改源码
util.parseDependencies = function(code) {
var ret = [], match, regRequire,
regGet = /^function\s*\(\s*(\w+)/;
code = removeComments(code);
match = regGet.exec(code);
regRequire = new RegExp('(?:^|[^.$])\\b' + match[1] + '\\s*\\(\\s*([\"\'])([^\"\'\\s\)]+)\\1\\s*\\)', 'g');
regRequire.lastIndex = 0;
while ((match = regRequire.exec(code))) {
if (match[2]) {
ret.push(match[2])
}
}
return util.unique(ret)
}
可以使用UglifyJS进行压缩: