Laravel 4: Publishing a Package's Assets

2019-04-09 20:31发布

How to publish package assets? I've found a tutorial here: http://laravel-recipes.com/recipes/279

But when I tried to publish assets from my workbench, I get this error:

[RuntimeException]         
 Unable to publish assets.  

asset:publish [--bench[="..."]] [--path[="..."]] [package]

My command code is:

php artisan asset:publish --bench=Mypackage

How can I get my package assets to be published.

Thank you.

标签: php laravel-4
4条回答
成全新的幸福
2楼-- · 2019-04-09 20:37

When you want to publish assets that are developed and stored in your workbench you should use the --bench flag. In your case you want to publish a package in the vendor folder then provide "myVendor/myPackage".

Publishing assets from a vendor package

php artisan asset:publish "vendor/package"

Publishing assets from a workbench package

php artisan asset:publish --bench="vendor/package"
查看更多
一夜七次
3楼-- · 2019-04-09 20:38

I'll give an example with Twitter Bootstrap Package.

If you want to publish your assets in the folder "public/packages" :

php artisan asset:publish --path="vendor/twitter/bootstrap/dist"

If you want to publish your assets in the folder "public/" :

php artisan asset:publish --path="vendor/twitter/bootstrap/dist" "../"
查看更多
一夜七次
4楼-- · 2019-04-09 20:56

You use the Workbench to prepare your own package for use in Laravel.

There is a directory structure for where to place your files:

/src
    /Vendor
        /Package
            PackageServiceProvider.php
    /config
    /lang
    /migrations
    /views
/tests

/public <---- the folder in question here

When preparing your package, any files that need to be accessible from the web server like imgs/css/js files (or assets as they are typically called in web apps) are put here.

Then when you enter the command:

php artisan asset:publish --bench=Mypackage

it will deploy those files into

/approot
/public
    /vendor/package/

more info here: http://laravel.com/docs/packages

查看更多
唯我独甜
5楼-- · 2019-04-09 21:00

When I wanted to copy Twitter Bootstrap (SASS version) for me worked only:

php artisan asset:publish --path="vendor\twbs\bootstrap-sass\assets"  .

it copied assets folder content (3 directories) to public/packages.

When I had no . at the end there was no message and nothing was copied.

And when I omitted assets directory in the command the whole vendor\twbs\bootstrap-sass directory content was copied to public directory what is of course unnecessary

查看更多
登录 后发表回答