"use strict";

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

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

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

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

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

let options = (0, _utils.getOptions)();
let {
  umd: {
    component: {
      umdVar,
      isHtml,
      isDocs,
      watch,
      outputFolder,
      cssUniqueness,
      folder
    }
  }
} = options;
let appPath = process.cwd();
let className = cssUniqueness ? 'fz__[hash:base64:5]' : '[name]__[local]';
module.exports = {
  watch: watch,
  entry: {
    main: _path.default.join(appPath, folder, isHtml ? 'html.js' : 'index.js')
  },
  output: {
    path: _path.default.join(appPath, outputFolder),
    filename: 'js/[name].js',
    library: umdVar,
    libraryTarget: 'umd'
  },
  mode: 'production',
  optimization: {
    minimize: true
  },
  plugins: (0, _pluginUtils.getUMDComponentPlugins)(isDocs),
  module: {
    rules: [{
      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: /(\.module)?\.css$/,
      use: [{
        loader: _miniCssExtractPlugin.default.loader,
        options: {
          publicPath: '../'
        }
      }, {
        loader: 'css-loader',
        options: {
          modules: true,
          localIdentName: className
        }
      }]
    }, isDocs ? {
      test: /\.docs\.js$/,
      use: require.resolve('../loaders/docsLoader.js'),
      exclude: /node_modules/
    } : {}, {
      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']
  }
};