0
define(["jquery","bootstrap","jquery.min"],function($){
    var inittest = function(){
        alert("hello");
    }
    var init = function(){
        inittest();
    };
    return {
        init: init
    }
});

It's not working. How to use jQuery to define array?

4
  • This thread on how to load Bootstrap with requirejs should be helpful. You need to shim bootstrap. Look at the first answer there for the details. Commented Nov 28, 2015 at 9:29
  • how to use jquery.min file work with this code? Commented Nov 28, 2015 at 9:36
  • Requirejs doesn't care whether your jquery is minified or not, so choose one of the two and then load it in requirejs.config. Did you read the top answer I linked to above? Commented Nov 28, 2015 at 9:39
  • i want another one example.please send another one example? Commented Nov 28, 2015 at 9:47

1 Answer 1

0

You need to do two things here (the details are in the useful thread I linked you to, so please read).

  1. Configure requirejs so that when you declare modules (e.g. "jquery", "bootstrap"), requirejs can resolve them to actual files, minified or otherwise.
  2. Shim bootstrap by specifying jquery as its dependency, so that jquery is loaded before it.

To accomplish these, make a call to requirejs.config({...}) with the appropriate options (here is an example). The use case there is exactly the same as yours: jquery is specified as a bootstrap dependency by shimming bootstrap. There you will also see an example of how to tell requirejs where your files are (this is accomplished via the paths property). Note how the .js extension is not explicitly specified there; do the same.

Needless to say, configuring requirejs can get complicated, but the basic idea is there, configure it by specifying the base directory and where the files are to be found, then shim non-AMD modules. An important thing to be aware of is that bootstrap is going to be what's called a declarative module, which means that it's only used for its side-effects (viz. for what changes it makes to $).

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

Comments

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.