pcardune / handlebars-loader

A handlebars template loader for webpack
557 stars 169 forks source link

Support for ES2015 default exports with Webpack 2 in helpers #115

Open TomOne opened 7 years ago

TomOne commented 7 years ago

If a helper uses ES2015 default exports with Webpack 2 (2.1.0-beta.25), the following setup fails:

.babelrc:

{
    "presets": [
        ["es2015", { "modules": false }]
    ]
}

template.handlebars:

{{my-helper}}

my-helper.js:

export default function () {
  return 'test'
}

Attempting to to provide a context to the imported template results in this error:

import template from './template.handlebars'

template({}) // <-- Error __default(...).call is not a function

However, if the ES2015 default export is replaced by a CommonJS export, everything works fine:

my-helper.js:

module.exports = function () {
  return 'test'
}

It would it be great for handlebars-loader to support ES2015 exports using Webpack 2. Or is this issue caused by Webpack’s loader API?

mteodori commented 7 years ago

same problem here, thanks @TomOne for the workaround provided

daslicht commented 7 years ago

I have the same question, any solution yet , please?