How do I run `pub build` in a custom (non-release) mode while still minifying?

35 views
Skip to first unread message

Lucas Meadows

unread,
Jan 21, 2015, 6:59:51 PM1/21/15
to mi...@dartlang.org
I need to parameterize my pub builds from the command line, so hard-coding additional arguments into the pubspec won't work.

I see that I can say `pub build --mode=myMode1` or `pub build--mode=myMode2`, which allows me to parameterize my transformers, but it seems to prevent me from minifying my resultant JS.

I would like to find a way to both parameterize my transformers AND take advantage of dart2js minification. Is there some way to do this? (e.g., use --mode=release but pass custom BarbackSettings in via CLI somehow)


Bob Nystrom

unread,
Jan 29, 2015, 6:50:39 PM1/29/15
to General Dart Discussion
Sorry for the long delay!

On Wed, Jan 21, 2015 at 3:59 PM, Lucas Meadows <lmea...@sonardesign.com> wrote:
I need to parameterize my pub builds from the command line, so hard-coding additional arguments into the pubspec won't work.

I see that I can say `pub build --mode=myMode1` or `pub build--mode=myMode2`, which allows me to parameterize my transformers, but it seems to prevent me from minifying my resultant JS.

You can explicitly control minification of dart2js, by doing:

transformers:
- $dart2js:
    $minify: true

That will enable it for all modes, which may not be exactly what you want.

I would like to find a way to both parameterize my transformers AND take advantage of dart2js minification. Is there some way to do this? (e.g., use --mode=release but pass custom BarbackSettings in via CLI somehow)

Part of this limitation is deliberate. We in general don't want to encourage users to do a lot of build tweaking through command line flags because it encourages hard-to-reproduce build. If someone on your team doesn't realize they need to pass --enable-awesome-stuff --remove-broken-junk when they call pub build, they'll be confused that what they see is different from what you see. We want as much of that configuration in files that get checked into your repository. For transformers, that means in your pubspec.

That being said, some kind of flexibility is obviously useful, which is why we have modes. It's still really limited though because we haven't had much time to work on it, and we haven't had a clear picture of what kinds of options we want to expose.

Cheers,

- bob

Reply all
Reply to author
Forward
0 new messages