Search code examples
symfonywebpackassetswebpack-dev-server

Symfony asset function prepends / to http url


I've tried to add webpack to a Symfony 3.1 app. The problem is, when I add HMR, the asset function doesn't resolve correctly

// base.html.twig
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>

// app/config/config_dev.yml
framework:
    assets:
        base_path: "http://localhost:8080"

Result: <script src="/http://localhost:8080/bundles/fosjsrouting/js/router.js"></script>

How can I tell Symfony to not prepend the starting / if the base_path begins with http://?


Solution

  • You can use base_urls. Protocol/host/port should not be used in base_path for assets.

    https://symfony.com/doc/current/reference/configuration/framework.html#assets