I have created a web application in React with Create React App. Somewhere in my development process, the launch time for my development server grew tremendously. It now takes about 8 minutes to launch. I am using Craco to modify my Webpack config and to compile my Less theme, but I can confirm that launching without Craco takes just as long. I can tell when I run my server with Craco and Webpackbar that the majority of the launch time is taken by babel-loader transpiling files in node_modules, so I suspect that this is either a problem with my configs or my dependencies. The project is written in TypeScript and my two biggest dependencies besides React are Ant Design (antd) and Ant Design Icons (@antd/icons).
I've included my package.json and craco.config.js as well as the dependencies of my files below to show the dependency tree:
//package.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@ant-design/icons": "^4.7.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/user-event": "^12.8.3",
"antd": "^4.17.2",
"axios": "^0.23.0",
"craco-less": "^1.20.0",
"rc-footer": "^0.6.6",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^5.3.0",
"react-syntax-highlighter": "^15.4.4",
"web-vitals": "^1.1.2"
},
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@craco/craco": "^6.4.3",
"@types/antd": "^1.0.0",
"@types/react-router-dom": "^5.1.9",
"@types/react-syntax-highlighter": "^13.5.2",
"@types/webpack-bundle-analyzer": "^4.4.1",
"@types/webpackbar": "^4.0.2",
"craco-antd": "^1.19.0",
"react-scripts": "4.0.3",
"webpack-bundle-analyzer": "^4.5.0",
"webpackbar": "^5.0.0-3"
}
}
//craco.config.js
const CracoAntDesignPlugin = require( "craco-antd" )
const WebpackBar = require( "webpackbar" )
const { BundleAnalyzerPlugin } = require( "webpack-bundle-analyzer" )
const path = require( "path" )
const { getThemeVariables } = require( "antd/dist/theme" )
module.exports = {
eslint: {
enable: false // This doesn't seem to do anything, either. I still get eslint warnings after launching.
},
webpack: {
cacheDirectory: true, // I'm not sure if this has any effect.
plugins: [
// @ts-ignore
new WebpackBar( { profile: true } ),
new BundleAnalyzerPlugin(
{
openAnalyzer: false,
analyzerMode: "static",
reportFilename: path.join( __dirname, "build", "bundle_analysis.html" )
}
)
]
},
plugins: [
{
plugin: CracoAntDesignPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: getThemeVariables( {
dark: true
} )
}
}
}
}
]
}
//Imports in index.tsx
import React, { createElement, lazy, Suspense, useEffect, useState } from "react";
import ReactDOM from "react-dom";
import PropTypes, { InferProps } from "prop-types";
import {
BrowserRouter,
Switch,
Route,
Redirect,
NavLink,
useRouteMatch
} from "react-router-dom"
import { Col, Empty, Layout, Menu, Row, Skeleton } from "antd"
import { MenuOutlined } from "@ant-design/icons"
import { Callback, Repeat } from "./Utils"
import Header from "./Header"
import Footer from "./Footer"
import "./index.less"
import "rc-footer/assets/index.css"
import reportWebVitals from "./reportWebVitals"
//Imports in Header.tsx
import { useEffect, useState } from "react"
//Imports in Footer.tsx
import { Button, Card, Space } from "antd"
import useBreakpoint from "antd/lib/grid/hooks/useBreakpoint"
import RCFooter from "rc-footer"
//Imports in MyAccount.tsx
import { Button, Card, Col, Form, Input, Row } from "antd";
//Imports in Utils.tsx
import { useEffect } from "react"
import PropTypes, { InferProps } from "prop-types"
//Imports in index.less
@import "normalize.css";
@import "~antd/dist/antd.less";
@import "~antd/dist/antd.dark.less";
How can I modify my Craco config to have a reasonable dev server launch time?