"use strict";

var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property"));

var _defineProperties = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-properties"));

var _getOwnPropertyDescriptors = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors"));

var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));

var _getOwnPropertyDescriptor = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor"));

var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));

var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));

var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));

var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));

var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));

var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));

var _defineProperty3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));

var _path = require("path");

var _webpack = _interopRequireDefault(require("webpack"));

var globalDefines = _interopRequireWildcard(require("../babel-define"));

var _webpack2 = require("../configs/webpack/webpack.config");

var _webpack3 = require("../configs/webpack/webpack.plugins");

function ownKeys(object, enumerableOnly) { var keys = (0, _keys.default)(object); if (_getOwnPropertySymbols.default) { var symbols = (0, _getOwnPropertySymbols.default)(object); if (enumerableOnly) symbols = (0, _filter.default)(symbols).call(symbols, function (sym) { return (0, _getOwnPropertyDescriptor.default)(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; (0, _forEach.default)(_context4 = ownKeys(source, true)).call(_context4, function (key) { (0, _defineProperty3.default)(target, key, source[key]); }); } else if (_getOwnPropertyDescriptors.default) { (0, _defineProperties.default)(target, (0, _getOwnPropertyDescriptors.default)(source)); } else { var _context5; (0, _forEach.default)(_context5 = ownKeys(source)).call(_context5, function (key) { (0, _defineProperty2.default)(target, key, (0, _getOwnPropertyDescriptor.default)(source, key)); }); } } return target; }

const CWD = process.env.CWD = process.cwd();
const CLI_ROOT = (0, _path.resolve)(__dirname, '..', '..');
const local_node_modules = (0, _path.join)(CLI_ROOT, 'node_modules');

module.exports = ({
  config
}) => {
  var _context, _context2, _context3;

  return _objectSpread({}, config, {
    resolveLoader: {
      modules: [local_node_modules, (0, _path.resolve)(CLI_ROOT, '../../node_modules'), (0, _path.resolve)(__dirname, '../configs/webpack/loaders'), //resolve(CWD, 'node_modules'),
      'node_modules']
    },
    resolve: _objectSpread({}, config.resolve, {
      alias: _objectSpread({
        'CORE_CONFIGS_PATH': '@meniga/config/src/configs',
        'CUSTOM_CONFIGS_PATH': (0, _path.resolve)(_webpack2.APP_PATH, 'configs')
      }, config.resolve.alias),
      modules: [(0, _path.resolve)(CWD, 'node_modules'), (0, _path.resolve)(CWD, '../../node_modules'), 'node_modules']
    }),
    mode: 'development',
    module: {
      rules: [{
        test: /\.(js|jsx|mjx)$/,
        loader: 'babel-loader',
        exclude: /node_modules[\\/](?!(@meniga))/,
        query: {
          presets: [[require.resolve('@babel/preset-env'), {
            targets: {
              browsers: ['last 2 versions', 'ie >= 11']
            } // UseBuiltIns does not work here, we might want to investigate why

          }], require.resolve('@babel/preset-react')],
          plugins: (0, _concat.default)(_context = [[require.resolve('@babel/plugin-proposal-decorators'), {
            legacy: true
          }], [require.resolve('@babel/plugin-proposal-class-properties'), {
            loose: true
          }]]).call(_context, (0, _map.default)(_context2 = ['babel-plugin-macros', '@babel/plugin-syntax-dynamic-import', '@babel/plugin-transform-async-to-generator', '@babel/plugin-proposal-export-namespace-from', '@babel/plugin-proposal-export-default-from', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-runtime', 'babel-plugin-jsx-control-statements', 'babel-plugin-lodash']).call(_context2, require.resolve))
        }
      }, {
        test: /\.(jpe?g|png|gif)$/i,
        loader: 'file-loader?name=images/[name].[ext]'
      }, {
        test: /\.module.less$/i,
        //loader: 'style-loader!css-loader?modules&localIdentName=[name]__[local]!less-loader',
        loader: _webpack3.ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [{
            loader: 'css-loader',
            options: {
              modules: true,
              localIdentName: '[name]__[local]'
            }
          }, {
            loader: 'less-loader'
          }],
          publicPath: '../'
        })
      }, {
        test: /^(?!.*\.module).*\.less.*$/i,
        // loader: 'style-loader!css-loader!less-loader',
        loader: _webpack3.ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [{
            loader: 'css-loader'
          }, {
            loader: 'less-loader'
          }],
          publicPath: '../'
        })
      }, {
        test: /\.css$/,
        //loader: 'style-loader!css-loader',
        loader: _webpack3.ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: 'css-loader',
          publicPath: '../'
        })
      }, {
        test: /\.(woff|woff2|svg|ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: 'file-loader?name=fonts/[name].[ext]',
        exclude: [/css/, /images/],
        include: /fonts/
      }, {
        test: /\.svg$/,
        loader: 'svg-inline-loader'
      }]
    },
    plugins: (0, _concat.default)(_context3 = [new _webpack.default.DefinePlugin(_objectSpread({}, globalDefines, {
      __CWD__: (0, _stringify.default)(process.cwd())
    })), new _webpack3.ExtractTextPlugin({
      filename: '[name].[hash].css',
      allChunks: false,
      disable: true
    })]).call(_context3, config.plugins)
  });
};