handlebars-loader icon indicating copy to clipboard operation
handlebars-loader copied to clipboard

Feature request: Optional partialResolver

Open Devqon opened this issue 3 years ago • 1 comments

Hi,

We use the handlebars-loader in combination with Storybook and plain html/scss, which works awesome!

We want to configure handlebars to optionally resolve partials based on prefixed, and if not passed use the default partial resolver. There is now only an option to override the behavior completely, without fallback.

What we want to achieve:

<!-- custom resolving, search in a directory called 'legacy' -->
{{> legacy.my-partial }}
<!-- should still work (fallback to default resolve) -->
{{> my-partial }}

Devqon avatar Dec 10 '21 15:12 Devqon

Hi,

I had the same request and I manage to do this by that ugly thing:

{
    test: /\.(html|handlebars|hbs)$/,
    use: [
        {
            loader: 'handlebars-loader',
            options: {
                partialResolver: function (partial, callback) {
                    callback(undefined, (partial.startsWith('common/') ? path.join(__dirname, 'src', 'partials', partial.replace('common/', '')) : './' + partial) + '.hbs')
                }
            }
        }
    ]
}

In this example, with prefix 'common', partials will be loaded from '/src/partials", without prefix it will follow standard import.

thibaudsowa avatar Jun 09 '23 15:06 thibaudsowa