如何使web_ui自动编译css文件

时间:2013-06-24 12:41:19

标签: dart dart-webui

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

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

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

1 个答案:

答案 0 :(得分:2)

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

通过将编译器传递给full标志,可以实现CSS文件的自动编译:

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

machine标志告诉编译器将消息打印到Dart编辑器控制台。有关标记的完整列表,请参阅Build.dart and the 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']);
}