0

我正在使用 web_ui 并且每当我更改其中的 CSS 文件时web/css/,除非我更改文件,否则它不会被编译web/index.html。我猜这是因为只有文件“web/index.html”被列为 build.dart 中的入口点。

但是将样式表添加到入口点列表不起作用。

有没有办法在每次更改 CSS 文件时自动编译它们而无需编辑.html文件?

4

1 回答 1

2

请记住,您可以编辑任何文件.dart.html文件,编译器将运行;它不必是入口点文件。

可以通过将full标志传递给编译器来实现 CSS 文件在更改时的自动编译:

build(['--machine', '--full'], ['web/index.html']);

machine标志告诉编译器将消息打印到 Dart 编辑器控制台。有关标志的完整列表,请参阅Build.dart 和 Dart Editor Build System

这种方法意味着每次更改文件时,您的整个项目都将重新构建,而不是通常的增量方法。如果您有一个大型项目,这可能需要一段时间。这是一个更全面的构建文件,它利用了增量编译,并且仅在更改 css 文件时才重新构建整个项目:

List<String> args = new Options().arguments;
bool fullRebuild = false;

for (String arg in args) {
  if (arg.startsWith('--changed=') && arg.endsWith('.css')) {
    fullRebuild = true;
  }
}

if(fullRebuild) {
  build(['--machine', '--full'], ['web/index.html']);
} else {
  build(args, ['web/index.html']);
}
于 2013-06-24T14:55:36.087 回答