tmodjs icon indicating copy to clipboard operation
tmodjs copied to clipboard

关于打包模块 自定义

Open bluemsn opened this issue 11 years ago • 2 comments

有这样一个场景,目前tmodjs的打包规则是 接照amd ,cmd 类似seajs,requirejs的 define形式进行打包的, 如下: https://github.com/aui/artTemplate/blob/master/src/outro.js


// RequireJS && SeaJS
if (typeof define === 'function') {
    define(function() {
        return template;
    });

// NodeJS
} else if (typeof exports !== 'undefined') {
    module.exports = template;
} else {
    this.template = template;
}

})();

这样打包,少了很多的适用性,因为有些加载器上的define规则 不是这个样式,这样就没办法适用了,

如下;


// RequireJS && SeaJS
if (typeof define === 'function') {
    define("想在此处会有一些名称",['template'],function(template) {
        return template;
    });

// NodeJS
} else if (typeof exports !== 'undefined') {
    module.exports = template;
} else {
    this.template = template;
}

})();

不知道 怎么样可以做到这样的需要求,

我看了一下 tmodjs的源码,发现支持 cmd,amd,default,的那段https://github.com/aui/tmodjs/blob/master/src/AOTcompile.js#L82
我自己加了一条规则 重写了一下,但是最后发现,define的地方,还是需要修改。觉得这个地方需要在grunt或者什么地方去配置。将配置的信息加到根据需要编译文件名字来定, define('static/js/a',['template'], function(){})

bluemsn avatar Jun 30 '14 05:06 bluemsn

对 define 自动添加 id 与依赖信息,这个不应该是 r.js 或者 spmjs 做的事情么?

aui avatar Jun 30 '14 07:06 aui

除非这个模块是一个通用的规范,否则不建议做成通用的。后续我考虑支持配置模块的exports

aui avatar Jul 04 '14 02:07 aui