Php artisan publish assets

Installation

Visit the composer.json file on Github for the complete list of package requirements.

Install The Package

 
1composer require livewire/livewire

Include The Assets

Add the following Blade directives in the head tag, and before the end body tag in your template.

 
1html>
2head>
3 .
4 @livewireStyles
5head>
6body>
7 .
8 @livewireScripts
9body>
10html>

You can alternatively use the tag syntax.

 
1livewire:styles />
2.
3livewire:scripts />

That’s it! That’s all you need to start using Livewire. Everything else on this page is optional.

Publishing The Config File

Livewire aims for «zero-configuration» out-of-the-box, but some users require more configuration options.

You can publish Livewire’s config file with the following artisan command:

 
1php artisan livewire:publish --config

Publishing Frontend Assets

If you prefer the JavaScript assets to be served by your web server not through Laravel, use the livewire:publish command:

 
1php artisan livewire:publish --assets

To keep the assets up-to-date and avoid issues in future updates, we highly recommend adding the command to the post-autoload-dump scripts in your composer.json file:

 
1
2 "scripts":
3 "post-autoload-dump": [
4 "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
5 "@php artisan package:discover --ansi",
6 "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
7 ]
8 >
9>

Configuring The Asset Base URL

By default, Livewire serves its JavaScript portion ( livewire.js ) from the following route in your app: /livewire/livewire.js .

The actual script tag that gets generated defaults to:

There are two scenarios that will cause this default behavior to break:

  1. You publish the Livewire assets and are now serving them from a sub-folder like «assets».
  2. Your app is hosted on a non-root path on your domain. For example: https://your-laravel-app.com/application . In this case, the actual assets will be served from /application/livewire/livewire.js , but the generated script tag, will be trying to fetch /livewire/livewire.js .

To solve either of these issues, you can configure the «asset_url» in config/livewire.php to customize what’s prepended to the src=»» attribute.

For example, after publishing Livewire’s config file, here are the settings that would fix the above two issues:

Источник

Php artisan publish assets

Published on December 7, 2016

The vendor:publish command is used to publish any assets that are available from third-party vendor packages. It provides a few options to help specifically choose which assets should be published. The following table lists and describes each of the options that are available for use:

Option Description
—force Supplying this flag will cause the vendor:publish command to overwrite any existing files.
—provider= Supplying a value for will cause the command to only publish the assets associated with the specified service provider.
—tag=* A list of tags to limit the types of assets that will be published.

The following service provider will be used to demonstrate the usage of the vendor:publish command:

 
1
2
3namespace App\Providers;
4
5use Illuminate\Support\ServiceProvider;
6
7class ExampleServiceProvider extends ServiceProvider
8
9 /**
10 * Bootstrap the application services.
11 *
12 * @return void
13 */
14 public function boot()
15
16
17 // Translations example.
18 // `translations` is the tag.
19 $this->publishes([
20 __DIR__.'/example/translations' =>
21 resource_path('lang/vendor/example')
22 ], 'translations');
23
24 // Migrations example.
25 $this->publishes([
26 __DIR__.'/example/migrations' => database_path('migrations')
27 ], 'migrations');
28
29 // Configuration example.
30 // `config` is the tag.
31 $this->publishes([
32 __DIR__.'config/example.php' => config_path('example.php')
33 ], 'config');
34
35 // Public assets example.
36 // `public` is the tag.
37 $this->publishes([
38 __DIR__.'example/assets' => public_path('vendor/example')
39 ], 'public');
40 >
41
42 /**
43 * Register the application services.
44 *
45 * @return void
46 */
47 public function register()
48
49 //
50 >
51>

The following command would simply attempt to publish the assets from all registered providers. The defaults will be used; no existing files will be overwritten and all tags will be publishes.

 
1# Publish all vendor assets.
2php artisan vendor:publish

The following would only publish the assets for the App\Providers\ExampleServiceProvider service provider:

 
1# Publish only the ExampleServiceProvider assets.
2php artisan vendor:publish --provider="App\Providers\ExampleServiceProvider"

The following examples demonstrate different uses of the vendor:publish command:

 
1# Force files to be overwritten if they exist.
2php artisan vendor:publish --force
3
4# Publish assets that have the specified tags.
5php artisan vendor:publish --tag=public --tag=migrations

Источник

Читайте также:  Throw custom exception in java
Оцените статью