const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyPlugin = require('copy-webpack-plugin')
//__dirname,
module.exports = {
  ignoreWarnings: [
    {
      module: /module2\.js\?[34]/ // A RegExp
    },
    {
      module: /[13]/,
      message: /homepage/
    },
    /warning from compiler/,
    (warning) => true
  ],
  plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].css',
      chunkFilename: '[id].css'
    }),
    new CopyPlugin({
      patterns: [
        {
          from: './app/Views/kewilayahan/dist/*.*',
          to: path.resolve('./public/kpdl/dist/[name][ext]')
        }
      ]
    })
  ],
  entry: {
    kpdl: './app/Views/kewilayahan/kytp/kpdl.js',
    monitoring: './app/Views/kewilayahan/monitoring/index.js',
    'monitoring-perubahan-perilaku': './app/Views/kewilayahan/monitoringPerubahanPerilaku/index.js',
    peta: './app/Views/kewilayahan/peta/peta.js'
  },
  output: {
    publicPath: '/engineN/public/kpdl/dist/',
    path: path.resolve('./app/Views/kewilayahan/dist'),
    filename: '[name].js'
  },
  optimization: {
    minimize: false
  },
  module: {
    rules: [
      {
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-react'],
            plugins: ['@babel/plugin-proposal-optional-chaining', '@babel/plugin-proposal-nullish-coalescing-operator']
          }
        }
      },
      {
        test: /\.s[ac]ss$/i,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath: ''
            }
          },
          'css-loader',
          'sass-loader'
        ]
      },
      {
        test: /\.css$/i,
        // use: ['style-loader', 'css-loader']
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              publicPath: ''
            }
          },
          {
            loader: 'css-loader',
            options: {
              url: {
                filter: (url) => {
                  if (/^data:(application\/font-woff|image|font)/i.test(url)) {
                    return false
                  }
                  return true
                }
              }
            }
          }
        ]
      },
      {
        test: /Image\.(png|jpe?g|gif)$/i,
        use: [
          {
            loader: 'file-loader'
          }
        ]
      }
    ]
  },
  // mode: 'production'
  mode: 'development'
  // devServer: {
  //   static: {
  //     directory: path.join(__dirname, './public/kpdl/dist'),
  //     serveIndex: false
  //   },
  //   compress: false,
  //   hot: true,
  //   port: 9000,
  //   proxy: [
  //     {
  //       context: ['/engineN/geoserver'],
  //       target: 'http://localhost',
  //       changeOrigin: false
  //     }
  //   ]
  // }
}