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 UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const DashboardPlugin = require("webpack-dashboard/plugin"); const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const HappyPack = require("happypack"); const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); const {getClientEnvironment} = require("../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'; // Some apps do not use client-side routing with pushState. // For these, "homepage" can be set to "." to enable relative asset paths. const shouldUseRelativeAssetPaths = publicPath === "./"; // Get environment variables to inject into our app. const environ = getClientEnvironment(publicUrl); // Note: defined here because it will be used more than once. const cssFilename = "static/css/[name].[contenthash:8].css"; 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: {}, }; const rules = (env) => { // "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