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

打包后的js把require都替换掉了,导致seajs不能运行。 #4

Open
cxc3214 opened this issue Jun 13, 2015 · 1 comment
Open

Comments

@cxc3214
Copy link

cxc3214 commented Jun 13, 2015

package.json

{
    "name": "sjld-flow", 
    "version": "0.0.1", 
    "description": "sjldflow", 
    "keywords": [ ], 
    "homepage": "", 
    "repository": {
        "type": "svn", 
        "url": ""
    }, 
    "bugs": {
        "url": ""
    }, 
    "licenses": "MIT", 
    "spm": {
        "output": [            
            "bjlbb.js"
        ], 
        "dependencies": {
            "seajs": "2.3.0"
         }, 
        "engines": {
             "seajs": "2.3.0"
        },
        "ignore": ["backbone","handlebars","underscore"]
    }
}


打包后的js一段

define("sjld-flow/0.0.1/wdsx",["backbone","handlebars","underscore"],function(t,e,n){var i=t("sjld-flow/0.0.1/mvc/view/wdsx/wdsx");n.exports=i});

t,e,n 被替换
而sea-warp源码里CMD_REG正则是要有require 才不会包 define

 wrapExec[uri] = function(uri, content) {
var wrappedContent;
var CMD_REG = /define\(.*function\s*\(\s*require\s*(.*)?\)\s*\{/;
if (CMD_REG.test(content) ||
query.indexOf('nowrap') > 0) {
wrappedContent= content;
} else {
wrappedContent = 'define(function(require, exports, module) {\n' +
content + '\n})';
}
wrappedContent = wrappedContent + '//# sourceURL=' + uri;
globalEval(wrappedContent, uri);
} 

请问如何才能打包不用 替换require 或者如何才能正确执行?谢谢啦

@nuintun
Copy link

nuintun commented Jul 20, 2015

define(id, deps, factory)

提取依赖后 deps 已经不再用 require 获取了,而是直接从 define 的第二个参数获取,所以这时候压缩是不会有问题的,如果你那边报错先去检查下你的id和路径的对应关系!

sea-wrap 并不推荐线上环境用,跨域在老版本浏览器是个问题!

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

2 participants