简体   繁体   English

dart pub build:排除文件或目录

[英]dart pub build: exclude a file or directory

I am trying to exclude a list of files or directories when building a web application with dart's pub build . 在使用dart的pub build Web应用程序时,我试图排除文件或目录的列表。 Using this, as suggested by the documentation : 根据文档建议使用此方法:

transformers:
- simple_transformer:
    $exclude: "**/CVS"

does not work: 不起作用:

Error on line 10, column 3 of pubspec.yaml: "simple_transformer" is not a dependency. pubspec.yaml的第10行第3列错误:“ simple_transformer”不是依赖项。

- simple_transformer: -simple_transformer:

Is there a way to do it (using SDK 1.10.0) ? 有没有办法做到这一点(使用SDK 1.10.0)?

Sadly there is currently no support to mark files as ignored by pub build as Günter already mentioned. 遗憾的是,如Günter所述,目前尚不支持将文件标记为pub build忽略。 The .gitignore feature was removed as it was undocumented and caused more trouble than it solved. .gitignore功能已被删除,因为该功能.gitignore记录,并且造成的麻烦超过了解决的范围。

But you can execlude files from the build output . 但是您可以从构建输出中执行文件。 This means that the files are still processed (and still take time to process =/ ) but aren't present in the output directiory. 这意味着文件仍在处理中(仍需要花费时间来处理= /),但在输出目录中不存在。 This is useful for generating a deployable copy of your application in one go. 这对于一次生成应用程序的可部署副本很有用。

In our application we use a simple ConsumeTransformer to mark assets as consumed so that they are not written to the output folder: 在我们的应用程序中,我们使用一个简单的ConsumeTransformer将资产标记为已消耗,以便不将其写入输出文件夹:

library consume_transformer;

import 'package:barback/barback.dart';

class ConsumeTransformer extends Transformer implements LazyTransformer {
  final List<RegExp> patterns = <RegExp>[];

  ConsumeTransformer.asPlugin(BarbackSettings settings) {
    if (settings.configuration['patterns'] != null) {
      for (var pattern in settings.configuration['patterns']) {
        patterns.add(new RegExp(pattern));
      }
    }
  }

  bool isPrimary(AssetId inputId) =>
      patterns.any((p) => p.hasMatch(inputId.path));

  void declareOutputs(DeclaringTransform transform) {}

  void apply(Transform transform) => transform.consumePrimary();
}

The consumer requires a list of regex patterns as an argument an consumes the matched files. 使用者需要一个正则表达式模式列表作为参数,以使用匹配的文件。 You need to add the transformer to you pubspec.yaml file as the last transformer: 您需要将转换器作为最后一个转换器添加到pubspec.yaml文件中:

transformers:
- ... # Your other transformers
- packagename/consume_transformer:
    patterns: ["\\.psd$"]

The example configuration ignores all files that have the psd extension, but you can add pattern as you need them. 示例配置忽略了所有具有psd扩展名的文件,但是您可以根据需要添加模式。

I created a pub package that contains the transformer, take a look here . 我创建了一个包含转换器的pub包,在此处查看

simple_transformer is the name of the transformer you want to inform to exclude the files. simple_transformer是要通知以排除文件的转换器的名称。 If you want to apply this to dart2js you need to use the name $dart2js instead of simple_transformer . 如果要将其应用于dart2js,则需要使用名称$dart2js而不是simple_transformer
For more details about configuring $dart2js see https://www.dartlang.org/tools/pub/dart2js-transformer.html 有关配置$dart2js更多详细信息,请参见https://www.dartlang.org/tools/pub/dart2js-transformer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM