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

Dynamic require macro path

Open sidonaldson opened this issue 7 years ago • 3 comments

Is it possible to have a dynamic paths in a require macro? I'm thinking in terms of loading a language variant:

@require('./header-' + language + '.hbs')

sidonaldson avatar Mar 01 '17 17:03 sidonaldson

hello @sidonaldson , afaik you can't do this on webpack 1. I think is because the way webpack handles paths (they should always point to the actual resource).

emaphp avatar Mar 02 '17 12:03 emaphp

@emaphp thanks for the quick reply. Maybe I could try aliasing the path and switching that per language instead. In theory that should work

sidonaldson avatar Mar 02 '17 12:03 sidonaldson

I can confirm that alias works:

// where language is set to 'en' for example
resolve: {
		alias: {
			test: path.resolve(__dirname, 'templates', language),
		}
	}

and then in a template

@require('~test/tracking-snippet.hbs')

sidonaldson avatar Mar 03 '17 01:03 sidonaldson