metalsmith / js-bundle

A metalsmith plugin that bundles your JS using esbuild

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add jsbundle property to global metadata

webketje opened this issue · comments

Adding jsbundle property to the global metadata with a structure jsbundle: { 'source-file.js': { src: 'destination-file.js', async: }}}.

This allows templates to do:

{% for script in jsbundle %}
<script {% for attr,value in script %} {{attr}}="{{value}}"{% endfor %}></script>
{% endfor %}

As well as use a mechanism whereby file front-matter specifies the scripts to load:

---
scripts:
  - 'assets/js/common/source.js'
  - 'assets/js/app/source.js':
     async: true
     integrity: 'abcdefg'
---
{% for script in jsbundle %}
{% if typeof script === 'string' %}
<script src="{{ script }}"></script>
{% else %}
<script {% for attr,value in script %} {{attr}}="{{value}}"{% endfor %}></script>
{% endfor %}