const { smart } = require("webpack-merge");
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const base = require("./webpack.base.js");

module.exports = smart(base, {
  mode: "production",
  entry: "./src/index.jsx",
  devtool: "source-map",
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "../dist"),
    libraryTarget: "umd",
    library: "react-gui",
  },
  module: {
    rules: [
      {
        // exclude: /node_modules/,
        test: /\.css$/,
        loader: ["style-loader", "css-loader"],
      },
      {
        exclude: /node_modules/,
        test: /\.less$/,
        loader: [
          "style-loader",
          {
            loader: "css-loader",
            options: {
              modules: {
                localIdentName: "[name]_[local]_[hash:base64:5]",
              },
            },
          },
          "less-loader",
        ],
      },
    ],
  },
  resolve: {
    extensions: [".js", ".jsx"],
  },
  externals: {
    react: {
      root: "React",
      commonjs2: "react",
      commonjs: "react",
      amd: "react",
    },
    "react-dom": {
      root: "ReactDOM",
      commonjs2: "react-dom",
      commonjs: "react-dom",
      amd: "react-dom",
    },
    "react-draggable": {
      root: "ReactDraggable",
      commonjs2: "react-draggable",
      commonjs: "react-draggable",
      amd: "react-draggable",
    },
    "react-dnd": {
      root: "ReactDnD",
      commonjs2: "react-dnd",
      commonjs: "react-dnd",
      amd: "react-dnd",
    },
    "react-dnd-html5-backend": {
      root: "ReactDnDHTML5Backend",
      commonjs2: "react-dnd-html5-backend",
      commonjs: "react-dnd-html5-backend",
      amd: "react-dnd-html5-backend",
    },
    "@babel/runtime": {
      root: "BabelRuntime",
      commonjs2: "@babel/runtime",
      commonjs: "@babel/runtime",
      amd: "@babel/runtime",
    },
    "@easyv/react-icons": {
      root: "@easyv/react-icons",
      commonjs2: "@easyv/react-icons",
      commonjs: "@easyv/react-icons",
      amd: "@easyv/react-icons",
    },
    antd: {
      root: "antd",
      commonjs2: "antd",
      commonjs: "antd",
      amd: "antd",
    },
  },
  plugins: [
    new CleanWebpackPlugin(),
    // new BundleAnalyzerPlugin()
  ],
});
