const { injectBabelPlugin } = require('react-app-rewired')
const rewireLess = require('react-app-rewire-less')
const path = require('path')

module.exports = function override (config, env) {

  config = injectBabelPlugin(
    [
      'import',
      {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
      }, 'ant',
    ],
    config,
  )

  config = injectBabelPlugin(
    [
      'import',
      {
        libraryName: 'antd-mobile',
        libraryDirectory: 'lib',
        style: true,
      }, 'ant-mobile',
    ],
    config,
  )

  config = rewireLess.withLoaderOptions({
    modifyVars: { '@primary-color': '#1DA57A' },
    javascriptEnabled: true,
  })(config, env)

  config.resolve.alias = {
    '@': path.join(__dirname, './src'),
  }

  return config
}
