2

I am using webpack dev server to serve my assets in local development. I have following in my paramters.yml.dist

# local assets devserver address
# if you want to use webpack dev server use "http://localhost:8090"
# and then > npm run devserver
assets_base_url: ~

I have following in framework for local environment.

framework:
    assets:
        base_urls: ["%assets_base_url%"]

My problem is that it is not working with base settings of "~" for my colleagues that are not using devserver.

Error: "" is not a valid URL

What should I do enable or disable devserver assets url by one setting in parameters.yml

Symfony docs for asset component

1 Answer 1

1

Instead of put base_urls: ["%assets_base_url%"], you can do that in the Extension Class of your bundle.

namespace Acme\HelloBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class AcmeHelloExtension extends Extension implements PrependExtensionInterface
{
    // ...

    public function prepend(ContainerBuilder $container)
    {
        $assetBaseUrl = $container->getParameter('assets_base_url');
        if (!$assetBaseUrl) {
            $container->prependExtensionConfig(
                'framework',
                array(
                    'assets' => array(
                        'base_urls' => array($assetBaseUrl)
                    )
                )
            );
        }
    }
}

Inside the PrependExtensionInterface::prepend() method you can prepends settings over config.yml configuration.

Sign up to request clarification or add additional context in comments.

7 Comments

How it will work if I want to use this setting globally and I have 20+ company bundles in project.
You need a 21° bundle where to do this (call it "CoreBundle", or whatever), and the others bundle must be now have a dependency to this new bundle.
I will show this solution or I will force all colleagues to set it manually to correct Url. Rather then creating dependencies like this.
wait, wait, wait... I maybe was looking for the most complicated solution
try to change assets_base_url: ~ to assets_base_url: []
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.