Exclude a json file when craming your curl project

19 views
Skip to first unread message

Magnus Landerblom

unread,
Oct 10, 2014, 9:49:40 AM10/10/14
to cuj...@googlegroups.com
I have a project where I use curl.
In this I have a json dependency (json!routes.json) which is meant to be generated by the server to configure the client upon boot. 
The problem arises when I want to cram this into one file but exclude this json file. 
I haven't found a way to exclude it, I have tried: 

 excludes: [
   
'json!/routes.json',
   
'../bower_components/curl/src/curl/plugins/json!/routes.json',
   
'../bower_components/curl/src/curl/cram/json!/routes.json'
 
]


but neither of these helps me. 

I'm using the latest and greatest of both curl and cram and running cram from the CLI pointing out my index.html. 

Is there a solution for this? Do you need more info on the project to give me some pointers?

//Magnus


Adam Jorgensen

unread,
Oct 14, 2014, 1:21:50 PM10/14/14
to cuj...@googlegroups.com
I would load routes.json using a nested curl within the AMD module(s) that require it.

For example:
define(function () {
  curl
(["json!/routes.json"], function(routes) {
   
// DO STUFF WITH routes
 
});
});

Working in this fashion will allow you to bypass cram.

unscriptable

unread,
Oct 15, 2014, 1:36:16 PM10/15/14
to cuj...@googlegroups.com
Have you tried excluding just "/routes.json"?  (Long shot. Probably won't work).  

Otherwise, what Adam has suggested will work.  Cram ignores async module requests... although, I would do it in a loader-agnostic fashion:

define(function (require) {
   
require('json!/routes.json', function (routes) {
       
// do stuff with routes.
   
});
});


We have done some research into the best ways to push un-bundled data (like routes.json) to the client.  The fastest way is to embed it in the HTML as a "data island".  If you have the ability to insert it into the HTML and then find it with a doc.getElementById() or doc.querySelector(), then that might be a good option.  This strategy tends to work best when the HTML document does not need to be cached.  

-- John

Magnus Landerblom

unread,
Oct 21, 2014, 5:06:33 AM10/21/14
to cuj...@googlegroups.com
Hi, 

Yes, I've tried to ignore the routes.json only and as you said it didn't work unfortunately.

The problem with loading it inside the define function as you both suggested is that I need to return a function from the module  that is dependent on routes.json and doing it this way I can only work with the promise of routes.json and not the data itself. 
Meaning the everything I return with be inside a promise. 
This it not a bad thing only a problem because the rest of the application isn't written with this in mind. 
Hope you understand my issue with this. 

I've succeeded with this once with require.js but I want to use Curl since I like it more but this makes me feel that it should exist a solution.

Embedding it in HTML isn't possible because the html isn't generated it is served as a static resource.

//Magnus

Adam Jorgensen

unread,
Oct 21, 2014, 8:39:38 AM10/21/14
to cuj...@googlegroups.com
So, your module which depends on routes.json needs to return function that depends on the content of routes.json?

I was going to provide you with a really hacky solution involving setTimeout but decided it might be better to keep that particular abomination under the bed :-)

Honestly, this sounds like a bug in cram given that it's ignoring excludes.

Your options are:
  1. File an issue, try to find and fix the bug in cram yourself and submit a pull request 
  2. File an issue, wait for someone else to fix it
  3. Re-work your application to use a Promise for the value of routes.json
If you have lots of time, go with 1. If you have less time, go with 2 + 3 

Magnus Landerblom

unread,
Oct 21, 2014, 9:15:19 AM10/21/14
to cuj...@googlegroups.com
I went with option number three. I would have wanted to go with the first option but didn't because of a couple of reasons. 
  1. Limited time (not a personal project)
  2. I like promises and cujos rest lib is very nice
  3. As I understand the future of both curl and cram are for now a bit uncertain with regards to es6 modules and RaveJs

Thanks for your suggestions, I can now continue :)

//Magnus
Reply all
Reply to author
Forward
0 new messages