const webpack = require("webpack");
const path = require("path");
const Dotenv = require("dotenv-webpack");

module.exports = (env) => {
  // Use env.<YOUR VARIABLE> here:
  //console.log("REACT_APP_DEPURAR: ", env.REACT_APP_DEPURAR); // 'local'

  return {
    entry: [
      //'react-hot-loader/patch',
      //'./../src/lib/index.js'
      path.resolve(__dirname, "./../src/lib/index.js"),
    ],
    output: {
      path: path.resolve(__dirname, "./../pkg"),
      filename: "is-componentes.js",
      library: {
        name: "@intersoft/componentes",
        type: "umd",
      },
      globalObject: `this`,
    },
    module: {
      rules: [
        {
          test: /\.(js|jsx)$/,
          use: "babel-loader",
          exclude: /node_modules/,
        },
        {
          test: /\.css$/,
          use: [
            "style-loader",
            {
              loader: "css-loader",
              options: {
                importLoaders: 1,
              },
            },
            "postcss-loader",
          ],
          exclude: /\.module\.css$/,
        },
        {
          test: /\.css$/,
          use: [
            "style-loader",
            {
              loader: "css-loader",
              options: {
                importLoaders: 1,
                modules: true,
              },
            },
            "postcss-loader",
          ],
          include: /\.module\.css$/,
        },
        {
          test: /\.less$/,
          use: ["style-loader", "css-loader", "less-loader"],
        },
        {
          test: /\.png$/,
          use: [
            {
              loader: "url-loader",
              options: {
                mimetype: "image/png",
              },
            },
          ],
        },
        {
          test: /\.scss$/,
          use: ["style-loader", "css-loader", "sass-loader"],
        },
        {
          test: /\.styl$/,
          use: ["style-loader", "css-loader", "stylus-loader"],
        },
        {
          test: /\.svg$/,
          use: "file-loader",
        },
      ],
    },

    plugins: [new Dotenv()],
  };
};
