pugjs / pug-runtime

The runtime for the Pug compiler
MIT License
10 stars 6 forks source link

pug-runtime on bower/in the browser #34

Open magnuspaaske opened 7 years ago

magnuspaaske commented 7 years ago

Hey

I hadn't seen this project after pug was renamed from jade, but I had been using jade-runtime before. I was thinking why there's no browser optimized version of the runtime so that it can be dropped into a project with no problems (preferably loaded from bower).

Not sure how it could best be done but I assume the main file could simply be used as a basis. Currently when I compile pug I need to add the functions anyways but it would be better to add it based on the common master.

/Magnus

tedeh commented 6 years ago

I'm sitting with an "ancient" project running requirejs and I had to do this in order to be able to use pug-runtime properly.

  1. Copy pug-runtime/index.js into a separate folder $FOLDER
  2. Remove the require('fs') line in index.js
  3. Run r.js -convert $FOLDER outputFileName
  4. Find the right output file (r.js is a super silly tool when it comes to parsing args) and rename it to pug-runtime.amd.js or something
  5. Rock and roll (I can now render pug in the browser)
ForbesLindesay commented 6 years ago

The latest version of pug automatically generates the required runtime functions inline, so you shouldn’t need to reference pug-runtime. If you want to as a performance optimisation (if your app has a lot of pug templates), any CommonJS loader should work fine.