Search code examples
javascripthandlebars.jsprecompile

How to Precompile scripts in JS


I have many js files which I concatenate using grunt. Most of my code is generic, but some parts of it are private for some clients (meaning client a has some scripts that client b won't use). Currently I'n using simple if conditional everywhere it is needed. I wish that somehow, when i build the concatenated script to a specific client, he will get only his methods (without the if parts that suits other clients). I was looking to use handlebars, but i couldn't figure out how i can use it for this task. My private scripts don't contain any html elements. Any ideas?


Solution

  • It sounds like your best bet would be a closure comipler. If you would show a minimal code example of what you want to minify / optimize and what you expect to happen, the answer would be more detailed.

    Another approach would be to create a build system based on outside configuration. I.e. do not use if's inside your JavaScript, instead make a grunt build based on some configurable object. Could be as simple as array of files for concatenation.