deedubs / require-jade

Add jade to requireJS
MIT License
55 stars 17 forks source link

Fix for "JS error in produced optimized code" #15

Open isadovskiy opened 11 years ago

isadovskiy commented 11 years ago

Fix for https://github.com/rocketlabsdev/require-jade/issues/14

vincentmac commented 11 years ago

I just tried your changes and think I figured out what you are doing and why you are receiving this error.

When you are using r.js to build your project, require-jade will take your template and convert it to a javascript function that will act as your template. To be able to use this new "template" you need to have the jade runtime included in your optimized file. By turning on the pragmasOnSave { excludeJade: true } flag, you are telling r.js to include the jade runtime and exclude the jade compiler.

Now when you set excludeJade: false (or don't include the flag at all) and compile, you are still creating the javascript templates; however, you are telling r.js to include the full jade compiler, which will not work on the precompiled templates.

It looks like your PR is also creating a new empty jade object var jade = {}; (line 3898) which you are then using to assign undefined properties (ie jade.attrs) to functions in the module (line 3913). I am not quite sure how this PR is making this work for you, but it is not working when I try it.

Another thing to consider is, if you are building your app, why would you want to compile your jade templates on the client side? I do not see the advantage to doing this.

If you are using r.js to build your app, use the jade runtime.

isadovskiy commented 11 years ago

Sorry, looks like I messed up something... Previous fix actually does not work. The new one I just committed works fine for me. Please review. Here are the tests: https://docs.google.com/file/d/0B4Ec_AMB8FX2aHNjSjhOWHNmSEU/edit?usp=sharing

EvanCarroll commented 9 years ago

How do I set {excludeJade:true} and why would a flag that says to excludeJade being set to true result in the inclusion of Jade?