const path = require('path');

process.env.NODE_ENV = 'production';

module.exports = {
  entry: path.resolve(__dirname, '../src/index.js'),
  output: {
    path: path.resolve(__dirname, '../dist'),
    libraryTarget: 'umd',
    umdNamedDefine: true,
  },
  mode: process.env.NODE_ENV,
  module: {
    rules: [
      {
        test: /\.jsx$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['babel-preset-env'],
          },
        },
      },
      {
        oneOf: [
          {
            test: /src[\\/]theme\.less$/,
            use: [
              {
                loader: `${path.resolve(
                  __dirname,
                  '../src/less-vars-to-js-loader.js',
                )}?path=./src`,
              },
            ],
          },
          {
            test: /\.less$/,
            use: [
              'style-loader',
              'css-loader',
              {
                loader: 'less-loader',
                options: {
                  lessOptions: {
                    javascriptEnabled: true,
                  },
                },
              },
            ],
            include: [
              path.resolve(__dirname, '../src'),
              path.resolve(__dirname, 'node_modules'),
            ],
          },
        ],
      },
      {
        test: /\.(eot|svg|ttf|woff(2)?)(\?v=\d+\.\d+\.\d+)?/,
        use: [
          {
            loader: require.resolve('url-loader'),
          },
        ],
      },
    ],
  },
};
