const path = require('path');
// const nodeExternals = require('webpack-node-externals');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: {
    pages: path.resolve(__dirname, 'src/pages'),
    layouts: path.resolve(__dirname, 'src/layouts'),
    reducers: path.resolve(__dirname, 'src/reducers'),
    ui: path.resolve(__dirname, 'src/ui'),
    actions: path.resolve(__dirname, 'src/actions.js'),
    intl: path.resolve(__dirname, 'src/intl.jsx'),
  },
  // path.resolve(__dirname, 'src/index.js'),
  output: {
    path: path.resolve(__dirname, 'lib'),
    // filename: 'dashboard-components.[name].js',
    filename: '[name].js',
    library: ['dashboard-components', '[name]'],
    libraryTarget: 'umd',
  },
  resolve: {
    extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx'],
  },
  // externals: [nodeExternals()],
  target: 'web',
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        enforce: 'pre',
        exclude: /node_modules/,
        loader: 'eslint-loader',
        options: {
          emitWarning: true,
          failOnWarning: true,
          failOnError: true,
        },
      },
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        options: {
          presets: ['@babel/preset-env', '@babel/preset-react'],
          plugins: ['@babel/plugin-proposal-class-properties'],
        },
      },
      {
        test: /\.s[c|a]ss$/,
        use: ['style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
      },
      {
        test: /\.(png|jpg|gif)$/i,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 8192,
            },
          },
        ],
      },
    ],
  },
  plugins: [
    new MiniCssExtractPlugin({
      // filename: 'dashboard-components.[name].css',
      filename: '[name].css',
    }),
  ],
  performance: {
    hints: false,
  },
};
