Stolz / Assets

An ultra-simple-to-use assets management library for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How it pipeline multiple assets, how determines the sorting ?

ozmu opened this issue · comments

Hi Stolz,
First of all, thanks for this great package.

I'm using theme. But, the theme's javascript files and webpack's js/app.js file conflicts.
In app/Http/Controllers/HomeController:

     Assets::add([
        'js/app.js',
        'assets/js/assets.js',
        'assets/js/script.js',
        'assets/js/docs.js',
    ]);

In resources/views/layouts/docs.blade.php:

    {!! Assets::js() !!}

When generate js files:

    <script type="text/javascript" src="/js/app.js"></script>
    <script type="text/javascript" src="/assets/js/assets.js"></script>
    <script type="text/javascript" src="/assets/js/docs.js"></script>
    <script type="text/javascript" src="/assets/js/script.js"></script>

In this case, I want to assets/js/script.js generate before assets/js/docs.js. How can do it ?

commented

Hi @ozmu

The assets list is a FIFO queue so the assets will be generated in the order you add them to the list. What you are experiencing shouldn't happen. I've tried to reproduce your same scenario but the behavior I get seems correct:

require __DIR__ . '/vendor/autoload.php';
$assets = new Stolz\Assets\Manager;
$assets->add(['js/app.js', 'assets/js/assets.js', 'assets/js/script.js', 'assets/js/docs.js']);
echo $assets->js();

prints

<script src="js/js/app.js" type="text/javascript"></script>
<script src="js/assets/js/assets.js" type="text/javascript"></script>
<script src="js/assets/js/script.js" type="text/javascript"></script>
<script src="js/assets/js/docs.js" type="text/javascript"></script>

Also, there are several automatic tests in place that tests exactly that and they are all passing.
To be honest, seems quite unlikely the assets order gets altered considering the assets list is a plain PHP array and assets get pushed at the end of the list as they are added. Could you please send me your full configuration to see if I can replicate the problem?

commented

@ozmu please let me know if there are any updates and I'll reopen the issue