larowlan / vite-plugin-twig-drupal

Provides a vite plugin for rendering Drupal flavoured twig files with Storybook
MIT License
15 stars 4 forks source link

includes using alias from Vite config #20

Closed dhmax88 closed 2 months ago

dhmax88 commented 2 months ago

I'm trying to use includes with an alias from vite, i.e.

resolve: {
    alias: {
        '@templates': resolve(__dirname, '/src/templates'),
    },
},

so I can then do:

{% include '@templates/button/button' %} within storybook files.

But the alias is not being picked up within Storybook. Does anyone have this working?

larowlan commented 2 months ago

These are called namespaces in twig, see the docs in the README - https://github.com/larowlan/vite-plugin-twig-drupal?tab=readme-ov-file#installation

dhmax88 commented 2 months ago

Thanks for the speedy reply @larowlan

When using namespaces I run into the same issue and get this error:

import '/var/www/html/src/templates/typography/@templates/button/button';

which would suggest the namespace isn't functioning as expected

larowlan commented 2 months ago

Can you share your config? Thanks

dhmax88 commented 2 months ago

I realise the issue, and it's most likely due to my own ignorance!

twig({
    namespaces: {
        templates: join(__dirname, '/src/templates'),
    },
}), 

the above adds the '@' in the plugin, so this is then used as @templates/ in the storybook files. I was setting the @ in the namespace itself.

larowlan commented 2 months ago

Sweet! If I can update the readme at all to make it clearer, please let me know 👍