Is it feasible to use Laravel Mix in the latest Sage 10 release?

Hi everyone,

I know Bud has it’s advantages but I’m lagging behind in understanding how you’d move your entire development environment into WSL so I was wondering it it’d be feasible to just use Laravel Mix?

I went through the documentation of Acorn, Bud and Laravel Mix and all looks good, the only part I didn’t understand was this part:

/**
 * Register the theme assets.
 *
 * @return void
 */
add_action('wp_enqueue_scripts', function () {
    bundle('app')->enqueue();
}, 100);

As this calls this within Acorn

/**
 * Get bundle from manifest
 *
 * @param  string $bundle
 * @param  string $manifest
 * @return Bundle
 */
function bundle(string $bundle, ?string $manifest = null): Bundle
{
    if (! $manifest) {
        return \app('assets.manifest')->bundle($bundle);
    }

    return \app('assets')->manifest($manifest)->bundle($bundle);
}

Is it possible to just set the value of assets.manifest to mix-manifest.json?

Looking at this again is it just a case of passing through the name of the file as a string?

Digging further I see where the paths are set:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Default Assets Manifest
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default asset manifest that should be used.
    | The "theme" manifest is recommended as the default as it cedes ultimate
    | authority of your application's assets to the theme.
    |
    */

    'default' => 'theme',

    /*
    |--------------------------------------------------------------------------
    | Assets Manifests
    |--------------------------------------------------------------------------
    |
    | Manifests contain lists of assets that are referenced by static keys that
    | point to dynamic locations, such as a cache-busted location. We currently
    | support two types of manifest:
    |
    | assets: key-value pairs to match assets to their revved counterparts
    |
    | bundles: a series of entrypoints for loading bundles
    |
    */

    'manifests' => [
        'theme' => [
            'path' => get_theme_file_path('public'),
            'url' => get_theme_file_uri('public'),
            'assets' => get_theme_file_path('public/manifest.json'),
            'bundles' => get_theme_file_path('public/entrypoints.json'),
        ]
    ]
];

Can these be overwritten or updated?

I can’t offer any specific suggestions for you, but in case you’re not aware, early beta versions of Sage 10 used Mix. That codebase might give you some ideas. Here’s the last release that used Mix: Release Sage 10.0.0-beta.1 · roots/sage · GitHub

1 Like

I’ve updated some older v1, v2 acorn sites to v3, and continue to use mix on a few of them. However, I haven’t tried enqueuing them with bundle and instead continue to use wp_enqueue_script/style like the older mix versions of Sage 10 did.

If you publish/copy the config/assets.php file, you can change the manifests key to match your config. For example:

'manifests' => [
    'theme' => [
        'path' => get_theme_file_path('dist'),
        'url' => get_theme_file_uri('dist'),
        'assets' => get_theme_file_path('dist/mix-manifest.json'),
    ]
]
1 Like

Would this just go in the theme root? One further question, just more so out of curiosity.

I’m using Laragon because it has some nice features that I didn’t get out of the box with XXAMP, at least I think that’s what it was called?

Anyway, is everyone in this community just running Linux or Docker, or is it that WSL is okay once you figure it out?

Thanks.

Yep! Basically, copy this file to theme_root/config/assets.php.

As far as your other questions, I’m mostly Mac, so not the best resource on the Windows side. However, it looks like WSL is still the way for Windows. This topic seems to help clarify a bit more.

1 Like