Skip to content

Add support for referencing src paths to craft.vite.inline() #72

@Kashkin

Description

@Kashkin

Is your feature request related to a problem? Please describe.

At present, I include SVGs built from Vite using both .asset() and .inline()

{% set logoPath = craft.vite.asset('src/images/logo.svg') %}
{{ logoPath|default ? craft.vite.inline(logoPath)|attr({"class": "w-12"}) }}

This works, but is inlining the file from the full URL, whereas I would greatly prefer to use the local file path.

Describe the solution you would like

I would like to be able to pass the src path straight into the inline function.

{{ craft.vite.inline('src/images/logo.svg')|attr({"class": "w-12"}) }}

This would need to reference the manifest to get the built file path, and likely use @webroot to access the file. It may require an additional config setting for the path to dist.

Describe alternatives you have considered

Alternatively, .asset() could accept an additional parameter to return only the file path.

{% set logoPath = craft.vite.asset('src/images/logo.svg', public=false, pathOnly=true) %} 
{{ logoPath }} # outputs 'dist/assets/images/logo-bbdb01c5.svg', which can then be concatenated with '@webroot'
{{ craft.vite.inline("@webroot/#{logoPath}")|attr({"class": "w-12"}) }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions