1

I am attempting to use node-underscorify with Grunt to compile HTML templates into a format that Underscore will accept.

My gruntfile looks as such:

browserify: {
        standalone: {
            src: ['<%= config.main %>/*/*.js'],
            dest: '<%= config.dist %>/js/<%= pkg.name %>.standalone.js',
            options: {
                standalone: '<%= pkg.name %>',
                transform: ['node-underscorify'],
                debug: true,
                external: ['jquery', 'underscore', 'backbone.marionette']
            }
        },

All was working well until I tried to use Underscore methods inside HTML templates. For example, trying to call _.each results in a " _ is not defined" error. According to the node-underscorify documentation, an require option can be passed in, such as:

requires:[{variable: '_', module: 'underscore'}]}

How can I properly set up node-underscorify to work with Grunt such that I can use underscore methods in my HTML templates (or view helpers, etc)?

1
  • I think you would be better to create issue for that module. It's hard to tell what's wrong without digging through that module. Its author should be more able to find an issue. Commented Sep 15, 2014 at 19:10

1 Answer 1

3

Although having second look in the docs, it should be pretty obvious. I think it cannot work like that. Instead you should invoke something like this in your code.

document.body.innerHTML = template({message: "Hello Node Underscorify!", _: require('underscore')});
Sign up to request clarification or add additional context in comments.

1 Comment

That was exactly it. I chose the wrong part of the documentation to chase. Thank you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.