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]: @modern-js/module-tools 开发组件库,热更新太卡 #5292

Open
GuoYiJi opened this issue Jan 23, 2024 · 10 comments
Open

[Bug]: @modern-js/module-tools 开发组件库,热更新太卡 #5292

GuoYiJi opened this issue Jan 23, 2024 · 10 comments
Labels
bug Something isn't working help wanted Extra attention is needed 👏 PR welcome

Comments

@GuoYiJi
Copy link

GuoYiJi commented Jan 23, 2024

版本信息

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 87.83 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 120.0.6099.234
    Edge: 120.0.2210.144
    Safari: 17.2.1
  npmPackages:
    @modern-js/eslint-config: 2.35.1 => 2.35.1
    @modern-js/module-tools: 2.35.1 => 2.35.1
    @modern-js/tsconfig: 2.35.1 => 2.35.1

问题详情

使用 @modern-js/module-tools 本地开发组件库的时候,每次更改代码保存 rebuild 的时候,都会耗尽 cpu 造成机器卡顿,如 vscode 卡死,可以观察下 vscode 反应跟底部 cpu 占用面板,请问那边项目文件多有遇到么,非常影响效率,请帮忙看下🙏

配置

import { moduleTools, defineConfig } from '@modern-js/module-tools';

export default defineConfig({
  plugins: [moduleTools()],
  buildPreset({ preset }) {
    const { NPM_COMPONENT } = preset;
    return NPM_COMPONENT.filter(e => e.format !== 'cjs').map(config => {
      config.define = {
        VERSION: '1.0.1',
      };
      return config;
    });
  },
  buildConfig: {
    asset: {
      svgr: true,
    },
    alias: {
      '@': './src',
    },
    style: {
      sass: {
        additionalData: `
          @use "@/styles/variables.scss" as *;
          @use "@/styles/mixins.scss" as *;
        `,
      },
    },
  },
});

录屏链接:https://www.zhihu.com/zvideo/1733153234569715712

复现链接

复现步骤

@GuoYiJi GuoYiJi added the bug Something isn't working label Jan 23, 2024
@10Derozan
Copy link
Member

Can you try to disable some task? Maybe it exist multiple watcher and occupy too much memory.
Remove buildPreset and only a esbuild task or tsc task.

@10Derozan
Copy link
Member

10Derozan commented Jan 24, 2024

Ideally, we should only enable one watcher and rebuild the all task, we need improve it next major version.
By the way, no much this feedback about this problem.

@GuoYiJi
Copy link
Author

GuoYiJi commented Jan 25, 2024

您可以尝试禁用某些任务吗?可能是存在多个watcher,占用内存过多。仅 删除esbuild 任务或 tsc 任务。您可以尝试取消某些任务吗?可能存在多个watcher,占用内存过多。删除并仅删除一个esbuild任务或tsc任务。关闭

只保留 esm 可以解决,问题出在最后一个任务,这个任务主要用来构建 typeing?我使用 esm 的任务并修改 dts 配置也可以输出 typeing

[
  {
    format: 'cjs',
    target: 'es6',
    buildType: 'bundleless',
    outDir: './dist/lib',
    dts: false,
  },
  {
    format: 'esm',
    target: 'es6',
    buildType: 'bundleless',
    outDir: './dist/es',
    dts: false,
  },
  {
    buildType: 'bundleless',
    outDir: './dist/types',
    dts: { only: true },
  },
]

@GuoYiJi
Copy link
Author

GuoYiJi commented Jan 25, 2024

您可以尝试禁用某些任务吗?可能是存在多个watcher,占用内存过多。仅 删除esbuild 任务或 tsc 任务。您可以尝试取消某些任务吗?可能存在多个watcher,占用内存过多。删除并仅删除一个esbuild任务或tsc任务。关闭

只保留 esm 可以解决,问题出在最后一个任务,这个任务主要用来构建 typeing?我使用 esm 的任务并修改 dts 配置也可以输出 typeing

[
  {
    format: 'cjs',
    target: 'es6',
    buildType: 'bundleless',
    outDir: './dist/lib',
    dts: false,
  },
  {
    format: 'esm',
    target: 'es6',
    buildType: 'bundleless',
    outDir: './dist/es',
    dts: false,
  },
  {
    buildType: 'bundleless',
    outDir: './dist/types',
    dts: { only: true },
  },
]

抱歉,看错了,ems 的 dts 设置 { only: true } 后,只会输出 typeing,没有构建的 js

@10Derozan
Copy link
Member

只跑输出类型的任务会卡吗,如果会的话那和 tsc 有关

@GuoYiJi
Copy link
Author

GuoYiJi commented Jan 25, 2024

只跑输出类型的任务会卡吗,如果会的话那和 tsc 有关

确实是,测试了下只跑这个任务就会卡

@10Derozan
Copy link
Member

tsc watch 的问题可以再研究一下,对于 module tools 本身或许可以细粒度划分一下 watch 命令,只 watch 某个或者某几个任务

@10Derozan 10Derozan added the help wanted Extra attention is needed label Jan 29, 2024
@FeSeason
Copy link

Ideally, we should only enable one watcher and rebuild the all task, we need improve it next major version. By the way, no much this feedback about this problem.

+1

@FeSeason
Copy link

是否可以开发watch相关的钩子 做一些自定义的操作

@10Derozan
Copy link
Member

是否可以开发watch相关的钩子 做一些自定义的操作

欢迎直接贡献代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed 👏 PR welcome
Projects
None yet
Development

No branches or pull requests

3 participants