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 打包之后 require返回的对象为null #1488

Closed
honger05 opened this issue Apr 22, 2015 · 8 comments
Closed

seajs 打包之后 require返回的对象为null #1488

honger05 opened this issue Apr 22, 2015 · 8 comments

Comments

@honger05
Copy link

   define("tms/login/1.0.0/login-debug", [ "$-debug" ], function(require, exports, module) {
      var $ = require("$-debug"), Utils = require("utils-debug");  // null
   }

这样 返回的 $ 、Utils 都为 null 。

   define("tms/login/1.0.0/login-debug", function(require, exports, module) {
      var $ = require("$-debug"), Utils = require("utils-debug"); // object
   }

, [ "$-debug" ] 把依赖删除了 就 正常了。

为什么啊!

@army8735
Copy link
Member

那个是工具用的,提前解析。如果遇到这个参数就不即时解析加快速度了。第2个参数是undefined,自然没有

@honger05
Copy link
Author

define("att/b/1.0.0/a-debug", [ "b-debug" ], function(require) {
    var b = require("b-debug"), c = require("c-debug");
    console.log(b); // object
    console.log(c); // null
});

我刚刚测试发现 如果 [ "b-debug" ] 这里不写成 [ "b-debug" , "c-debug" ] 的话 ,下面的c就是null

就是说 [ "b-debug" ] 提前解析了,下面的require将不再解析。如果上面不配置 [ ] 依赖。才会去解析 rquire() 的文件。

那么问题来了!

为什么我的spm2打包的时候 就只自动添加第一个依赖b-debug。后面的依赖c-debug不会再加上去,导致c的对象是null。

@army8735
Copy link
Member

@sorrycc

@honger05
Copy link
Author

另外 请教一个问题

之前 我想用spm3的 但是spm3不能直接打包在本地。 后来放弃了。

后来看了些spm3的资料, 了解到 现在都写成 commonjs规范的

打包的时候 线上再把它封装成 cmd的。

然后再下载下来用。。。

我对 spm3 的理解对吗?

那我在实际写业务模块的时候 不是很麻烦么。并且我上传的业务模块不是大家能用的。

我也并不希望敏感的 业务模块上传到spmjs.io上。

这时候 我怎么使用spm3呢?

@army8735
Copy link
Member

spm3可以本地打包

@afc163
Copy link
Member

afc163 commented Apr 23, 2015

spm build

@honger05
Copy link
Author

我用spm2打包 ,又有个问题
抽取依赖的时候,相对路径为 [ "./lo\\lo-debug"] 这样会报这个文件找不到的错误
改成 [ "./lo/lo-debug"] 就没问题。 这算bug吗?

前者是加载文件,后者是加载模块

@nimoc
Copy link

nimoc commented Apr 23, 2015

@honger05
关于 spm3 请关注这个issues
spmjs/spm#1273

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

4 participants