简体   繁体   中英

Rendering inline Javascript in Jade file

This is a random one, so I'll try to get as clear as possible. I just burned about 3 hours trying to figure out what's going on and I can't even figure out where I should be looking.

We used a method I found from you that will allow us to include JS files directly in one single Jade file. We use this as a sort of manifest for all of our vendor libraries and app source code. Essentially, it worked so that there is one big JS file serving up all of the application libraries and code.

Here's a little of that manifest, called application_js.jade :

include ../../public/javascripts/lib/modernizr.min.js
include ../../public/javascripts/lib/jquery.min.js
include ../../public/javascripts/lib/prettydate.js
include ../../public/javascripts/lib/jquery.easing.min.js
include ../../public/javascripts/lib/jquery.isotope.min.js
include ../../public/javascripts/lib/jquery.ui.1.9.2.min.js
include ../../public/javascripts/lib/jquery.cookie.js

..and so on.

Our express app is set up to simply render this file:

app.get('/javascripts/application.js', function(req, res) {
  return res.render('js-views/application_js');
});

We recently updated a few packages and such, but I'm confused because now, when we hit the url domain.com/javascripts/application.js each one of these include files is now strangely wrapped in a <script> tag and pushed into the <head> of the document. Before, it would return a page of straight up javascript, which worked wonderfully.

I know this isn't really the best practice but it's been on our production app for about 6 months now and is good enough...trust me, I'd much rather see this thing in require.js !

Let me know if you need to see our package.json file or anything else, happy to help. Thanks in advance for any insight!

I have run into the same problem myself. Jade has changed and even though this has worked in previous versions, for newer I had to change the jade file slightly, like this:

script
  include ../../public/javascripts/lib/modernizr.min.js
  include ../../public/javascripts/lib/jquery.min.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM