J'ai créé une application web en React avec Create React App. Quelque part dans mon processus de développement, le temps de lancement de mon serveur de développement a énormément augmenté. Il faut maintenant environ 8 minutes pour le lancer. J'utilise Craco pour modifier ma configuration Webpack et pour compiler mon thème Less, mais je peux confirmer que le lancement sans Craco prend autant de temps. Lorsque je lance mon serveur avec Craco et Webpackbar, je peux dire que la majorité du temps de lancement est pris par babel-loader qui transpose les fichiers dans node_modules, donc je soupçonne qu'il s'agit d'un problème avec mes configurations ou mes dépendances. Le projet est écrit en TypeScript et mes deux plus grandes dépendances en plus de React sont Ant Design (antd) et Ant Design Icons (@antd/icons).
J'ai inclus mon package.json et craco.config.js ainsi que les dépendances de mes fichiers ci-dessous pour montrer l'arbre de dépendance :
//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";
Comment puis-je modifier ma configuration Craco pour avoir un temps de lancement du serveur de développement raisonnable ?