本文介绍了有不同的方式来为不同的环境有不同的配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个需要一些配置的应用。我现在的方式是有点hacky和繁琐 - 如果我在本地开发,我包括本地配置文件(一个dart文件,定义一些常量),如果部署,我包括一个不同的飞镖文件,用不同的值定义相同的常量。

I've created an app that requires some configuration. The way I'm doing it now is a bit hacky and tedious -- If I'm developing locally, I include the "local" configuration file (a dart file that defines a few consts) and if deploying, I include a different dart file that defines the same consts with different values.

理想情况下,将有一种方法来定义不同的配置,可以传递到pub服务/构建。看起来像这样一个明显的需要,我觉得一些可能已经存在,我只是没有经历它。在那儿?还是在作品中?

Ideally, there would be a way to define different configurations, which could be passed to pub serve/build. It seems like such an obvious need that I feel like something may already exist and I just haven't run across it yet. Is there? Or is something in the works?

推荐答案

,但您可以使用,例如 String

Pub build does not support defining environment variables but you can use fromEnvironment method, for example, on String:

String.fromEnvironment(String name, {String defaultValue})



或将其设为fancier ://www.dartlang.org/tools/pub/assets-and-transformers.htmlrel =nofollow>变压器。它将允许您自动(在pub构建或pub服务)从 pubspec.yaml 或另一个源获取设置,并将它们嵌入到代码中。例如,(it is transformer)包支持此表单的设置:

Or make it "fancier" with transformers. It will allow you to automatically(on pub build or pub serve) get settings from pubspec.yaml or another source and embed them in to the code. For example sass(it is transformer) package supports settings of this form:

:::yaml
transformers:
  - sass:
      executable: /path/to/sass     # Sass executable to use
      compass: true                 # Include compass
      line-numbers: true            # Include line numbers in output
      style: compact                # Style of generated CSS
      copy-sources: true            # Copy original .scss/.sass files to output directory

做几乎任何包括源代码修改。

With it you can do pretty much anything including source code modification.

这篇关于有不同的方式来为不同的环境有不同的配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:30
查看更多