The new build package looks awesome, but I'm really confused on how to actually use it...

91 views
Skip to first unread message

Ryan Gonzalez

unread,
Dec 8, 2017, 1:00:05 PM12/8/17
to misc
Okay, so I've been trying to learn how to use the new build package:

https://github.com/dart-lang/build

And it looks awesome! However, I'm having a hard time trying to figure out
how to use this from a practical standpoint.

Okay, so most Dart transformers do something like this:

- take input.dart
- do something with out
- output a new input.dart

Now, the build package has a requirement that builders can't overwrite
their inputs...which makes total sense. However, this is where things get
confusing.

Say I have index.html:


<head>
<title>something</title>
<script src="index.dart"></script> <!-- look here -->
<script src="packages/browser/dart.js"></script>
</head>

Now, I want to run some transformation on index.dart as part of the build
process. However, since I can't replace index.dart, I have to write it out
to another file ...let's say it's index.processed.dart. Now, the HTML file
needs to be rewritten to reference the new file...but files can't be
overwritten. So in the end, I'd have to change index.html to something
else.

Of course, this isn't really that practical. I'm pretty sure there has to
be some way of doing this simple workflow, but I just can't figure out how.
:/

--
Ryan (ライアン)
Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else
https://refi64.com/

Bob Nystrom

unread,
Dec 8, 2017, 3:45:19 PM12/8/17
to General Dart Discussion, Jacob Macdonald, Nate Bosch
+Jake and Nate, who work on this...

Yeah, that is a challenge. For what it's worth, this use case is exactly why the old barback build system does let you overwrite files, even though supporting that causes a lot of other complexity.

I'm not sure what the idiomatic solution for this is with the new build system. I think what you'd probably do is in your index.html file, reference the file that will be built — the output file at its new location — and not the original input file.

Cheers!

– bob

Nate Bosch

unread,
Dec 11, 2017, 5:17:52 PM12/11/17
to Bob Nystrom, General Dart Discussion, Jacob Macdonald
This challenge definitely has come up before and it usually fits into a pattern:

User has written some code and their entrypoint (index.dart, index.html, etc) refers only to code they've written.
Builder wants to generate new code but without being referenced it can't be used.

Angular, package:initialize, and dart_to_js_script_rewriter all fit this pattern. For the most part, these patterns show up when there are two ways of executing the code (mirrors vs no mirrors, dartium running dart vs chrome running js) and in most cases the direction we're moving is to have only 1 way for executing the code.

Most of the time what this means is that the user needs to write something a bit different, and reference files they didn't write. In your example we'd ask the user to write their html with <script src="index.processed.dart">

We've discussed finding some way to model this with package:build but so far we have not found anything satisfying, so we're sticking doing the changes manually for now.

Nate Bosch

unread,
Dec 11, 2017, 5:17:54 PM12/11/17
to Dart Misc
This challenge definitely has come up before and it usually fits into a pattern:

User has written some code and their entrypoint (index.dart, index.html, etc) refers only to code they've written.
Builder wants to generate new code but without being referenced it can't be used.

Angular, package:initialize, and dart_to_js_script_rewriter all fit this pattern. For the most part, these patterns show up when there are two ways of executing the code (mirrors vs no mirrors, dartium running dart vs chrome running js) and in most cases the direction we're moving is to have only 1 way for executing the code.

Most of the time what this means is that the user needs to write something a bit different, and reference files they didn't write. In your example we'd ask the user to write their html with <script src="index.processed.dart">

We've discussed finding some way to model this with package:build but so far we have not found anything satisfying, so we're sticking doing the changes manually for now.

Reply all
Reply to author
Forward
0 new messages