Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 本地开发 hmr 速度缓慢 #1397

Closed
iwtem opened this issue Jan 22, 2024 · 5 comments
Closed

[Bug]: 本地开发 hmr 速度缓慢 #1397

iwtem opened this issue Jan 22, 2024 · 5 comments
Labels
🐞 bug Something isn't working need reproduction

Comments

@iwtem
Copy link

iwtem commented Jan 22, 2024

Version

System:
    OS: macOS 14.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 19.84 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 120.0.6099.234
    Safari: 17.2.1

Details

项目采用的是 monorepo 代码管理模式,大致的目录结构如下:

ui/
├── apps/
│   ├── main/ ----------------- 主应用
│   ├── app1/ ----------------- 应用 1
│   └── app2/ ----------------- 应用 2
├── packages/
│   ├── config/ -------------- 项目基础配置,包括 taidwind,rsbuild
│   ├── package1/ ------------ 组件库1
│   └── package2/ ------------ 组件库2
├── package.json ------------- 项目配置文件
├── pnpm-lock.yaml ----------- 依赖关系及版本锁
├── pnpm-workspace.yaml ------ monorepo workspace 配置
├── README.md ---------------- 项目说明与开发文档
└── tsconfig.json ------------ TypeScript 配置

在从 rspack 替换到 rsbuild 后,发现热更新的时间增加了 3.x,之前平均保持在 1s - 2s 之间,下面是现在的热更新的时间截图:
image

下面是我的 rsbuild 配置:

import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSvgr } from '@rsbuild/plugin-svgr';

export default defineConfig({
  source: {
    entry: { index: './src/index.tsx' },
  },
  output: {
    copy: ['public/favicon.ico', { from: 'public/img', to: 'img' }],
  },
  html: { template: 'public/index.html' },
  server: {
    historyApiFallback: true,
    proxy: {
      '/app': { target: 'https:xxx', changeOrigin: true },
    },
  },
  plugins: [pluginReact(), pluginSvgr({ svgDefaultExport: 'component' })],
  performance: {
    bundleAnalyze: process.env.BUNDLE_ANALYZE
      ? { analyzerMode: 'server', openAnalyzer: true }
      : undefined,
  },
});

有考虑过可能和 taildwind 的 content 配置有关系,但是删除部分元素后,没有明显的效果,下面是我的 taildwind 配置:

import type { Config } from 'tailwindcss';

const config: Config = {
  content: [
    'public/index.html',
    'src/**/*.tsx',
    '../app1/src/**/*.tsx',
    '../app2/src/**/*.{ts,tsx}',
    '../../packages/package1/src/**/*.tsx',
    '../../packages/package2/src/**/*.tsx',
  ],
  plugins: [],
};

export default config;

Reproduce link

1

Reproduce Steps

项目启动后,之后的热更新就会很慢

@iwtem iwtem added the 🐞 bug Something isn't working label Jan 22, 2024
@chenjiahan
Copy link
Member

可以把 tailwindcss 关闭再对比一下

@chenjiahan
Copy link
Member

没有复现链接的话很难排查

@iwtem
Copy link
Author

iwtem commented Jan 22, 2024

可以把 tailwindcss 关闭再对比一下

我把 taildwind 从 postcss.confing.js 配置中移除,发现几乎没效果,还是保持在 3s 以上,下面是 postcss.config 的配置:

module.exports = {
  plugins: {},
};

@chenjiahan
Copy link
Member

从现有信息看可能的原因有:

  • Rspack 版本不同导致的性能差异
  • 使用 SVGR 导致的性能开销

你可以按照这两个因素排查下

Copy link
Contributor

Hello @iwtem. Please provide a reproduction repository or online demo. For background, see Why reproductions are required. Thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working need reproduction
Projects
None yet
Development

No branches or pull requests

2 participants