thewebartisan7's avatar

Manage Assets with Laravel Mix on Package

How to manage assets inside a package with laravel mix?

0 likes
4 replies
manelgavalda's avatar

When you compile down your assets you just need to reference this assets in your view. If your assets are versioned, you can use the mix() helper to point to the versioned assets automatically:

<script src="{{ mix('/js/app.js') }}"></script>

Docs for compiling assets with mix: https://laravel.com/docs/5.7/mix

thewebartisan7's avatar

I know how to use mix from root of project. But I want to use from my custom package, that I have inside packages/vendorname/packagename

manelgavalda's avatar

@ZOROASTER - You don't need laravel-mix for a laravel package. You want laravel-mix just for the package development when compiling assets.

  • If you don't want your users to overwrite the files you can just have the compiled files in your package.

  • If you want your users to overwrite the assets, let them publish the assets and do what they want. Docs: https://laravel.com/docs/5.7/packages#public-assets

public function boot()
{
    $this->publishes([
        __DIR__.'/path/to/assets' => public_path('vendor/courier'),
    ], 'public');
}
thewebartisan7's avatar
thewebartisan7
OP
Best Answer
Level 14

I found what I looking for.

/// Load mix and mix-merge-manifest
const { mix } = require('laravel-mix');
require('laravel-mix-merge-manifest');


/// Allow merge manifest
mix.setPublicPath('../../public').mergeManifest();
1 like

Please or to participate in this conversation.