You got (pub) served!

305 views
Skip to first unread message

Bob Nystrom

unread,
Aug 16, 2013, 6:37:06 PM8/16/13
to General Dart Discussion
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.

Awesome sauce!

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

jim.trainor.kanata

unread,
Aug 16, 2013, 7:12:22 PM8/16/13
to mi...@dartlang.org
What about directories other than web, lib, and asset?

What if we just want to resolve a plain old library that can be loaded today with "package:" import url as long as the path can be resolved in the packages directory?

Thanks
16 August, 2013 6:37 PM
--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

Filipe Morgado

unread,
Aug 17, 2013, 1:57:27 PM8/17/13
to mi...@dartlang.org
Sexta-feira, 16 de Agosto de 2013 23:37:06 UTC+1, Bob Nystrom escreveu:

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".

:D

Alex Tatumizer

unread,
Aug 17, 2013, 2:55:51 PM8/17/13
to mi...@dartlang.org
Very commendable initiative indeed!
Unfortunately, I'm too busy with pigeon breeding at the moment to fully appreciate this tour de force by Bob and Nathan, who apparently spent their entire vacation on this feature.
Will give it a try at the first opportunity.
Good job!!!


 

Alex Tatumizer

unread,
Aug 17, 2013, 7:56:35 PM8/17/13
to mi...@dartlang.org
> These are called "pluralia tantum"
I have to admit I at first mistakenly read it as  "pluralia tantrum", and was wondering whether the phrase really refers to my significant other. Need to refresh my Latin ASAP.


Bob Nystrom

unread,
Aug 19, 2013, 1:18:35 PM8/19/13
to General Dart Discussion

On Fri, Aug 16, 2013 at 4:12 PM, jim.trainor.kanata <jim.train...@gmail.com> wrote:
What about directories other than web, lib, and asset?

What if we just want to resolve a plain old library that can be loaded today with "package:" import url as long as the path can be resolved in the packages directory?

Unfortunately, that isn't a use case pub serve is designed to support. One of my goals here is to move away from "packages" directories, because relying on the file system for that abstraction layer has proven to be an unending source of bugs for us.

When we have support for user-defined transformation steps, it will probably be increasingly important for pub serve to be able to assume that "package:" URLs refer to actual pub packages so that we use that to find which transforms to apply to a given asset. That's probably vague, but we'll have more details here when we're a little farther along implementing transformers.

Cheers,

- bob

Reply all
Reply to author
Forward
0 new messages