/** * css压缩的构建处理器 * * @constructor * @param {Object} options 初始化参数 */ function CssCompressor( options ) { options = edp.util.mix( { files: [ '*.css' ], compressOptions: {} }, options ); AbstractProcessor.call( this, options ); }
/** * 路径映射的构建处理器 * * @constructor * @param {Object} options 初始化参数 * @param {function} options.mapper from和to的自定义处理函数. * @param {string} options.from 原路径前缀片段 * @param {string|function} options.to 替换的目标路径片段 * @param {Array} options.replacements 需要替换的对象列表 */ function PathMapper( options ) { this.files = [ '**/*' ]; var pageFiles = [ '*.html', '*.htm', '*.phtml', '*.tpl', '*.vm' ]; // 默认的配置 options = edp.util.mix( { replacements: [ { type: 'html', tag: 'link', attribute: 'href', files: pageFiles }, { type: 'html', tag: 'img', attribute: 'src', files: pageFiles }, { type: 'html', tag: 'script', attribute: 'src', files: pageFiles }, { type: 'html', tag: 'a', attribute: 'href', files: pageFiles }, { type: 'html', tag: 'embed', attribute: 'src', files: pageFiles }, { type: 'html', tag: 'param', attribute: 'value', files: pageFiles, condition: function ( tagSource ) { return /\sname=['"]movie['"]/.test( tagSource ); } }, { replacer: 'module-config', files: pageFiles.slice(0).concat( ['*.js'] ) }, { replacer: 'inline-css', files: pageFiles }, { replacer: 'css', files: ['*.css', '*.less'] } ], from: 'src', to: 'asset' }, options ); AbstractProcessor.call( this, options ); // 用户自定义的配置 var from = this.from = new RegExp( '(^|/)' + this.from + '(/|$)' ); var to = this.to = function ( match, head, tail ) { return (head === '/' ? head : '') + options.to + (tail === '/' ? tail : ''); }; if (typeof this.mapper !== 'function') { this.mapper = function(value) { return value.replace( from, to ); }; } var mapper = this.mapper; /** * 值替换函数 * * @param {string} value 原始值 * @return {string} */ this.valueReplacer = function ( value ) { if ( !value ) { return ''; } if ( !edp.path.isLocalPath( value ) ) { return value; } return mapper(value); }; }
/** * 模板合并的工作 * * @constructor * @param {Object} options 初始化参数 */ function TplMerge( options ) { // 默认的配置信息 options = edp.util.mix( { /** * 需要检查的插件Id列表 * @type {Array.<string>} */ pluginIds: [ 'tpl', 'er/tpl' ], /** * 项目的配置文件 * @type {string} */ configFile: 'module.conf', /** * 默认要处理的配置文件 * @type {Array.<string>} */ files: [ 'src/**/*.js' ], /** * 默认不要用format,否则chrome下面因为太多的字符串拼接操作,会出现 * RangeError: Maximum call stack size exceeded * 的问题 * * html2js的默认参数 * @type {Object} */ html2jsOptions: { mode: 'default' }, /** * 默认输出的文件路径,相对的是 configFile 所在的目录 * @type {string} */ outputPath: null, /** * 默认的代码输出模板 * @type {string} */ outputWrapper: 'define(function(){ return %output%; });' }, options ); AbstractProcessor.call( this, options ); /** * 所有找到的模板文件列表 * @private * @type {Array.<string>} */ this.tpls = []; /** * 所有需要替换的文件列表 * @private * @type {Object.<string, FileInfo>} */ this.fileMap = {}; /** * 开发状态下,模板大部分都是以xhr的形式加载的,但是 * 发布状态下,如果分开部署,涉及到跨域的问题,就需要以amd module的形式加载模板, * 那么可以设置一下这个参数的值. * * 需要注意的是,这个参数必须跟 `outputType` 一起配合使用 * @type {string} */ this.outputPluginId; /** * @type {string} */ this.outputType; }