"use strict";

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

var _miniCssExtractPlugin = _interopRequireDefault(require("mini-css-extract-plugin"));

var _utils = require("../utils");

var _cssClassNameGenerate = _interopRequireDefault(require("../utils/cssClassNameGenerate"));

var _pluginUtils = require("../pluginUtils");

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

let options = (0, _utils.getOptions)();
let {
  umd: {
    css: {
      umdVar,
      watch,
      outputFolder,
      cssUniqueness,
      folder,
      publicPath,
      cssHashSelectors,
      classNamePrefix,
      customClassNamePrefix
    }
  },
  packageVersion
} = options;
let appPath = process.cwd();
let publicPathStr = `${publicPath || `${'//js.zohostatic.com/support/zohodeskcomponent@'}${packageVersion}`}/${outputFolder}/`;
module.exports = {
  watch: watch,
  entry: {
    main: _path.default.join(appPath, folder, 'css.js')
  },
  output: {
    path: _path.default.resolve(appPath, outputFolder),
    filename: '[name].js',
    library: umdVar,
    libraryTarget: 'umd',
    publicPath: publicPathStr
  },
  mode: 'production',
  optimization: {
    minimize: true
  },
  plugins: (0, _pluginUtils.getUMDCSSPlugins)('styles.css'),
  module: {
    rules: [{
      include: /\.json$/,
      use: [{
        loader: 'json-loader'
      }]
    }, {
      test: /\.js$/,
      use: [{
        loader: 'babel-loader',
        options: {
          presets: [[require.resolve('@babel/preset-env'), {
            modules: false
          }], require.resolve('@babel/preset-react')],
          plugins: [require.resolve('@babel/plugin-proposal-object-rest-spread')],
          cacheDirectory: true
        }
      }],
      include: _path.default.join(appPath, 'src')
    }
    /*,
    {
    test: /\.css$/,
    use: [MiniCssExtractPlugin.loader, 'css-loader']
    }*/
    , {
      test: /(\.module)?\.css$/,
      use: [{
        loader: _miniCssExtractPlugin.default.loader,
        options: {
          publicPath: '../'
        }
      }, {
        loader: 'css-loader',
        options: {
          modules: {
            getLocalIdent: (0, _cssClassNameGenerate.default)(cssUniqueness, cssHashSelectors, classNamePrefix, customClassNamePrefix)
          }
        }
      }]
    }, {
      test: /\.jpe?g$|\.gif$|\.png$/,
      use: ['url-loader?limit=10000&name=./images/[name].[ext]']
    }, {
      test: /\.woff$|\.woff2$|\.ttf$|\.eot$/,
      use: ['url-loader?limit=10000&name=./fonts/[name].[ext]']
    }, {
      test: /\.svg$/,
      use: ['url-loader?limit=1&name=./fonts/[name].[ext]']
    }, {
      test: /\.html$/,
      use: {
        loader: 'html-loader',
        options: {
          attrs: [':data-src'],
          interpolate: 'require'
        }
      }
    }]
  },
  resolve: {
    modules: [_path.default.resolve(__dirname, '..', '..', 'node_modules'), 'node_modules']
  },
  resolveLoader: {
    modules: [_path.default.resolve(__dirname, '..', '..', 'node_modules'), 'node_modules']
  }
};