const path = require("path"); const webpack = require("webpack"); const HtmlWebpackPlugin = require("html-webpack-plugin"); // const FaviconsWebpackPlugin = require("favicons-webpack-plugin"); const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin"); const DashboardPlugin = require("webpack-dashboard/plugin"); const BundleAnalyzerPlugin = require("webpack-bundle-analyzer") .BundleAnalyzerPlugin; const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); const { loadEnv, getClientEnvironment } = require("./env"); function getConfig(env) { const { isProd, isDev } = loadEnv(env); const paths = require("../paths"); // Webpack uses `publicPath` to determine where the app is being served from. // It requires a trailing slash, or the file assets will get an incorrect path. const publicPath = paths.publicPath; // `publicUrl` is just like `publicPath`, but we will provide it to our app // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript. // Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz. const publicUrl = paths.publicUrl.slice(0, -1); // Source maps are resource heavy and can cause out of memory issue for large source files. const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== "false"; const shouldExtractCss = process.env.EXTRACT_CSS ? process.env.EXTRACT_CSS === "true" : isProd; // Get environment variables to inject into our app. const environ = getClientEnvironment(env, publicUrl); const postCssConfig = { loader: require.resolve("postcss-loader"), options: { // Necessary for external CSS imports to work // https://github.com/facebookincubator/create-react-app/issues/2677 ident: "postcss", plugins: () => [ require("postcss-flexbugs-fixes"), require("postcss-preset-env")({ stage: 0 }) ] } }; const sassConfig = { loader: require.resolve("sass-loader"), options: {} }; // "postcss" loader applies autoprefixer to our CSS. // "css" loader resolves paths in CSS and adds assets as dependencies. // "style" loader turns CSS into JS modules that inject