Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用时间戳后,再使用seajs-debug加载未压缩的xx-debug.js失效 #16

Open
stoneChen opened this issue Apr 21, 2014 · 1 comment

Comments

@stoneChen
Copy link

配置map后的确可以解决时间戳的问题,代码如下:

seajs.config({
            alias: {
               //别名设置...
            },
            map: [
                [ /^(.*\/app.*\/.*\.(?:css|js))(?:.*)$/i, '$1?t=20140421' ]
            ]
        })

但是打包部署后,使用{url}?seajs-debug访问页面,调出调试窗口后,无法调用未压缩的xx-debug.js

查了下源码,发现seajs源码中有下面这句话:

for (var i = 0, len = map.length; i < len; i++) {
      var rule = map[i]

      ret = isFunction(rule) ?
          (rule(uri) || uri) :
          uri.replace(rule[0], rule[1])

      // Only apply the first matched rule
      if (ret !== uri) break
    }

导致seajs-debug.js中的map函数不被执行.
而seajs-debug是被异步preload进来的,理论上,seajs-debug中的map始终比我自己的map注册时间晚,所以xx-debug.js的map执行不了.
请问有什么好办法解决此问题么?

@stoneChen
Copy link
Author

研究出一个勉强可行方案:

var pageDebug = (seajs.data.preload[0] == 'seajs-debug');//判断是否预加载seajs-debug
seajs.config({
    alias: {
        "$": "jquery/jquery/1.7.2/jquery",
        "$-debug": "jquery/jquery/1.7.2/jquery-debug",
        "seajs-debug": "seajs/seajs-debug/1.1.1/seajs-debug",
        "placeholders":"gallery/placeholders/3.0.2/placeholders"
    },
    map: [
        pageDebug?function(){}:[ /^(.*\/app.*\/.*\.(?:css|js))(?:.*)$/i, '$1?t=20140421' ]//时间戳
    ]
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant