Search code examples
javascriptnode.jsbrowserifynode-modules

Browserify & Jstify: "Unexpected token %="


So ... I'm fairly new with Browserify and giving a shot at rebuilding an AMD project with it. However, in any scenario where I would have been using tpl! to require my templates with RequireJS, I'll have, ex:

var QuoteTemplate= require('js/quoting/quote/quoteTemplate');

but when I run the CLI, using this example taken from https://github.com/zertosh/jstify

browserify -t [ jstify --minifierOpts [ --collapseWhitespace false ] ] js/quoting/app.js > js-dist/quoting.js

at the first instance of a JS tag in the template I get

ParseError: Unexpected token %=

...which frankly is the exact token I was expecting it to expect.

I'm picking on jstify here but I've also tried it with node-underscorify and with Handlebars as well (modifying my template, of course, it still chokes on the . in my dot syntax but I don't play much with hbs, so, idk) ... my point being that perhaps I have misunderstood something silly and could be straightened out easily...? Maybe?


Solution

  • Ok. Well, I'm not sure if this is exactly an answer in the classic sense, but now that I've gotten another shot at this I've decided just to recreate it using an extra step:

    var fs = require('fs');
    var QuoterTemplate = _.template(fs.readFileSync(__dirname + '/quote/quoteTemplate.tpl', 'utf8'));
    

    And then I'm using the [brfs]1 transform to pull that template in, to be turned into a template function by Underscore.

    So... I may go to my grave not understanding why I was having this problem, but at least I'll be able to load templates this way before I die. Hope this helps somebody!