"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.configAudioLoader = configAudioLoader;
exports.configFontLoader = configFontLoader;
exports.configImageLoader = configImageLoader;
exports.configSVGLoader = configSVGLoader;
exports.configVideoLoader = configVideoLoader;
exports.configVideoLoaderObj = configVideoLoaderObj;
exports.createNameTemplate = createNameTemplate;

var _path = _interopRequireDefault(require("path"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// function getLoaderOptionQueryString(params) {
const ImageExtRegex = /\.jpe?g$|\.gif$|\.png|\.webp$/;
const FontExtRegex = /\.woff2|\.woff$|\.ttf$|\.eot$/;
const SVGExtRegex = /\.svg$/;
const AudioExtRegex = /\.ogg|\.mp3$/;
const VidioExtRegex = /\.mp4|\.webm$/;

function createLoaderOptionQueryString(loaderName, nameTemplate, limit = 1000) {
  return `${loaderName}?limit=${limit}&name=${nameTemplate}`;
}

function configImageLoader(nameTemplate) {
  return {
    test: ImageExtRegex,
    use: createLoaderOptionQueryString('url-loader', `./images/${nameTemplate}`)
  };
}

function configFontLoader(nameTemplate) {
  return {
    test: FontExtRegex,
    use: createLoaderOptionQueryString('url-loader', `./fonts/${nameTemplate}`)
  };
}

function configSVGLoader(nameTemplate) {
  return {
    test: SVGExtRegex,
    use: createLoaderOptionQueryString('url-loader', `./fonts/${nameTemplate}`, 1)
  };
}

function configAudioLoader(nameTemplate) {
  return {
    test: AudioExtRegex,
    use: createLoaderOptionQueryString('file-loader', `./fonts/${nameTemplate}`, 1)
  };
}

function configVideoLoader(nameTemplate) {
  return {
    test: VidioExtRegex,
    use: createLoaderOptionQueryString('url-loader', `./videos/${nameTemplate}`, 1)
  };
}

function configVideoLoaderObj(nameTemplate) {
  return {
    test: VidioExtRegex,
    use: {
      loader: 'url-loader',
      options: {
        limit: 1000,
        name: nameTemplate,
        fallback: _path.default.join(__dirname, '..', 'loaders', 'fileLoader.js')
      }
    }
  };
}

function createNameTemplate(enableChunkHash) {
  const ext = `${enableChunkHash ? '.[hash:20]' : ''}.[ext]`;
  return `[name]${ext}`;
}
/*
export function createImageAndFontsAndSVGLoaders(enableChunkHash) {
  const nameTemplate = createNameTemplate(enableChunkHash);
  return [
    configImageLoader(nameTemplate),
    configFontLoader(nameTemplate),
    configSVGLoader(nameTemplate),
    configAudioLoader(nameTemplate)
  ];
}
*/

/*
export function createLoaderOptionObject(
  loaderName,
  nameTemplate,
  fallback,
  limit = 1000
) {
  return {
    loader: loaderName,
    options: {
      limit,
      name: nameTemplate,
      fallback
    }
  };
}

function configLoaderObject(filter, loaderAndOptions) {
  return {
    test: filter,
    use: loaderAndOptions
  };
}
*/