如何使用dart包部署dart Web应用程序?

时间:2013-03-06 08:32:03

标签: dart dart2js

考虑以下dart网络应用:

import "dart:html";
// assume this is a custom library hosted somewhere on github, i.e. 
// there is a pubspec.yaml entry
//
// dependencies:
//    my_hello:
//      git: http://github.com/foo/my_hello.git
//
import "package:my_hello/my_hello.dart" as hello;

main() {
  query("#message").innerHtml = hello.message;
}

如何在Web服务器上的某个位置部署它(例如作为github页面),以便它可以在Dartium中用作基于dart的Web应用程序?

  1. 我是否必须在Web服务器上创建目录packages
  2. 我是否必须将包my_hello.dart复制到网络服务器?

    packages/my_hello/...

    或者Dartium是否能够解析给定pubspec.yaml的依赖关系?

4 个答案:

答案 0 :(得分:6)

目前,您需要部署packages个文件夹以及您的代码。 Dartium不使用pubspec.yaml

目前正在进行中,有一个dart2dart工具,它与dart2js做类似的事情 - 树摇动,缩小,并将所有代码整合到一个可部署的源文件中。有关说明,请参阅此dartbug issue,并在google群组中查看此recent discussion

这可能是pub deploy方案的一部分,该方案将用于打包您的应用以在Web服务器上进行部署。

另见:what could be a deployment strategy with pubspec on dart 并且:Creating a Javascript deployment set from Dart2js output

更新Dartbug 6006目前正在进行中,并说它的工作原理如下:

  

它会将“web”中的所有内容复制到deploy目录中,在所有入口点上运行dart2dart和dart2js,并清理Dart源文件。这将生成一个无需任何额外步骤即可提供的目录。

答案 1 :(得分:3)

使用:

$ pub build [--no-minify]
  

准备好部署网络应用时使用pub build。当您运行pub build时,它会为当前包及其所有依赖项生成资产,并将它们放入名为build的新目录中。

自:

https://plus.google.com/+SethLadd/posts/ZVw5EFX355z

答案 2 :(得分:2)

我个人一直在使用rsync,因为它简单快速

cd web
rsync -RLr . ../../deploy/

答案 3 :(得分:0)

这是一个实用程序脚本,它将Web应用程序所依赖的包复制到部署目录 - 请参阅Gist