javascript - How can I load require.js from multiple paths, without using an absolute url? -


i have directory structure this:

├── index.html ├── static │   └── js │       ├── main.js │       ├── jquery.js │       └── require.js └── subfolder     └── index.html 

in top-level index.html, i'm loading require.js this, , works:

<script data-main="static/js/main" src="static/js/require.min.js"></script> 

however, in subfolder/index.html, can't load require.js succesfully:

<script data-main="../static/js/main" src="../static/js/require.min.js"></script> 

which results in "script error for: jquery", , same each dependency of main module.

the baseurl require.js set static/js. because these pages intended used locally, can't use absolute url. how can require.js work subfolders?

contents of main.js file:

require.config({     baseurl: 'static/js',     paths: {         'jquery': 'jquery-2.0.3',     } });  require(['jquery'], function($) { ... } 

the solution not set baseurl @ all:

if no baseurl explicitly set in configuration, default value location of html page loads require.js. if data-main attribute used, path become baseurl.

removing baseurl setting resulted in above example working correctly.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -