资产不能安装在symfony 4中

时间:2018-03-25 18:18:58

标签: symfony assets symfony4

我阅读了Web Assets的symfony文档,并在项目的 root 中创建了/assets目录,然后运行命令php bin/console assets:install,但得到:

  

[确定]任何捆绑都没有提供任何资产。

我将一个CSS文件存储在资源目录中但未安装在/public

我该怎么办?

2 个答案:

答案 0 :(得分:1)

The web assets documentation for Symfony 4 recommends using Webpack Encore. The assets:install command is not used in this configuration.

Here's what you have to do according to the documentation :

  • Install Node.js and Yarn on your computer.
  • Install Encore into your project with : yarn add @symfony/webpack-encore --dev
  • Configure webpack / Encore by editing (or creating) the webpack.config.js file as described here.
  • Compile your assets by running : yarn run encore dev

答案 1 :(得分:0)

有一个解决方法,可以在我们等待进一步的webpack-encore开发时(或多或少)清楚地做到这一点。可以通过Makefile或类似方式完成,但这是更本地的解决方案。

创建空白捆绑包:

// src/BlankBundle/BlankBundle.php
namespace App\BlankBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class BlankBundle extends Bundle
{
}

然后将您的资产放入src/BlankBundle/Resources/public目录并启用捆绑软件:

// add it to config/bundles.php
App\BlankBundle\BlankBundle::class => ['all' => true],

执行php bin/console assets:install命令后,您的资源将位于public/bundles/blank目录中。