0

I am using ASP.NET MVC to build a web application, and I have fallen in love with the library Q.js, available here:

Q.js

Right now, I am using version 1.0, I load it up in the way that is most natural to me as an ASP.NET MVC developer. I have a place in my BundleConfig that just loads the script with my other scripts.

BundleConfig.cs

public static class BundleConfig {
   public static void RegisterBundles(BundleCollection bundles){
      bundles.Add(new ScriptBundle("~/bundles/scripts")
         .Include("~/content/scripts/jquery.js")
         // lots of other includes
         .Include("~/content/scripts/q.js"));
   }
}

So then in my view _Layout.cshtml, it's the normal simple process...

_Layout.cshtml

<head>
   @Scripts.Render("~/bundles/scripts")
</head>

Easy enough, right? Yes, it works fine. But I notice that Q.js has another branch labelled v2.

Now, from what I can immediately tell, they are not that much different, but I do not believe the creator would have made a version 2 if they were not doing it to improve the product. I'd like to try it out, but this is where my experience fails me.

version 2 seems fundamentally different than version 1. Here is a link to it for quicker reference; Qv2

The q.js file starts out with this at line 43.

require("collections/shim");
var WeakMap = require("collections/weak-map");
var Iterator = require("collections/iterator");
var asap = require("asap");

I am accustomed to the require function being a part of requirejs, but I don't believe that is the purpose being served here. I in fact think this is intended to be consumed/run/used by node.js.

Now, since I am using ASP.NET MVC, I won't be using node.js. I've attempted to just put the expected folders and files in the right place so that they would be path relative to q.js, but that does not seem to satisfy it.

The Actual Question

Is there a way I can 'compile' Q.js 2.0 into a .js file that will not require node.js, and can be loaded normally within my ASP.NET MVC project? Can I use node.js to actually create an output .js file that has everything I need?

10
  • 1
    Are you looking for browserify? Commented Jul 21, 2014 at 15:45
  • 1
    browserify.org is what you are looking for. Commented Jul 21, 2014 at 15:46
  • Hey, thanks for the very rapid feed back. I'll check this out. In the meantime, could I trouble one or both of you to actually post this as an official "answer", so that if you are right I can award you appropriate credit? Commented Jul 21, 2014 at 15:47
  • 1
    browserify will enable you to use node/CommonJS style require calls and using module.exports to define modules yourself in a browser environment. This: github.com/substack/browserify-handbook is a pretty good reference, also this:myeyeson.net/gulp-js-and-browserify-with-asp-net may help you getting stuff set up in ASP.NET Commented Jul 21, 2014 at 15:51
  • 1
    Apparently (since you seem to be using require.js) you can just shim Q's export like: stackoverflow.com/a/18827459/797194 Commented Jul 21, 2014 at 15:56

1 Answer 1

1

browserify is a tool for Node that takes all of the require()d dependencies, resolves them, and packages them into a single JavaScript file servable to the browser.

Sign up to request clarification or add additional context in comments.

10 Comments

FWIW, i thought of it on my own, before seeing the comments on the OP.
I am reading up on it right now, but I am still very confused about how to use it. Trying to see if I can find more examples. It seems to expect a lot of knowledge about node.js
Basic usage is actually pretty simple. Just create a Node.js file with require()s, run the browserify command from a CLI, and be done with it.
So I would download Q.js v2 from the github, and then open a command line, go to where that file is stored, and run browserify on it, and it will find the dependencies and output a working file?
Yep, provided all of Q's dependencies are available.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.