dart - 如何在 Assets 更改时自动运行变压器

标签 dart windows-7-x64 watch dart-pub

Barback package描述:

An asset build system. Given a set of input files and a set of transformations (think compilers, preprocessors and the like), will automatically apply the appropriate transforms and generate output files. When inputs are modified, automatically runs the transforms that are affected. Runs transforms asynchronously and in parallel when possible to maximize responsiveness.

Docs on assets and transformers say:

For pub serve, the transformers run when the dev server starts up and whenever a source asset changes. The pub build command runs the transformers once and then exits.

So I took this example:

// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:barback/barback.dart';
import 'package:markdown/markdown.dart';

import 'dart:async';

class ConvertMarkdown extends Transformer {

  // A constructor named "asPlugin" is required. It can be empty, but
  // it must be present. It is how pub determines that you want this
  // class to be publicly available as a loadable transformer plugin.
  ConvertMarkdown.asPlugin();

  // Any markdown file with one of the following extensions is
  // converted to HTML.
  String get allowedExtensions => ".md .markdown .mdown";

  Future apply(Transform transform) {
    return transform.primaryInput.readAsString().then((content) {

      // The extension of the output is changed to ".html".
      var id = transform.primaryInput.id.changeExtension(".html");

      String newContent = "<html><body>"
                        + markdownToHtml(content)
                        + "</body></html>";
      transform.addOutput(new Asset.fromString(id, newContent));
    });
  }
}

它按 pub build 的预期运行,但除了打印之外,对 pubserve 不执行任何操作:

Build completed successfully

每次我更改目录中的任何文件(不仅仅是适当的 Assets )时。

After reading this我认为 Dart 在 Windows 平台上观看文件(不仅仅是目录)时存在一些问题。

最佳答案

确实,pubserve 在每次文件修改后都会运行转换器。但与 pub build 相比,它不会将结果输出到 build/ 文件夹。 pubserve 是一个开发服务器,因此您需要通过 HTTP 请求资源,例如在浏览器中。

请参阅pub serve文档以获取更多详细信息

关于dart - 如何在 Assets 更改时自动运行变压器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24224732/

相关文章:

flutter - PageView 内部的 GridView 抖动

flutter - 关闭抽屉后重新聚焦 TextField

dart - 有谁知道如何向 Cupertino SliverAppBar 添加渐变背景?

c++ - 编译 DirectX11 着色器文件

javascript - URL 正则表达式由 regex buddy 传递,但被 Dart 失败

python-2.7 - 64 位 Windows 7 上的 Python 32 或 64?安装 easy_install 会有什么影响?

javascript - AngularJS - 当触发变量在范围内更改时,我的错误消息不会更新?

Angularjs 观察不同 Controller 中的 ng-model 变化

javascript - 使用 webpack 观看目录

java - Do-While 循环 Java 输出错误