Search code examples
dartdart2js

how to deploy dart web app with dart packages?


Consider the following dart web app:

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;
}

How to deploy it somewhere on a web server (for example as github pages), such that it can be used as dart based web app in Dartium?

  1. Do I have to create a directory packages on the web server?
  2. Do I have to copy the package my_hello.dart to the web server?

    packages/my_hello/...

    Or is Dartium able to resolve the dependencies given a pubspec.yaml ?


Solution

  • At the moment, you need to deploy the packages folders, along with your code. Dartium doesn't use the pubspec.yaml

    Currently in progress, there is a dart2dart tool, which does a similar thing to dart2js - tree shaking, minification, and bringing all the code into a single deployable source file. See this dartbug issue for instruction and this recent discussion on google groups.

    This will likely form part of the pub deploy scenario, which will be used to package your app for deployment on a web server.

    See also: what could be a deployment strategy with pubspec on dart and: Creating a Javascript deployment set from Dart2js output

    Update: Dartbug 6006 is being worked on at the moment, and says that it work like the following:

    It'll copy everything in "web" into a deploy directory, run dart2dart and dart2js on all the entrypoints, and clean up the Dart source files. This will produce a directory that can be served without any additional steps.