这是我的(简化的)文件夹结构:
/
pubspec.yaml
build/
client.dart.js, etc
lib/
game.dart
server/
server.dart
web/
client.dart
canvas.dart
index.html
我正在使用“dartiverse search”示例中的代码来提供这些文件(简化):
var buildDirectory = new Http.VirtualDirectory(buildPath);
buildDirectory.jailRoot = false;
// Serve everything not routed elsewhere through the virtual directory.
buildDirectory.serve(router.defaultStream);
// Special handling of client.dart. Running 'pub build' generates
// JavaScript files but does not copy the Dart files, which are
// needed for the Dartium browser.
router.serve("/client.dart").listen((request) {
Uri clientScript = Platform.script.resolve("../web/client.dart");
buildDirectory.serveFile(new File(clientScript.toFilePath()), request);
});
router.serve("/canvas.dart").listen((request) {
Uri clientScript = Platform.script.resolve("../web/canvas.dart");
buildDirectory.serveFile(new File(clientScript.toFilePath()), request);
});
router.serve("/lib/game.dart").listen((request) {
Uri clientScript = Platform.script.resolve("../lib/game.dart");
buildDirectory.serveFile(new File(clientScript.toFilePath()), request);
});
我的问题是:有没有更好的方法来为项目中的文件提供服务,其中 .dart 文件在 lib/ 和 web/ 文件夹之间拆分?上面显示的方法可能适用于一些文件,但如果我的项目增长并且我有 50 个这样的 .dart 文件怎么办?