如何减少Flutter的build_runner构建时间

发布于 2025-02-13 18:07:54 字数 128 浏览 0 评论 0原文

我的项目越来越大,每次我运行build_runner时,构建都需要太多时间。我减少构建时间的想法是仅构建实际需要构建的文件,而这些文件是我当前功能目录的文件。

是否可以仅适用于单个文件夹或一个文件来运行build_runner?

My project is getting really big and every time I run build_runner it takes too much time to build. My idea to reduce the build time is to build only files that actually need building and those are files of my current feature directory.

Is there a way to run build_runner only for a single folder or a single file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆流 2025-02-20 18:07:54

您可以在构建器中设置启用的true或fals。

targets:
  $default:
    builders:
      your_builder:
        generate_for:
          - lib/**/*.dart
      mockito:mockBuilder:
        enabled: false
      json_serializable:
        enabled: true

You can set enabled true or false in builder .

targets:
  $default:
    builders:
      your_builder:
        generate_for:
          - lib/**/*.dart
      mockito:mockBuilder:
        enabled: false
      json_serializable:
        enabled: true
面如桃花 2025-02-20 18:07:54

我发现使用generate_for单个构建器是提高速度的好方法。
您可以:

  1. 将相关文件移动到专用文件夹中,然后
$default:
  builders:
    your_builder:
      generate_for:
        - lib/path/to/folder/**.dart
  1. 在文件中添加一个特殊的扩展名。例如,对于json_serializable,我用.json.dart给出文件,然后我使用lib/**。json.dart用于generate_for >。

更多信息在此处: https://codewithandrea.com /提示/加速代码生成型跑步者 - dart-flutter/

I found that using generate_for for individual builders is a good way to increase the speed.
You could:

  1. Move the related files in a dedicated folder and then
$default:
  builders:
    your_builder:
      generate_for:
        - lib/path/to/folder/**.dart
  1. Add a special extension to your files. For example, for json_serializable, I suffix my files with .json.dart and then I use lib/**.json.dart for the generate_for.

More info here: https://codewithandrea.com/tips/speed-up-code-generation-build-runner-dart-flutter/

离不开的别离 2025-02-20 18:07:54

您可以考虑使用构建过滤器

这是文章更聪明。

You can consider running the build runner on a subset of the files using the build-filter.

Here's an article where the author walks you through creating a shell script that runs the buildrunner more smartly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文