Greetings noble Dartisans!
Deep and mysterious things have been afoot in pub-land. Nathan and I now have the first visible piece kinda-sorta working. When the next cut of the SDK comes out, there will be a pub serve command. (If you're on bleeding_edge, it's there now! The future is here!)
This spins up a local web server that serves up your package's files and those of everything it depends on. In particular:
- Files in your package's web/ directory. These get served at URLs that directly correspond to their file path. So http://localhost:8000/foo/bar.dart maps to yourpackage/web/foo/bar.dart.
- Files in your dependency's lib/ directories. Any URL that contains a "packages" directory is understood to resolve to this. So http://localhost:8000/whatever/packages/foo/bar.dart maps to lib/bar.dart in the "foo" package. This also works for files in your own package's lib/ directory, of course.
- Files in your dependency's asset/ directories.
What's that? A new exciting top level directory in your pub package? That's right! We're starting get support for non-Dart-file assets working. Any URL that contains an "assets" directory maps to this.
So http://localhost:8000/whatever/assets/foo/bar.png maps to asset/bar.dart in the "foo" package. This also works for files in your own package's asset/ directory too.
TL;DR: Run pub serve. Hit URLs. They map like:
localhost/<...>/packages/<pkg>/<path> -> <pkg>/lib/<path>
localhost/<...>/assets/<pkg>/<path> -> <pkg>/asset/<path>
localhost/<anything else> -> <your pkg>/web/<anything else>
What this generally means is you can spin up the server, hit an HTML file in your web/ directory, and "package:" imports will just work. Exciting bit: no symlinks were harmed in the production of this film. Since pub is responding to the request, it can just go find the package's real location itself.
What's next?
This is just the first visible piece of a lot of work we've been doing. This server sits on top of a library called barback that supports automatically transforming and generating assets on the fly. Pub serve doesn't currently have a way to provide transformers, but when it does, this server will also convert/transform/minify/compile/transpile all of your awesome content on the fly for you. When the source files change, it will automatically rebuild anything that's affected by the change.
Until we have that in place, though, pub serve is of limited use, but you're definitely welcome to start playing with it. File bugs when it breaks.
Anticipated questions!
What about pub deploy?
Soon, pub deploy will use the exact same barback backend for asset generation as pub serve. We'll be reusing all of the asset infrastructure for both your dev iteration loop and when you're ready to cut a final build.
This also means when user-defined transformers are in, you'll be able to hook them into your build step as well as your iteration loop.
What about the web server in the Editor?
We've got a bunch of work to do here (the Editor's server is way ahead of pub server) but our intent is to unify them into a single server once we can get to feature parity.
What do you call words like "pants" and "scissors" that have no singular form?
These are called "pluralia tantum", Latin for "plural only". Note that "pluralia tantum" is not a pluralia tantum. Its singular form is "plurale tantum".
Let us know if you have any other questions/comments/lavish praise/excoriations.
Cheers!
- bob