PHPackages                             visuellverstehen/statamic-sourcestack - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. visuellverstehen/statamic-sourcestack

ActiveStatamic-addon

visuellverstehen/statamic-sourcestack
=====================================

A Statamic utility to only include css/js sources once.

v1.0.1(2y ago)11.3k↓100%MITPHPPHP ^8.0

Since Apr 11Pushed 1y ago7 watchersCompare

[ Source](https://github.com/visuellverstehen/statamic-sourcestack)[ Packagist](https://packagist.org/packages/visuellverstehen/statamic-sourcestack)[ RSS](/packages/visuellverstehen-statamic-sourcestack/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

SourceStack
===========

[](#sourcestack)

A Statamic utility to only include css/js sources once. This can be useful when you want to include dedicated files for specific partials/sets that would otherwise be included multiple times within a template.

Assume a basic Statamic blueprint with a replicator field `pagebuilder` that stacks sets in a template:

```

{{ pagebuilder }}
    {{ partial:if_exists src="sets/{type}" }}
{{ /pagebuilder }}
```

Further assume that there is an 'image' and a 'gallery' set, which both require dedicated javascript source files:

```

{{ once }}
    {{ push:scripts }}
        {{ vite src="resources/js/lightbox.js" }}
    {{ /push:scripts }}
{{ /once }}
```

```

    …

{{ once }}
    {{ push:scripts }}
        {{ vite src="resources/js/lightbox.js|resources/js/slider.js" }}
    {{ /push:scripts }}
{{ /once }}
```

By using the [`once`](https://statamic.dev/antlers#once) tag we try make sure to only include every source once. The `scripts` [stack](https://statamic.dev/antlers#stacks) is rendered in the layout.

However, if you add both an image and a gallery in a page, the `lightbox.js` script file will be added twice. The stack has no way to determine if a file was already added or not.

This is where SourceStack comes in.

How to Install
--------------

[](#how-to-install)

Run the following command from your project root:

```
composer require visuellverstehen/statamic-sourcestack
```

How to Use
----------

[](#how-to-use)

Let's modify the Statamic setup described above. Instead of using the `scripts` stack for our js source, we use the `sourcestack` tag included in this package:

```

{{ sourcestack src="resources/js/lightbox.js" }}
```

The tag collects all the sources throughout the template, making sure to add every source only once. Eventually, the `sourcestack:render` tag renders all collected sources as a vite source tag.

```

        {{ template_content }}

    {{ sourcestack:render }}

```

You can also use the tag alias `srcstk`. Sources can be added with the `src`, `source` or `file` parameter. Output can be generated with `render` or `vite`.

```
{{ srcstk src="lightbox.js" }}
{{ srcstk:vite }}
```

Like in a vite tag you can add multiple sources at once. Files must be separated by either a comma (`,`) or a pipe (`|`):

```
{{ srcstk src="lightbox.js|gallery.js" }}
```

### Dedicated stacks

[](#dedicated-stacks)

If you need multiple stacks for different sources, you can define dedicated stacks in the config file:

```
'stacks' => [
    'css' => [
        'base_dir' => 'resources/css/',
        'extension' => 'css',
    ]
],
```

For each stack you can optionally define a base directory and a file extension. Assuming the example above, the tag would be used like this:

```
{{ sourcestack:css src="gallery" }}
{{ sourcestack:render stack="css" }}
```

Please note that stacks can't be called `render` or any other strings that resolve to public function names of the `Sourcestack` tag class.

### Caveats

[](#caveats)

The way SourceStack is currently built requires the output to be called *after* all sources have been collected. You can however use Statamics [section and yield](https://statamic.dev/antlers#section-amp-yield) logic to move e. g. a stack with css files to the `` element:

```

    {{ yield:css-sources }}

    {{ section:css-sources }}
        {{ sourcestack:render stack="css" }}
    {{ /section:css-sources }}

```

Configuration
-------------

[](#configuration)

In addition to dedicated stacks (see above), you can configure the default base directory to be used for all regular source file paths in `config/sourcestack.php`.

More about us
-------------

[](#more-about-us)

- [www.visuellverstehen.de](https://visuellverstehen.de)

License
-------

[](#license)

The MIT license (MIT). Please take a look at the [license file](LICENSE.md) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

760d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/57dcd9370600b66b5ad7d99dd2b633e36d3a9458e656d650045f5f5eaf540e2d?d=identicon)[visuellverstehen](/maintainers/visuellverstehen)

![](https://www.gravatar.com/avatar/16b77aabdc6e9a51c63341aa7ad7b295b05bb05b1814b1218963a806f2341f68?d=identicon)[simonerd](/maintainers/simonerd)

---

Top Contributors

[![simonerd](https://avatars.githubusercontent.com/u/7941370?v=4)](https://github.com/simonerd "simonerd (8 commits)")[![runepiper](https://avatars.githubusercontent.com/u/4521147?v=4)](https://github.com/runepiper "runepiper (2 commits)")

---

Tags

cssJSviteaddonstatamic

### Embed Badge

![Health badge](/badges/visuellverstehen-statamic-sourcestack/health.svg)

```
[![Health](https://phpackages.com/badges/visuellverstehen-statamic-sourcestack/health.svg)](https://phpackages.com/packages/visuellverstehen-statamic-sourcestack)
```

###  Alternatives

[visuellverstehen/statamic-classify

A useful helper to add CSS classes to all HTML tags generated by the bard editor.

20116.8k](/packages/visuellverstehen-statamic-classify)[marcorieser/statamic-livewire

A Laravel Livewire integration for Statamic.

2381.5k10](/packages/marcorieser-statamic-livewire)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)[marcorieser/statamic-live-search

A Statamic Live Search realized with Laravel Livewire.

2210.5k](/packages/marcorieser-statamic-live-search)[visuellverstehen/statamic-picturesque

A Statamic tag for building HTML-only responsive images.

1016.9k](/packages/visuellverstehen-statamic-picturesque)[justkidding96/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

141.6k](/packages/justkidding96-aardvark-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
