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

支持build参数,指定打包不同的配置文件 #171

Closed
leeight opened this issue Mar 14, 2014 · 11 comments
Closed

支持build参数,指定打包不同的配置文件 #171

leeight opened this issue Mar 14, 2014 · 11 comments

Comments

@leeight
Copy link
Member

leeight commented Mar 14, 2014

ecomfe/edp-build#36

@otakustay
Copy link
Member

为啥conf在src下……

在 2014年3月14日,13:18,leeight notifications@github.com 写道:

ecomfe/edp-build#36


Reply to this email directly or view it on GitHub.

@leeight
Copy link
Member Author

leeight commented Mar 14, 2014

他应该是举个例子吧,最终不一定要在src下面

@jinzhubaofu
Copy link

对的,conf可以放在src同级目录下

@leeight
Copy link
Member Author

leeight commented Mar 18, 2014

@yankun01

@yankun01
Copy link

@jinzhubaofu
看了一下需求,是要通过build参数来打包不同JS文件到最后的JS bundle,最后替换一下require
.config中的path参数,对吗?

刚看了一下代码,edp build 命令支持用config参数来指定build配置文件。例如:edp build --config 'edp-build-config-dev.js' 就去读edp-build-config-dev.js这个文件。我们也许可以在这个模块里任意制指定加载文件。最后在PathMapper中里指定需要的替换。

不知道这样能否解决这个问题。你可以加我的HI:vcfgvcfg继续讨论一下这个问题。

@leeight
Copy link
Member Author

leeight commented Mar 19, 2014

@yankun01 @jinzhubaofu 建议在issue上面讨论吧,这样子能有历史纪录。

@leeight
Copy link
Member Author

leeight commented Mar 19, 2014

我感觉可以放到JsCompressor的阶段去做这个事情,例如:

// src/common/a.js
define(function( require ){
  console.log( kUrl );
  require( './log' ) ( kUrl );
});

// src/common/log.js
define(function( require ){
  return function( msg ){
    if ( kDEBUG ) { console.log( msg ) }
  }
});

edp-build-config.js的配置里面,新增:

new JsCompressor({
  compressOptions: {
    global_defs: {
      kUrl: 'http://www.baidu.com',
      kDEBUG: false
    }
  }
});

当然了global_defs的值可以根据传递的不同参数,读取不同文件,不一定需要在edp-build-config.js里面写死的。

例如:

new JsCompressor({
  compressOptions: {
    global_defs: GlobalDefines( 'dev.define.js' )
  }
});

// dev.define.js
exports.kUrl = 'http://www.baidu.com',
exports.kDEBUG = false;

@leeight
Copy link
Member Author

leeight commented Mar 19, 2014

更进一步,如果需要处理的不仅仅是js,html,css也需要处理,就可能需要独立出一个Processor来做这个事情。

因为JsCompressor的内部实现是基于uglify-js的,所以处理js的时候有一定的优化策略。比如很明显的dead-code会被剔除掉。

@treelite
Copy link
Contributor

目前的话可以直接使用PathMapper内建的module-config处理器来进行require.config的替换,配合edp build --config xxx使用

另外现在有好些Processor都能做类似的事儿:ReplaceDebugVariableSubstitutionStringReplaceProcessorPathMapper

不过为不同的输出环境写不同的edp-build-config.js比较麻烦而且这些配置文件中大部分又是重复的,可以考虑重构edp-build.config.js使其能更灵活的进行task的设置?

@leeight
Copy link
Member Author

leeight commented Mar 20, 2014

我建议把exports.getProcessors改成这样子;

var p1 = new Processor1();
var p2 = new Processor2();
var p3 = new Processor3();

exports.getProcessors = function() {
  return {
    default: [ p1, p2 ],
    dev: [ p2 ],
    release: [ p1, p2, p3 ]
  };
}

当执行edp build --stage=dev的时候,选择用dev配置的Processors来执行。

@leeight
Copy link
Member Author

leeight commented Mar 20, 2014

另外现在有好些Processor都能做类似的事儿:ReplaceDebug, VariableSubstitution,StringReplaceProcessor,PathMapper

这个的确是个问题,需要统一考虑一下。新建一个ISSUE吧。

leeight added a commit to ecomfe/edp-build that referenced this issue Mar 24, 2014
@leeight leeight closed this as completed Mar 25, 2014
leeight added a commit to ecomfe/edp-build that referenced this issue Apr 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants