Question

My structure looks like so:

  • index.html
  • main.js #holds the configs.path and configs.shim
  • libs
    • jquery.js
    • require.js
    • backbone.js
    • underscore.js
  • modules
    • app
      • main.js #want to load in ./views/app.js here
      • views
        • app.js

so in /modules/app/main.js, I want to load in the /modules/app/views/app.js but having problem

Here is /modules/app/main.js

define(['views/app'],function(App){
console.log('app main')
//var app = new App();
})

The console error message I get is Get failed with path GitProjects/GameApp/views/app.js

How do I get it to load relatively inside modules?

here is ./main.js the file that holds the configs

require.config({
    paths: {
      jquery: './libs/jquery-2.0.3',
      underscore: './libs/underscore',
      backbone: './libs/backbone'
    },
    shim: {
        "underscore": {
            exports: '_'
        },
        "backbone": {
            deps: ["underscore", "jquery"],
            exports: "Backbone"
        }
    }
}); 

and here is my index.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Stop Game App</title>
        <script src="./libs/require.js" data-main='./main'></script>
    </head>
    <body>
        <div id="app"></div>
        <script>
        require(['./modules/app/main'],function(){
                console.log('main')
            })
        </script>
    </body>
</html>
Was it helpful?

Solution

You just need to set the path to "./" and be relative. That's all there is to it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top