gpt4 book ai didi

flutter build_runner : Build for specific file extensions in build. yaml

转载 作者:行者123 更新时间:2023-12-02 02:19:22 26 4
gpt4 key购买 nike

我想加快 build_runner 所需的构建时间,并且我还想在编辑没有任何文件可生成的文件时运行 build watch 时防止重新构建.

我知道这需要在 build.yaml 文件中进行编辑,但我什么也做不了。

这是我的构建文件

targets:
$default:
builders:
auto_route_generator:
generate_for:
include: [".route.dart"]
freezed:
generate_for:
include: [".model.dart"]
json_serializable:
generate_for:
include: [".model.dart"]
options:
explicit_to_json: true
include_if_null: false

即使尝试添加 enabled: false,这让我相信它会禁用该依赖项的构建,但什么也不做,文件继续生成。

也许我只是误解了应该如何使用构建文件...?

最佳答案

我找到了解决方案。这是非常接近 igokom 的答案。

targets:
$default:
builders:
auto_route_generator|autoRouteGenerator:
enabled: true
generate_for:
include:
- lib/infrastructure/routes/app_routes.routes.dart
# [exclude] is not needed if at least one path is provided
# in [include]. It will only target [include]d paths
# exclude:
# - ...

json_serializable:
enabled: true
generate_for:
include:
- lib/**.model.dart
- lib/**_bloc.dart
- lib/**_cubit.dart

options:
explicit_to_json: true
include_if_null: false
freezed|freezed:
enabled: true
generate_for:
include:
- lib/**.model.dart
- lib/**_bloc.dart
- lib/**_cubit.dart

injectable_generator|injectable_builder:
enabled: true
generate_for:
include:
- lib/**_bloc.dart
- lib/**_cubit.dart
- lib/**.dao.dart

injectable_generator|injectable_config_builder:
enabled: true
generate_for:
include:
- lib/infrastructure/injection/injection.dart

我之前收到一条警告,上面写着[警告] 在目标“my_app:my_app”中配置“auto_route_generator:auto_route_generator”,但这不是已知的生成器

我收到此错误是因为 auto_route 的生成器名称不是 auto_route_generator,而是 autoRouteGenerator

这些值可以在插件 build.yaml 文件中找到

builders:
# [autoRouteGenerator] is the name of the generator
# that needs to be referenced
autoRouteGenerator:
import: "package:auto_route_generator/builder.dart"
builder_factories: ["autoRouteGenerator"]
build_extensions: {'.dart': ['.gr.dart']}
auto_apply: dependents
build_to: source

Targets can be referred to in '$definingPackageName:$targetname'. When the target name matches the package name it can also be referred to as just the package name. One target in every package must use the package name so that consumers will use it by default. In the build.yaml file this target can be defined with the key $default or with the name of the package.

You can find more info about it herethis is a pretty good article这为 build.yaml 文件提供了一些很好的提示

关于 flutter build_runner : Build for specific file extensions in build. yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66664166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com