HTML 模板的良好资源打包程序?

发布于 2024-12-28 05:22:24 字数 561 浏览 3 评论 0原文

我正在编写一个足够复杂的 Web 应用程序,它需要大量的 HTML 模板(特别是它们是下划线模板,但这部分并不重要)。

我真的希望能够编写如下所示的模板文件:

fooTemplate:
<div class="foo">
   <div class="bar"><%=name %></div>
</div>

并将所有模板文件转换为如下所示的单个 JS 文件:

window.templates = {}
...
templates.fooTemplate = '<div class="foo"><div class="bar">...</div>';

理想的属性:

  • 有某种方法来指定每个模板的名称
  • 去掉不必要的 名称所有模板文件中的空格
  • 将所有模板文件连接成一个单一的 JS 文件
  • 监视目录并在文件更改时自动更新

有没有什么东西可以做这些事情?

I'm writing a web app that's complicated enough that it needs a large family of HTML templates (specifically they're underscore templates, but that part doesn't really matter).

I really want to be able to write template files that look like the following:

fooTemplate:
<div class="foo">
   <div class="bar"><%=name %></div>
</div>

And have it turn all of my template files into a single JS file that looks like this:

window.templates = {}
...
templates.fooTemplate = '<div class="foo"><div class="bar">...</div>';

Ideal properties:

  • Has some way to specify the name of each template
  • Strips unnecessary whitespace from all template files
  • Concatenates all template files into a single, monolithic JS file
  • Watches a directory and auto-updates when files change

Is there anything out there does does any of these things?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀟灑尐姊 2025-01-04 05:22:24

您不太可能找到一个可以完成您列出的所有操作的全面解决方案,不可避免地会“需要进行一些组装”(如果没有,我很想听听)。

  • 在 Rails 世界中, Jammit 将执行您所描述的许多操作。虽然它似乎与 Rails 紧密耦合,但我不是 Rails 专家,所以我无法建议(ab)使用不同的堆栈有多么困难。
  • 在 Django 世界中,有 django-asset-packager,但它只提到了 CSS/ JavaScript。
  • 基于 wrguard 用于目录监视,结合 Make/Rake/Paver/Cake/Ant 任务来处理您的模板。我曾经按照这些思路做了一个临时解决方案,它甚至没有花费半个工作日。
  • 您还可能在 capt 中找到一些灵感。

You're unlikely to find a comprehensive solution that does everything you list, there will inevitable be "some assembly required" (if not, I'd love to hear about it).

  • In the Rails world, Jammit will do a lot of what you describe. It seems quite tightly coupled to Rails though, but I'm no Rails expert so I can't advice on how difficult it is to (ab)use with a different stack.
  • In the Django world, there's django-asset-packager, but it only mentions CSS/Javascript.
  • It's probably not too much work to roll your own based on wr or guard for directory watching combined with Make/Rake/Paver/Cake/Ant tasks to process your templates. I did an ad-hoc solution along those lines once and it didn't even consume half a working day.
  • You might also find some inspiration in capt.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文