This extension allows you to automatically publish your assets with php artisan vendor:publish
with Laravel Mix. This is especially useful if you develop a package in the vendor
directory and want to push updated assets to the main application.
You can install the package with npm via the GitHub package registry. First, in the directory of your package.json
run:
echo "@mzur:registry=https://npm.pkg.github.com" >> .npmrc
Then run:
npm install --save-dev @mzur/laravel-mix-artisan-publish
Then require the extension in your Mix configuration:
const mix = require('laravel-mix');
require('@mzur/laravel-mix-artisan-publish');
...
Enable the extension by calling .publish()
at the end of your Mix chain:
mix.sass('resources/sass/app.scss', 'public/css').publish();
This will call the artisan vendor:publish
command of the main application.
To restrict publishing to a specific provider and/or tag, you may pass an object to .publish()
. You can also customize the relative path to the artisan file or disable the --force
argument:
mix.sass('resources/sass/app.scss', 'public/css').publish({
provider: 'My\\Package\\MyPackageServiceProvider',
tag: 'public',
path: '../../../artisan',
force: false,
});
And you're done!
The structure of this plugin was adapted from laravel-mix-artisan-serve.