Download the PHP package malyusha/laravel-webpack-assets without Composer
On this page you can find all versions of the php package malyusha/laravel-webpack-assets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download malyusha/laravel-webpack-assets
More information about malyusha/laravel-webpack-assets
Files in malyusha/laravel-webpack-assets
Package laravel-webpack-assets
Short Description Package to use WebpackManifestPlugin in laravel
License MIT
Informations about the package laravel-webpack-assets
Laravel Webpack Assets
Package that allows you to include assets from json file, generated by Webpack Manifest Plugin
Installation
Require the latest version of package using Composer
$ composer require malyusha/laravel-webpack-assets
If you are using version of laravel < 5.5, you need to add service provider into your config/app.php
file in providers
section:
\Malyusha\WebpackAssets\WebpackAssetsServiceProvider::class
You can add the WebpackAssets facade in facades
section:
'WebpackAssets' => \Malyusha\WebpackAssets\Facade::class
Configuration
To change package configuration you need to publish configuration file:
$ php artisan vendor:publish --tag=config
This will publish assets_manifest.php
file inside your config
directory.
Configuration file has a few options:
file
- path to manifest.json file, relative todisk
path. Seedisk
option;fail_on_load
- whether to fail on load assets file. If true - exception will be thrown;disk
- where yourmanifest.json
and all assets file are located. See laravelconfig/filesystems.php -> disks
.
Usage
Package provides helper functions to include script and style HTML elements inside blade templates:
webpack_script($script)
- will generate<script src="path_to_script_from_manifest_file"></script>
;webpack_style($script
- will do the same aswebpack_script
but for style;webpack($chunkName = null)
- will return instance ofAsset
class if no arguments provided, otherwise returns asset url with host.
Examples
Let's imagine, that you have generated manifest.json
file with such content:
Retrieving paths
Using in blade templates
Whenever you want to output your asset simply write:
Raw file contents
When you need to add inline file content, such as css or js wrapped with style
or script
tags
you can now use helper functions for that: webpack_raw_style
and webpack_raw_script
, or if
in object - webpack()->rawStyle()
and webpack()->rawScript()
.