deployer icon indicating copy to clipboard operation
deployer copied to clipboard

[IMPROVEMENT] allow to split Magento2 static file deployment in frontend and adminhtml area

Open mautz-et-tong opened this issue 2 years ago • 2 comments

We have a case where we have 30 frontend languages but only 2 adminhtml languages.

That causes a big overhead when deploying static files.

My 5 minute idea hack for this would be the following improvement:

in the magento2.php replace ll 97.

desc('Deploys assets');
task('magento:deploy:assets', function () {

    $themesToCompile = '';
    if (count(get('magento_themes')) > 0) {
        foreach (get('magento_themes') as $theme) {
            $themesToCompile .= ' -t ' . $theme;
        }
    }

    run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}");
});

with:

// Deploy frontend and adminhtml together as default
set('split_static_deployment', false);

desc('Deploys assets');
task('magento:deploy:assets', function () {

    $themesToCompile = '';
    if (get('split_static_deployment')) {
        invoke('magento:deploy:assets:adminhtml');
        invoke('magento:deploy:assets:frontend');
    } elseif (count(get('magento_themes')) > 0 ) {
        foreach (get('magento_themes') as $theme) {
            $themesToCompile .= ' -t ' . $theme;
        }
        run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --content-version={{content_version}} {{static_content_locales}} $themesToCompile -j {{static_content_jobs}}");
    }
});

desc('Deploys assets for backend only');
task('magento:deploy:assets:adminhtml', function () {

    $themesToCompile = '';
    if (count(get('magento_themes_backend')) > 0 && get('split_static_deployment')) {
        foreach (get('magento_themes_backend') as $theme) {
            $themesToCompile .= ' -t ' . $theme;
        }
    }

    run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --area=adminhtml --content-version={{content_version}} {{static_content_locales_backend}} $themesToCompile -j {{static_content_jobs}}");
});

desc('Deploys assets for frontend only');
task('magento:deploy:assets:frontend', function () {

    $themesToCompile = '';

    if (count(get('magento_themes_frontend')) > 0 && get('split_static_deployment')) {
        foreach (get('magento_themes_frontend') as $theme) {
            $themesToCompile .= ' -t ' . $theme;
        }
    }

    run("{{bin/php}} {{release_or_current_path}}/bin/magento setup:static-content:deploy --area=frontend --content-version={{content_version}} {{static_content_locales_frontend}} $themesToCompile -j {{static_content_jobs}}");
});

I need to add a fallback for

  • static_content_locales being fallback to static_content_locales_backend and static_content_locales_frontend
  • magento_themes being fallback to magento_themes_backend and magento_themes_frontend

Possible new configs: set('magento_themes_backend',['Magento/backend']); set('magento_themes_frontend',['Customer/foo']); set( 'static_content_locales_frontend', 'en_US de_DE es_ES es_CL nl_NL it_IT fr_FR fi_FI en_GB tr_TR pl_PL [...] foo_FOO' ); set( 'static_content_locales_backend', 'en_US de_DE' );

If this idea get some likes, I will a better version as PR ;-)

mautz-et-tong avatar Sep 21 '22 15:09 mautz-et-tong

I'm on the fence about this - we also do a split generation of the frontend and adminhtml but I feel like we're more an exception than the default.

Since this recipe is used by a lot of people I'd lean more to keeping the simple version as the default. If you're like us, you probably already have some overrides in place anyway (we use the default recipe and override a lot of tasks).

Then again, having it backwards compatible with the current default shouldn't introduce problems when done correctly. But again, I'm not sure how many people will benefit from this added complexity.

peterjaap avatar Sep 22 '22 08:09 peterjaap

That is why I used a not changing fallback as a solution. So, when you don't change a thing, you stay in your routine. You need to actively switch 'split_static_deployment' to true to get different behaviour. But then you profit of the split when configured right.

mautz-et-tong avatar Sep 22 '22 09:09 mautz-et-tong

if this https://github.com/deployphp/deployer/pull/3326 is merged, this issue can be closed as well.

akosglue avatar Mar 10 '23 10:03 akosglue