Another question about package:build on .html files

30 views
Skip to first unread message

Ryan Gonzalez

unread,
Mar 11, 2018, 6:07:54 PM3/11/18
to misc
A while back I asked something similar to this, but I have a different
question this time.

One of my transformers is an HTML preprocessor. Now, you can probably
already see the problem here. Since you can only generate new files,
not overwrite them, I can't rewrite the input HTML file. However,
paths with .html are (obviously) significant: rewriting index.html to
index.g.html just isn't ideal.

My question is: how should I handle this?

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

Matan Lurey

unread,
Mar 11, 2018, 6:13:55 PM3/11/18
to mi...@dartlang.org
Hi Ryan!

You're right that builds cannot overwrite or modify existing files. We've captured some Dart workarounds here:

Would love a bug (or a PR!) pushing us to document how to handle non-Dart assets. For your particular example, I've seen the following:

your_pkg/
  web/
    index.template.html

Where you write the final result as index.html (from index.template.html)

You could also create a separate template/ folder, i.e.:

your_pkg/
  web/
    template/
      index.html

... where it is copied into web/ with changes made. Hope that helps!

~ Matan

--
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
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Ryan Gonzalez

unread,
Mar 11, 2018, 6:26:23 PM3/11/18
to misc
Hmm...well, I'm doing this for my personal website, and I'm probably going to be running the preprocessor on every post, so renaming everything to .template.html wouldn't work...

Based on this, since package:build seems more flexible (outside of this) than Pub, could I just output the files to a directory other than 'web'? E.g., build/built-web or similar.

Matan Lurey

unread,
Mar 11, 2018, 6:31:51 PM3/11/18
to mi...@dartlang.org
Sure, you could totally do that. That was sort of my second example, i.e. write the following:

your_site/
  lib/
  web_template/

and have it output everything in web_template/ ==> web/

You probably want to reserve "web" for the actual (built) site assets. Build runner merges a combination of static and built assets together. So for example, if you have:

your_site/
  web/
    favicon.png
  web_template/
    index.html

Both "favicon.png" and "index.html" would be in your final (built) web directory. Does that help?
    

Ryan Gonzalez

unread,
Mar 11, 2018, 7:13:26 PM3/11/18
to misc
Yup...thanks!
Reply all
Reply to author
Forward
0 new messages