dart pub build:排除文件或目录

时间:2015-09-14 14:43:12

标签: dart dart-pub

在使用dart pub build构建Web应用程序时,我试图排除文件或目录列表。 使用此功能,如documentation

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

不起作用:

  

pubspec.yaml第10行第3行出错:“simple_transformer”不是依赖项。

     

- simple_transformer:

有没有办法(使用SDK 1.10.0)?

2 个答案:

答案 0 :(得分:2)

Sadly there is currently no support to mark files as ignored by pub build as Günter already mentioned. The .gitignore feature was removed as it was undocumented and caused more trouble than it solved.

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:

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:

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.

I created a pub package that contains the transformer, take a look here.

答案 1 :(得分:1)

simple_transformer是要通知以排除文件的转换器的名称。如果您要将此应用于dart2js,则需要使用名称$dart2js而不是simple_transformer
有关配置$dart2js的详细信息,请参阅https://www.dartlang.org/tools/pub/dart2js-transformer.html