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.
// 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/