emaphp / underscore-template-loader

A Underscore and Lodash template loader for Webpack
MIT License
104 stars 24 forks source link

Unable to use underscore functions inside template? #10

Closed kyllle closed 8 years ago

kyllle commented 8 years ago

When I use this plugin and use an underscore function inside my template I get an error Uncaught ReferenceError: _ is not defined pointing to the _.each() being used in the template?

SpaceK33z commented 8 years ago

_ needs to be globally available for this to work. Can you try to add the following to your webpack config?

{
    plugins: [
        new webpack.ProvidePlugin({
            _: 'underscore'
        })
    ]
}
kyllle commented 8 years ago

That's it, thanks for this!! I had originally added plugins inside the modules object.

arjunmayilvaganan commented 7 years ago

@SpaceK33z Not sure why we can't use underscore functions inside underscore templates.

If underscore is what renders the templates, then is it not what evaluates the expressions or statements inside the templates, such as _.each()?