//产出模式主要配置
var path = require('path');
var settings = require('../settings');
module.exports = function (hoo, root, media, relative) {
  var projectFiles = hoo.get('project.files');
  projectFiles.pop();
  projectFiles.pop();
  hoo.set('project.files', projectFiles);
  // 设置占位符
  var query = '?v=' + Date.now();
  var defineConfig = {};

  var mediaSet = hoo.media(media, defineConfig).match('**', {
    domain: relative ? "" : ("/" + path.join(settings.deployDir, ((root === '.' && media === 'prod') ? settings.defaultUploadDir : root)).replace(/\\/g, '/'))
  })
    .match('**.html', {
      //invoke hoo-optimizer-html-minifier
      optimizer: [hoo.plugin('html-minifier')]
    })
    .match('::package', {
      packager: hoo.plugin('map', {
        useTrack: false// 是否输出路径信息,默认为 true
      }),
      // 分析 __RESOURCE_MAP__ 结构，来解决资源加载问题
      postpackager: [hoo.plugin('loader', {
        resourceType: 'amd',
        useInlineMap: true,// 资源映射表内嵌
        allInOne: {
          js: '/static/bundle.js',
          includeAsyncs: true
        }
      }, 'prepend'), hoo.plugin('query', {
        placeholder: query // 这里传入占位符
      })
      ]
    })
    .match('**.{css,scss}', {
      packTo: '/static/bundle.css'
    })
    .match('/static/bundle.css', {
      release: '$0',
      useSprite: true
    });


  if (relative) {
    //使用相对路径
    mediaSet.hook('relative');
    mediaSet.match('**', {relative: true});
    /*mediaSet.match('**.html',{
     optimizer:function (content, file, settings) {
     // 只对 js 类文件进行处理
     console.log(file);
     return content;
     }

     })*/
  } else {
    mediaSet.match('**.js', {
      useHash: true,
      optimizer: hoo.plugin('uglify-js')
    })
      .match('**.{css,scss}', {
        useHash: true,
        // compress css invoke hoo-optimizer-clean-css
        optimizer: hoo.plugin('clean-css', {
          // option of clean-css
        })
      })
  }

  mediaSet.match('**.{png,jpg}', {
    useHash: true
  })
    .match('/components/**.{png,jpg}', {
      release: '/static/images/$0'
    })
    .match('/containers/**.{png,jpg}', {
      release: '/static/images/$0'
    })
    //针对以前的目录结构css/images/**.{png,jpg}进行兼容
    .match('/css/images/**.{png,jpg}', {
      release: '/static/images/$0'
    })
    .match('/entry/images/(**.{png,jpg})', {
      release: '/static/images/$1$2'
    })
    .match('/entry/images/extras/(**.{png,jpg})', {
      useHash: false
    })
    .match('/extras/**.{png,jpg}', {
      release: '$0',
      useHash: false
    });
};
