2

So, i have several handlebars templates on a far far away folder. I have to import them using

import UserTemplate from '../../../../../../More/Stuff/Omg/Template.handlebar'

I'm thinkg if i could do something nicer, like a function to resolve this for me for instance

  let UserTemplate = Templates.get('Template.handlebar');

Then this function would do all those crazy path stuff and import.

Would that be possible somehow ?

Gabriel Slomka
  • 1,487
  • 1
  • 11
  • 24

1 Answers1

2

There is a package that you can use that already does this module-alias

Under you package.json you would have

"_moduleAliases": {
  "@Templates"      : "./templates/"
}

Then you could query these as follows

import UserTemplate  from '@Templates/UserTemplate'

Also if you are using webpack you could use their built-in functionality of this https://webpack.js.org/configuration/resolve/.

asosnovsky
  • 2,158
  • 3
  • 24
  • 41